Hi everybody

I am a recent convert from SAS so please excuse me if this is all very
obvious:

I want to use the runs test {runs.test() in package tseries} to test the
randomness of a certain variable in a survey for each interviewer. I tried
to us the by() statement but it doesn't seem to work with runs.test() as the
function.

Here is what I have: Consider a data frame with two variables and 40
observations. Column 1 is the name of the interviewer and 2 is a variable
that could be either 0 or 1. ] Thus "interviewer" and  "var". This generates
such a data frame

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))

Runs Test

data:  as.factor(exampledata$var)
Standard Normal = -1.626, p-value = 0.1039
alternative hypothesis: two.sided

I can catagorise the data by "interviewer" and get means using the by()
statement and that works perfectly

by(exampledata$var, exampledata$interviewer, mean)

exampledata$interviewer: a
[1] 0.4
------------------------------------------------------------
exampledata$interviewer: b
[1] 0.35

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"

Can someone please tell me why this is the case. I tried aggregate() too but
with the same result

thanks
Christiaan

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to