Closed carldister closed 6 years ago
Also, I tried tweaking the example slightly and received and error - here is my slight modification and the error follows:
ttest<-function(n,loc,scale){ stat<-nlocscale
decision<-abs(stat)>1.96
return(list("decision"=decision))
}
n_grid<-c(50,100,250,500) loc_grid<-c(0,1,0.2) scale_grid<-c(1,2)
param_list=list("n"=n_grid, "loc"=loc_grid, "scale"=scale_grid)
MC_result<-MonteCarlo(func=ttest, nrep=1000, param_list=param_list)
Error in MonteCarlo(func = ttest, nrep = 1000, param_list = param_list) : object 'packages' not found
Thank you for any advice you may have on these issues
Hi! The error "Scalars in list components cannot be named." refers to the list returned by your runfunction. The scalars in this list are not allowed to be named. As an example
test_func<-function(n,loc,scale){ sample<-rnorm(n, loc, scale) stat<-sqrt(n)*mean(sample)/sd(sample) decision<-abs(stat)>1.96 names(decision)<-"decision" return(list("decision"=decision)) } will reproduce your error. But this will work:
test_func<-function(n,loc,scale){ sample<-rnorm(n, loc, scale) stat<-sqrt(n)*mean(sample)/sd(sample) decision<-abs(stat)>1.96 names(decision)<-"decision" return(list("decision"=unname(decision))) }
With regard to your modification of the example. There is a known bug that appears if the function to simulate is a simple deterministic one. This will be fixed soon with the next version of the package. But obviously, trying to put deterministic functions in there doesn't really make sense. Why would you want to repeat calculating that function many times if the outcome is always the same?
The solution of using the "unname" worked great! Thanks so much for your help
I tried the sample Montecarlo example on my version of R and it worked perfectly. Then, I made a much larger project with many more variables and received this error:
Error in MonteCarlo(func = runfunction, nrep = 1000, param_list = param_list) : Scalars in list components cannot be named.
I tried to make sure that the variable types matched the examples. Is there a limit to how many variables and how many combinations, or is that simply CPU execution time limited?