An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090114/5bdf0359/attachment-0001.pl>
runs.test in by() statement
3 messages · christiaan pauw, David Winsemius
Thanks to Patric and Christian for swift and accurate help I still had to learn the differnce between calling a function and passing a call to a function. I had to coerce the first variable to be a function but then it worked. by(as.factor(exampledata$var), exampledata$interviewer, runs.test) Regards Christiaan
On 14/01/2009, christiaan pauw <cjpauw at gmail.com> wrote:
exampledata<-data.frame(interviewer=rep(letters[1:2], 1), var=round(var=runif(40))) I do the runs test on "var" and it works runs.test(as.factor(exampledata$var))
I can catagorise the data by "interviewer" and get means using the by() statement and that works perfectly by(exampledata$var, exampledata$interviewer, mean)
Why is it impossible to use runs.test() as the function in the by() statement instead of mean by(exampledata, exampledata$interviewer, runs.test(as.factor(exampledata$var))) Error in FUN(X[[1L]], ...) : could not find function "FUN" thanks Christiaan
I always have trouble with "by" myself. I don't usually get an answer
as quickly as I did here. I usually give up and move to "aggregate" or
"ave".
First I limited the data given to "by" in the first argument to just
the variable under question. Then by the time R sends the information
to your function it may not be named what it was in the global
environment, so I packaged those two functions "runs.test" and
"as.factor" inside a packaging function that converted its name to
"x". Seems to give possibly sensible results. See if this works for you.
> by(exampledata$var, exampledata$interviewer,
function(x) {runs.test(as.factor(x))} )
exampledata$interviewer: a
Runs Test
data: as.factor(x)
Standard Normal = -0.8823, p-value = 0.3776
alternative hypothesis: two.sided
----------------------------------------------------------------------------------------------
exampledata$interviewer: b
Runs Test
data: as.factor(x)
Standard Normal = 0, p-value = 1
alternative hypothesis: two.sided
David Winsemius On Jan 14, 2009, at 3:13 AM, christiaan pauw wrote: > by(exampledata, exampledata$interviewer, > runs.test(as.factor(exampledata$var)))