Graded Response Model: R for Windows terminal front-end has stopped working


#1

Hi All,
I am trying to fit a graded response model in rstan. Unfortunately, R keeps crashing with the error “R for Windows terminal front-end has stopped working.”

I get the following output before the crash happens:

> stanout <- stan('latent-factor-model.stan'
+               , data=standat
+               , iter=4000
+               , chains=1)
hash mismatch so recompiling; make sure Stan code ends with a blank line
In file included from C:/Users/CURTS025/programs/R/library/BH/include/boost/config.hpp:39:0,
                 from C:/Users/CURTS025/programs/R/library/BH/include/boost/math/tools/config.hpp:13,
                 from C:/Users/CURTS025/programs/R/library/StanHeaders/include/stan/math/rev/core/var.hpp:7,
                 from C:/Users/CURTS025/programs/R/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5,
                 from C:/Users/CURTS025/programs/R/library/StanHeaders/include/stan/math/rev/core.hpp:12,
                 from C:/Users/CURTS025/programs/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Users/CURTS025/programs/R/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/Users/CURTS025/programs/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file46d031c2faa.cpp:8:
C:/Users/CURTS025/programs/R/library/BH/include/boost/config/compiler/gcc.hpp:186:0: warning: "BOOST_NO_CXX11_RVALUE_REFERENCES" redefined
#  define BOOST_NO_CXX11_RVALUE_REFERENCES
^
<command-line>:0:0: note: this is the location of the previous definition
 
SAMPLING FOR MODEL 'latent-factor-model' NOW (CHAIN 1).
 
Gradient evaluation took 0 seconds
1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
Adjust your expectations accordingly!
 
 
Iteration:    1 / 4000 [  0%]  (Warmup)

My R code and Stan code are below.

##
## Simulated data
##
library(tidyverse)
library(rstan)
simgrm <- function(n_subj, n_items, n_cat){
    item_prob <- function(t, a, k){
        c(0, plogis(k - a*t), 1) %>%
            diff()
    }
    item_sample <- function(t, a, k){
        item_prob(t, a, k) %>% sample(1:length(.), 1, prob=.)
    }
    theta <- rnorm(n_subj)
    alpha <- rnorm(n_items)
    kappa <- t(sapply(1:n_items
                    , function(j){
                        sort(c(rnorm(n_cat - 1)))
                    }))
    out <- data_frame(Respondent_Idx=1:n_subj) %>%
        crossing(Item_Idx=1:n_items) %>%
        mutate(Y=mapply(item_sample
                      , t=theta[Respondent_Idx]
                      , a=alpha[Item_Idx]
                      , k=as.list(data.frame(t(kappa[Item_Idx, ])))))
    return(out)
}
 
set.seed(1984)
n_cat <- 3L
n_respondents <- 500L
n_items <- 5L
tmpdat <- simgrm(n_respondents, n_items, n_cat)
standat <- list(
    n_data=nrow(tmpdat)
  , n_respondents=length(unique(tmpdat$Respondent_Idx))
  , n_items=length(unique(tmpdat$Item_Idx))
  , n_cat=n_cat
  , Respondent_Idx=tmpdat$Respondent_Idx
  , Item_Idx=tmpdat$Item_Idx
  , Y=tmpdat$Y
)
 
stanout <- stan('latent-factor-model.stan'
              , data=standat
              , iter=4000
              , chains=1)

data {
    int <lower=1> n_data;
    int <lower=1> n_items;
    int <lower=1> n_respondents;
    int <lower=1> n_cat;
    int <lower=1, upper=n_items>       Item_Idx[n_data];
    int <lower=1, upper=n_respondents> Respondent_Idx[n_data];
    int <lower=1, upper=n_cat>         Y[n_data];
}
 
parameters {
    vector[n_respondents] theta;
    real<lower=0> alpha[n_items];
    ordered[n_cat - 1] kappa[n_items];
    real mu_kappa;
    real<lower=0> sigma_kappa;
}
 
model {
    theta ~ normal(0.0, 1.0);
    alpha ~ cauchy(0.0, 5.0);
    mu_kappa ~ normal(0.0, 5.0);
    sigma_kappa ~ cauchy(0.0, 5.0);
    for (j in 1:n_items){
       for (k in 1:(n_cat - 1)){
           kappa[j, k] ~ normal(mu_kappa, sigma_kappa);
       }
    }
    for (n in 1:n_data) {
        Y[n] ~ ordered_logistic(theta[Respondent_Idx[n]] * alpha[Item_Idx[n]], kappa[Item_Idx[n]]);
    }
}

Any help would be appreciated!

Thank you,
McKay

[edited to set off code]


Troubles with Discourse
#2

I edited the post to add triple back-ticks to wrap code so it displays fixed width.

It would help if you gave us your sessionInfo() output. I don’t even have a guess as to what’s going on, but the RStan devs should.


#3

Thanks for fixing my formatting! (I’m not familiar with this interface…).

Results of sessionInfo() just before calling the stan function:

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
 
Matrix products: default
 
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252  
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                         
[5] LC_TIME=English_United States.1252   
 
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    
 
other attached packages:
[1] bindrcpp_0.2         rstan_2.15.1         StanHeaders_2.15.0-1
[4] dplyr_0.7.0          purrr_0.2.2.2        readr_1.1.1        
 [7] tidyr_0.6.3          tibble_1.3.3         ggplot2_2.2.1      
[10] tidyverse_1.1.1    
 
loaded via a namespace (and not attached):
[1] Rcpp_0.12.11     bindr_0.1        compiler_3.4.0   cellranger_1.1.0
[5] plyr_1.8.4       forcats_0.2.0    tools_3.4.0      jsonlite_1.5   
 [9] lubridate_1.6.0  gtable_0.2.0     nlme_3.1-131     lattice_0.20-35
[13] rlang_0.1.1      psych_1.7.5      parallel_3.4.0   haven_1.0.0    
[17] gridExtra_2.2.1  stringr_1.2.0    httr_1.2.1       xml2_1.1.1     
[21] hms_0.3          stats4_3.4.0     grid_3.4.0       inline_0.3.14  
[25] glue_1.1.0       R6_2.2.2         readxl_1.0.0     foreign_0.8-68 
[29] reshape2_1.4.2   modelr_0.1.0     magrittr_1.5     scales_0.4.1   
[33] assertthat_0.2.0 mnormt_1.5-5     rvest_0.3.2      colorspace_1.3-2
[37] stringi_1.1.5    lazyeval_0.2.0   munsell_0.4.3    broom_0.4.2    

#4

Thanks. @bgoodri or @jonah are probably going to have to answer this one.


#5

It worked for me on Windows.


#6

Bummer. Thanks for looking at this. After I read your response, I tried running the code on a different computer and it worked for me too. Not sure what is wrong with my laptop… Thanks again.