Skip to content
Prev 295862 / 398506 Next

simulation of levene's test

On Mon, May 28, 2012 at 12:14 PM, ?zg?r Asar <oasar at metu.edu.tr> wrote:
Or avoid the unncessary overhead of Rcmdr and use

library(car)

to provide levenTest instead.
It's also many orders of magnitude more efficient to preallocate "pv"
and then simply put things "into" it.

pv <- vector("real", 1000)
Setting the seed each loop seems excessive but I suppose it's a matter
of taste.
Is there any reason not to do this as x <- rnorm(60, 0, 2)
and this as as.factor(rep(1:3, each = 20))
Once you preallocate pv change this to

pv[i] <- leveneTest(x, group)$"Pr(>F)"[1]

But it's even better not to use the dollar sign shortcut here
(defensive programming and all that -- particularly with nonstandard
names which I'm pretty sure won't give a big error here but will
elsewhere)

pv[i] <- leveneTest(x, group)[["Pr(>F)"]][1]


And even better would be to do this all using the "replicate"
function, but I'll leave that as an exercise to the reader.

Michael