0

I am running code to simulate data and then run regression mixture models on them. I am using the FLEXMIX package for the regression mixture part and the package PARAMTEST for the simulations. I have about a dozen different simulation conditions, with a dozen estimated parameters and more than 30 output statistics being returned.

I get successful runs for number of simulation trials less than 20, but more than 20, I get errors like this below, stating that I am trying to access slots from NULL objects.

Error in unlist(x[[m]]@parameters) : 
  trying to get slot "parameters" from an object of a basic class ("NULL") with no slots
Called from: unlist(x[[m]]@parameters)

(The FLexmix package model output is in slots inside the output, which I access). I have tried putting in IF conditions checking that the estimated model is non-null, but I still get these errors. Sample code showing how I check that model objects are not null is below.

mix2_orig <- flexmix(z ~ x*y + I(x^2) + I(y^2), data=sim_dat, k=2)
mix2 <- relabel(mix2_orig, by = "model", which = "Intercept")
### 2-class model output stats
out2<-summary(mix2)

if (!(is.null(out2))){
    Prior_Class1<-if(!is.na(out2@comptab$prior[1]))
    cat("\n2-class solution\n")
    Prior_Class2<-if(!is.na(out2@comptab$prior[2]))
    #out2@comptab$ratio
    Ratio_Class1<-out2@comptab$ratio[1]
    Ratio_Class2<-out2@comptab$ratio[2]
    #out2@comptab$size
    Size_Class1<-out2@comptab$size[1]
    Size_Class2<-out2@comptab$size[2]
    sigma_comp1<-parameters(mix2, component=1)[[7]]
    sigma_comp2<-parameters(mix2, component=2)[[7]]
    
    AIC2<-out2@AIC
    BIC2<-out2@BIC
    sBIC2<-BIC2-7*log(sample)+ log((sample+2)/24)
    actual=sim_dat$class_label
    pred=mix2@cluster
    rmse2<-sqrt(mean((actual - pred)^2))
    
    
  }

Any ideas the simulation fails for larger numbers of trials? Is it due to accessing the slots in the Flexmix output objects too many times - Is it bad practice to access S4 objects slots directly using @??

user2450223
  • 235
  • 2
  • 10

0 Answers0