Need Help resloving error using ulam()

Model :

m1stan <- ulam (
  alist(
    tp ~ dpois(lambda),
    lambda <- a + bt * technique_NT + bc * category_LE,
    a ~ dnorm(0,5),
    bt ~ dnorm(0,1),
    bc ~ dnorm(0,1)
  ),
  data = assignment_data , chains = 4
)

The error message :

Error in mod$fit_ptr() :
  Exception: variable does not exist; processing stage=data initialization; variable name=technique; base type=vector_d  (in 'model659c78997d3_91de77165411d85e543f9e143f05d222' at line 7)In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  '-E' not found
failed to create the sampler; sampling not done
Stan model '91de77165411d85e543f9e143f05d222' does not contain samples.
Error in validObject(.Object) :
  invalid class “ulam” object: invalid object for slot "coef" in class "ulam": got class "NULL", should be or extend class "numeric"

Link to Dataset :
data_autumn2020.csv (1.7 KB)

The error message suggests that a variable called technique doesn’t exist in your data. Can you post the whole code?

1 Like
assignment_data<-read.csv2("Data/data_autumn2020.csv")
summary(assignment_data)
library(rethinking )
assignment_data$tpNT <- ifelse(assignment_data$technique == "NT",assignment_data$tp,0)
assignment_data$tpOT <- ifelse(assignment_data$technique == "OT",assignment_data$tp,0)
assignment_data$Exp <- ifelse(assignment_data$category == "ME",1,0)
assignment_data$technique_NT <- ifelse(assignment_data$technique == "NT", 1 , 0)
assignment_data$technique_OT <- ifelse(assignment_data$technique == "OT", 1 , 0)
assignment_data$category_LE <- ifelse(assignment_data$category == "LE", 1 , 0)
assignment_data$category_ME <- ifelse(assignment_data$category == "ME", 1 , 0)

m1 <- map (
  alist(
    tp ~ dpois(lambda),
    lambda <- a + bt * technique_NT + bc * category_LE ,
    a ~ dnorm(0,5),
    c(bt,bc) ~ dnorm(0,1)
  ),
data = assignment_data  
)

m2 <- map (
  alist(
    tp ~ dpois(lambda),
    log(lambda) <- a + bt * technique_NT ,
    a ~ dnorm(0,5),
    c(bt) ~ dnorm(0,1)
  ),
  data = assignment_data  
)

m3 <- map (
  alist(
    tp ~ dpois(lambda),
    lambda <- a + bc * category_LE ,
    a ~ dnorm(0,5),
    c(bc) ~ dnorm(0,1)
  ),
  data = assignment_data  
)

m4 <- map (
  alist(
    tp ~ dpois(lambda),
    lambda <- a ,
    a ~ dnorm(0,5)
  ),
  data = assignment_data  
)
compare(m1,m2,m3,m4)




m1stan <- ulam (
  alist(
    tp ~ dpois(lambda),
    lambda <- a + bt * technique_NT + bc * category_LE,
    a ~ dnorm(0,5),
    bt ~ dnorm(0,1),
    bc ~ dnorm(0,1)
  ),
  data = assignment_data , chains = 4
)

This is my whole code.

If you run your above code, you’ll also the warning message:

Removing one or more character or factor variables:
categorytechnique

Which means that the ulam function is dropping these variables from the dataset, which causes an error when Stan looks for those variables in the input data. This is an issue that you should post on the rethinking github, so the package author can fix it in the future: https://github.com/rmcelreath/rethinking

In the meantime, if you remove those variables from the dataset before you call ulam, then everything works:

assignment_data_red = assignment_data[,-c(2,3)]

library(rethinking)

m1stan <- ulam (
    alist(
        tp ~ dpois(lambda),
        lambda <- a + bt * technique_NT + bc * category_LE,
        a ~ dnorm(0,5),
        bt ~ dnorm(0,1),
        bc ~ dnorm(0,1)
    ),
    data = assignment_data_red , chains = 4
)

1 Like