philchalmers / SimDesign

Structure for organizing Monte Carlo simulations in R
http://philchalmers.github.io/SimDesign/
61 stars 17 forks source link

Code in SimDesign Package Won't Run #4

Closed ronb1000 closed 6 years ago

ronb1000 commented 6 years ago

results <- runSimulation(Design, replications = 1000, generate=Generate, analyse=Analyse, summarise=Summarise) Returns error message: Error: Function arguments for analyse are not correct!!!

Error arises for all your examples.

Using latest version of RStudio and R 3.1.3 on windows 10 computer. First time I have ever had sample code in a Package fail.

mattsigal commented 6 years ago

Can you link to which examples you are trying to run? And can you check that by this point in your script, that the Generate, Analyse, and Summarise objects exist in your workspace?

I'm not sure if it is related, but you might need to upgrade your version of R - the latest version for Windows is 3.4.2.

philchalmers commented 6 years ago

Matt is right, without seeing your code we have no idea what went wrong. What does the default example in runSimulation() give you?

library(SimDesign)
SimFunctions()

#### Step 1 --- Define your conditions under study and create design data.frame

Design <- data.frame(N = c(10, 20, 30))

#~~~~~~~~~~~~~~~~~~~~~~~~
#### Step 2 --- Define generate, analyse, and summarise functions

# help(Generate)
Generate <- function(condition, fixed_objects = NULL){
    dat <- with(condition, rnorm(N, 10, 5)) # distributed N(10, 5)
    dat
}

# help(Analyse)
Analyse <- function(condition, dat, fixed_objects = NULL){
    ret <- mean(dat) # mean of the sample data vector
    ret
}

# help(Summarise)
Summarise <- function(condition, results, fixed_objects = NULL){
    ret <- c(mu=mean(results), SE=sd(results)) # mean and SD summary of the sample means
    ret
}

#~~~~~~~~~~~~~~~~~~~~~~~~
#### Step 3 --- Collect results by looping over the rows in design

# run the simulation
Final <- runSimulation(design=Design, replications=1000,
                       generate=Generate, analyse=Analyse, summarise=Summarise)
Final
ronb1000 commented 6 years ago

I removed R 3.1.3 and installed R 3.4.2. Code in Phil's comment above now runs fine. Thanks for the quick reply. SimDesign is a great idea.

Ron

philchalmers commented 6 years ago

Thank you for the update. We'll add this higher version dependency in the next release to avoid the issue altogether.