For example, number of nodes in network studies change both sparsity, edge strength and dimension. Too much! Keep it fixed to one case
Try first using only 2 repititons, with nCores = 1
Use browser() for debugging (with nCores = 1)
Try local first before using a cluster
Example (see also examples folder)
# Install the package:
# library("devtools")
# install_github("sachaepskamp/parSim")
library("parSim")
# Some function we might use:
bias <- function(x,y){abs(x-y)}
# Run the simulation:
Results <- parSim(
# Any number of conditions:
sampleSize = c(50, 100, 250),
beta = c(0, 0.5, 1),
sigma = c(0.25, 0.5, 1),
# Number of repititions?
reps = 100,
# Parallel?
nCores = 1,
# Write to file?
write = FALSE,
# Export objects (only needed when nCores > 1):
export = c("bias"),
# R expression:
expression = {
# Load all R packages in the expression if needed
# library(...)
# Want to debug? Enter browser() and run the function. Only works with nCores = 1!
# browser()
# Enter whatever codes you want. I can use the conditions as objects.
X <- rnorm(sampleSize)
Y <- beta * X + rnorm(sampleSize, sigma)
fit <- lm(Y ~ X)
betaEst <- coef(fit)[2]
Rsquared <- summary(fit)$r.squared
# Make a data frame with one row to return results (multple rows is also possible but not reccomended):
data.frame(
betaEst = betaEst,
bias = bias(beta,betaEst),
Rsquared = Rsquared
)
}
)
# Analyze the results:
library("ggplot2")
library("tidyr")
# We want to plot bias and R-squared. Let's first make it long format:
Long <- gather(Results,metric,value,bias:Rsquared)
# Make factors with nice labels:
Long$sigmaFac <- factor(Long$sigma,levels = c(0.25,0.5,1), labels = c("Sigma: 0.025", "Sigma: 0.5", "Sigma: 1"))
# Now let's plot:
g <- ggplot(Long, aes(x = factor(sampleSize), y = value, fill = factor(beta))) +
facet_grid(metric ~ sigmaFac, scales = "free") +
geom_boxplot() +
theme_bw() +
xlab("Sample size") +
ylab("") +
scale_fill_discrete("Beta")
print(g)
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products.
Learn more.
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products.
You can always update your selection by clicking Cookie Preferences at the bottom of the page.
For more information, see our Privacy Statement.
Essential cookies
We use essential cookies to perform essential website functions, e.g. they're used to log you in.
Learn more
Always active
Analytics cookies
We use analytics cookies to understand how you use our websites so we can make them better, e.g. they're used to gather information about the pages you visit and how many clicks you need to accomplish a task.
Learn more