Lexer: Slice Lexer class

Description Usage Arguments Details Value See Also Examples

Description

This class contains the lexer and parser to create a model tree from the model string. To use this class, create an instance of it first. Then set the model string and data using the functions setModelString and setModelData. Afterwards use lexModel to create all object required to build the model. Than use parseModel to build the mode. This function will return the model tree that can be used in with sampler classed to sample from the model.

Usage

1
2
3
4
5
6
7
lex = new('Lexer')
lex$setModelString(model_str)
lex$setModelData(data_list)

lex$lexModel()

root_plate = lex$parseModel()

Arguments

mode_str

Contains the model string

data_list

Is a named list with the data used to build the model.

Details

The language is very similar to the bugs language

Value

Will return the build model tree if successful.

See Also

Package Overview: Slice-Package

Base Sampler class: Sampler

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require('Slice')

#define a regression model 
my_model_str= "
model regModel{
  #this is a comment
  y~ dnorm(x*beta1 +beta0,sigma)
  sigma~dgamma(0.01,0.01)
  beta0 ~ dnorm(0,s)
  s ~ dunif(0,1)
  beta1 ~ dnorm(0,1) #one more comment
}
"

#generate some data

set.seed(1234)
n <- 100
beta   <- c(1.4,-0.8)
sigma2 <- 1
X = cbind(rnorm(n,2,1),1)
val = X 
y = matrix( val,ncol = 1)
x = matrix(X[,1],ncol = 1)
data_list = list('y'=y,'x'=x)

lex = new('Lexer') ##create lexer obj
lex$setModelString(my_model_str) #set model
lex$setModelData(data_list) # set data

lex$lexModel() ##lexx the syntax 
 
root_plate = lex$parseModel() ##create the model

dennisthemenace2/Slice documentation built on Nov. 4, 2019, 10:26 a.m.