You requested this report (PR#1880)
berwin@maths.uwa.edu.au
berwin@maths.uwa.edu.au
Tue, 6 Aug 2002 10:58:40 +0200 (MET DST)
Hi guys,
I am planning to let my students do some simulations regarding the
bias of the sample standard deviation. The following function is
pretty standard (so I hope :) ):
> sim <- function(nrng, replic, true.s, random, ...){
+ res <- NULL
+ for(n in nrng){
+ data <- matrix(random(n*replic,...), ncol=replic)
+ val <- sqrt(apply(data, 2, var))
+ res <- rbind(res,
+ cbind(bias=val-true.s, n=n))
+ }
+ res
+ }
It takes a vector of sample sizes, a number (the number of
replications we want to simulate), the true value of the standard
deviation and a function that generates the random number (which may
depend on additional paramters). So let's try this:
> nrng <- c(2,4,8,16,32,64)
> replic <- 500
> true.s <- 2
> tmp <- sim(nrng, replic, true.s, rnorm, sd = 2)
Yes, seems to work. Now I thought of perhaps creating a list of
several scenarios (random numbers) and loop over it. So I tried:
> dist <- list(list(rnorm, true.s = 2, sd=2),
+ list(rexp, true.s = 1)
+ )
Followed by
> res <- sim(nrng, replic, dist[[1]][2], dist[[1]][1], dist[[1]][-c(1,2)])
Error in as.vector(data) : couldn't find function "random"
O.k., this doesn't work. So let us try:
> res <- sim(nrng, replic, dist[[1]][2], as.function(dist[[1]][1]), dist[[1]][-c(1,2)])
Error in as.function.default(dist[[1]][1]) :
invalid body argument for "function"
Should NEVER happen; please bug.report() [mkCLOSXP]
No idea why you consider this a bug. :) I would have been willing to
put it down to my misuse of R. But since you requested a bug report,
here it is.
Cheers,
Berwin
BTW: How can I actually do what I want to do? I realise that I am
probably on a completely wrong track regarding the passing of the
... parameters.
--please do not edit the information below--
Version:
platform = i686-pc-linux-gnu
arch = i686
os = linux-gnu
system = i686, linux-gnu
status =
major = 1
minor = 5.1
year = 2002
month = 06
day = 17
language = R
Search Path:
.GlobalEnv, package:ctest, Autoloads, package:base
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._