Normal.example <- function(mean=0,sd=1,n=10){
x <- rnorm(n=n,mean=mean,sd=sd)
c(
Mean=mean(x),
Median=median(x),
Var=var(x)
)
}
Normal.simres <- Simulate(
Normal.example(mean,sd,n),
expand.grid(
mean=0,
sd=c(1,10),
n=c(10,100)
),
nsim=200,
trace=50)
genTable(sd(Median)~sd+n,data=Normal.simres)
expr.simres <- Simulate(
median(rnorm(n,mean,sd)),
expand.grid(
n=c(10,100),
mean=c(0,1),
sd=c(1,10)
),
nsim=200,
trace=50
)
genTable(c(mean(result),sd(result))~sd+n+mean,data=expr.simres)
## This takes a little bit longer
lm.example <- function(a=0,b=1,n=101,xrange=c(-1,1),serr=1){
x <- seq(from=xrange[1],to=xrange[2],length=n)
y <- a + b*x + rnorm(n,sd=serr)
lm.res <- lm(y~x)
coef <- lm.res$coef
names(coef) <- c("a","b")
coef
}
lm.simres <- Simulate(
lm.example(n=n,serr=serr),
expand.grid(
serr=c(0.1,1,10),
n=c(11,101,501)
),
nsim=200,
trace=50
)
genTable(c(sd(a),sd(b))~serr+n,data=lm.simres)
Run the code above in your browser using DataLab