[R] How to run Shapiro-Wilk test for each grouped variable?
Iurie Malai
iurie.malai at gmail.com
Fri Apr 9 17:13:02 CEST 2010
Thank you very much, Jorge!
Your example worked for me. Here is the code:
d <- data.frame(data$groupFactor, data[2:17])
d
# p-values for the shapiro test (by levels of groupFactor)
with(d, aggregate(d[,-1], list(d[,1]), FUN = function(x)
shapiro.test(x)$p.value))
Iurie
2010/4/9 Jorge Ivan Velez <jorgeivanvelez at gmail.com>:
> Hi Iurie,
> Take a look at this example:
> # some data
> set.seed(123)
> x <- matrix(rnorm(100), ncol = 10)
> f <- sample(1:3, 100, replace = TRUE)
> d <- data.frame(f, x)
> d
> # p-values for the shapiro test (by levels of f)
> with(d, aggregate(d[,-1], list(d[,1]), FUN = function(x)
> shapiro.test(x)$p.value))
> HTH,
> Jorge
>
> On Fri, Apr 9, 2010 at 8:16 AM, Iurie Malai <> wrote:
>>
>> I want to run Shapiro-Wilk test for each variable in my dataset, each
>> grouped by variable groupFactor.
>> I have these working commands:
>>
>> > data.n<-names(data) # put names into a vector called data.n
>> > by(eval(parse(text=(paste("data",data.n[3],sep="$")))), data$factor,
>> > shapiro.test) #run shapiro.test
>>
>> but I must to change the variable number manualy. How to automate this?
>>
>> I tried this:
>>
>> > for (r in 3:18) {
>> > by(eval(parse(text=(paste("data",data.n[3],sep="$")))),
>> > data$groupFactor, shapiro.test)
>> > }
>>
>> but not working and no errors. Why?
>>
>> Please help.
>>
>> --
>> Regards,
>> Iurie Malai, Senior Lecturer
>> Department of Psychology
>> Faculty of Psychology and Special Education
>> Ion Creanga Moldova Pedagogical State University - www.upsm.md
>> http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University
>>
>> ______________________________________________
>> R-help at 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.
>
>
More information about the R-help
mailing list