| pmgRepeatTrials {pmg} | R Documentation |
A simple function to repeat an expression several times as an aid to simplifying simulations.
pmgRepeatTrials(expr, n = 10)
expr |
An R expression, such as rnorm(1) or
{x <- rnorm(10); t.test(x)\$p.value} that will be repeated n times. |
n |
Number of times to repeat the expressions. The default is 10. |
This functions aids in doing simulations. Rather than explicitly write
a for loop or use sapply this function will call
sapply on the expression.
A GUI for this appears in pmg under the Simluation tab. The "quick action" will call the function on the results of the simulation.
The output of a sapply call can be a vector, matrix, ... If it
is a vector, it is transposed/
This function and GUI was suggested by Daniel Kaplan at useR!2007
John Verzani
res <- pmgRepeatTrials(rnorm(1))
hist(res)
g = data.frame(
father = c(78.5, 78.5, 77.5, 76.0, 75.5),
mother = c(67.0, 68.0, 66.0, 65.5, 62.0),
sex = c("M", "M", "F", "F", "M"),
nkids = c(4, 4, 1, 2, 5)
)
res <- pmgRepeatTrials(coef(lm(father~ sex + sample(nkids),data=g)),100)
print(res)