Skip to content
Back to formatted view

Raw Message

Message-ID: <A0115461-6D50-4F06-8CFC-083CBEE86DD4@comcast.net>
Date: 2009-01-14T14:55:32Z
From: David Winsemius
Subject: runs.test in by() statement
In-Reply-To: <14a6d2ab0901140013q49183b37vd7849b8bcd2c05cb@mail.gmail.com>

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