nutterb / HydeNet

Hybrid Decision Networks in R
Other
23 stars 3 forks source link

Translate factor levels in compileJagsModel() and compileDecisionModel() #68

Closed jarrod-dalton closed 9 years ago

jarrod-dalton commented 9 years ago

It seems that we may be able to circumvent the need to specify numeric codes in place of factor levels in the data argument to compileJagsModel().

(Setting up the model:)

library(HydeNet)

mtcars2 <- transform(mtcars,
                     cyl = factor(cyl),
                     gear=factor(gear),
                     am = factor(am))

carNet <- HydeNetwork(~ cyl
                      + disp | cyl
                      + hp | disp
                      + wt
                      + gear
                      + mpg | disp*hp*wt*gear,
                      data=mtcars2)

Currently, if we want to observe cyl="6", we need to say:

carNet2 <- compileJagsModel(carNet, data = list(cyl = 3) )

It doesn't seem terribly difficult to make it so the syntax can be:

carNet2 <- compileJagsModel(carNet, data = list(cyl = "6") )
nutterb commented 9 years ago

carNet2 <- compileJagsModel(carNet, data = list(cyl = "6") )

This syntax works for me. The posterior distribution shows the value of 2 in place of 6, which is the appropriate numeric level. Using bindPosterior gives the option to relabel the factor to "6".

Are you getting an error with this syntax?