Error in new_CppObject_xp(fields$.module, fields$.pointer, ...)

278 views
Skip to first unread message

zha...@tongji.edu.cn

unread,
Feb 16, 2017, 4:58:45 PM2/16/17
to Stan users mailing list
Hi, All,

I'm trying to develop new psychometric model using Rstan for estimation process with defaulted non-informative priors, but I encounter the following error which I have no idea what's going on now. Anyone can help me interpret this problem?

> Bayesian_2PL <- stan_model(model_code = Bayesian_2PL_Model_NI, model_name = "Bayesian_2PL_NI") # compile once
> Fit_Bayesian_2PL_NI <- sampling(Bayesian_2PL, data = init, iter = 2000, chains = 4, control = list(adapt_delta = 0.8))
Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  variable does not exist; processing stage=data initialization; variable name=y; base type=int
In addition: Warning messages:
1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
2: In FUN(X[[i]], ...) : data with name y is not numeric and not used
failed to create the sampler; sampling not done

The dataset is a 5000 by 10 response pattern matrix, with only 0s and 1s, and the latent ability and item difficulties and item discriminations were estimates. The stan code I'm using is

Bayesian_2PL_Model_NI<-'data {
int<lower=0> n_student; // n_student: the number of students
int<lower=0> n_item; // n_item: the number of items
int<lower=0,upper=1> y[n_student, n_item]; // the matrix of responses patterm
}

parameters {
real item_diff[n_item]; // item difficulty for items
real item_disc[n_item]; // item discrimination for items
real theta[n_student]; // latent ability theta for n student
}

transformed parameters {
  real psm[n_student, n_item]; // problem-solving model
  real pprocess[n_student, n_item]; // the probability of a correct response

  for(i in 1:n_student)
    {
      for (j in 1:n_item)
        {
          psm[i, j] <- item_disc[j]*(theta[i] - item_diff[j]); // 2PL IRT model
          pprocess[i, j] <- inv_logit(psm[i, j]); // convert to the probability
        }
    }
}

model {
  for(i in 1:n_student)
    {
      for (j in 1:n_item)
        {
          y[i,j] ~ bernoulli(pprocess[i, j]);
        }
    }
}
'

The code can be run without error in Windows OS, but with MAC OS, the problem occurs. Does anyone know what's the problem here?

Thanks,

Sincerely,
Jiaqi

Matt Espe

unread,
Feb 16, 2017, 7:36:35 PM2/16/17
to Stan users mailing list
It looks like the issue is with the data that is being passed into the model. Can you include your R code for creating "init"? 

It also might be helpful to post the results of "str(init)".

Matt

Ben Goodrich

unread,
Feb 16, 2017, 9:02:02 PM2/16/17
to Stan users mailing list
On Thursday, February 16, 2017 at 4:58:45 PM UTC-5, zha...@tongji.edu.cn wrote:
I'm trying to develop new psychometric model using Rstan for estimation process with defaulted non-informative priors, but I encounter the following error which I have no idea what's going on now. Anyone can help me interpret this problem?

You ran into a bug that has been fixed on GitHub. If you do

devtools::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")

it should work.

Ben

zha...@tongji.edu.cn

unread,
Feb 18, 2017, 12:50:44 AM2/18/17
to Stan users mailing list
Hi, Ben,

I've tried the following code,

devtools::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")

then, there is another problem occurs, which I can not even google for potential solution.

Fit_Bayesian_3PLAG_NI <- sampling(Bayesian_3PLAG, data = init, iter = 1000, chains = 4, control = list(adapt_delta = 0.8))
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘is_dso_loaded’ for signature ‘"cxxdso"’

The model can be compiled, I've attached the data generation code, the stan model, and the testing code here, could you please help me figure out where the problem is?

Thanks,

Sincerely,
Jiaqi Zhang
FUNCDataGeneration.R
Bayesian3PLAGNI.R
Testing.R
FUNCGuessing_logic_scale.R
Inv_Logit_Function.R

zha...@tongji.edu.cn

unread,
Feb 18, 2017, 12:54:48 AM2/18/17
to Stan users mailing list
Thanks, Matt,

I've tried str(init), I thinks the init list looks as expected:

> str(init)
List of 3
 $ n_student: int 5000
 $ n_item   : int 10
 $ y        :'data.frame': 5000 obs. of  10 variables:
  ..$ Item1 : int [1:5000] 0 1 0 1 1 1 1 1 1 1 ...
  ..$ Item2 : int [1:5000] 1 1 1 1 1 1 1 1 0 1 ...
  ..$ Item3 : int [1:5000] 1 0 1 1 0 0 1 0 1 0 ...
  ..$ Item4 : int [1:5000] 1 1 1 1 1 1 1 1 1 1 ...
  ..$ Item5 : int [1:5000] 1 1 1 1 1 1 1 0 0 1 ...
  ..$ Item6 : int [1:5000] 1 1 1 1 1 1 1 1 1 1 ...
  ..$ Item7 : int [1:5000] 1 1 0 1 1 0 1 0 0 0 ...
  ..$ Item8 : int [1:5000] 0 1 0 1 0 0 0 0 0 0 ...
  ..$ Item9 : int [1:5000] 0 1 1 1 0 0 0 0 1 0 ...
  ..$ Item10: int [1:5000] 0 1 1 1 1 1 0 0 1 1 ...

After tried Ben's code, I've encounter another error.

Thanks again,

Sincerely,
Jiaqi Zhang

Ben Goodrich

unread,
Feb 18, 2017, 10:46:47 AM2/18/17
to Stan users mailing list
On Saturday, February 18, 2017 at 12:50:44 AM UTC-5, zha...@tongji.edu.cn wrote:
Fit_Bayesian_3PLAG_NI <- sampling(Bayesian_3PLAG, data = init, iter = 1000, chains = 4, control = list(adapt_delta = 0.8))
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘is_dso_loaded’ for signature ‘"cxxdso"’

I think your installation is incomplete. Try this:

1. Delete all objects from R's global environment
2. Close R
3. Restart R without loading any .RData file
4. Do remove.packages("rstan")
5. Check that system.file(package = "rstan") returns an empty string. If not, you may have to delete the rstan/ directory manually.
6. Do devtools::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")
7. Restart R, do library(rstan), and try again

Ben

zha...@tongji.edu.cn

unread,
Feb 18, 2017, 10:32:25 PM2/18/17
to Stan users mailing list
Thanks, Ben,

This is really helpful, and I got it work. I really appreciate your quick feedback!

Sincerely,
Jiaqi Zhang
Reply all
Reply to author
Forward
0 new messages