[R] runs.test in by() statement
David Winsemius
dwinsemius at comcast.net
Wed Jan 14 15:55:32 CET 2009
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)))
More information about the R-help
mailing list