Re: [R] how to iterate

From: Greg Snow <Greg.Snow_at_intermountainmail.org>
Date: Tue, 26 Jun 2007 09:37:10 -0600


Here is one approach:

> tmp <- scan()

1: 1 127 1 261 1 142 1 183 1 234 1 162 2 173 2 321 2 168 2 20: 197 2 213 2 261 3 198 3 126 3 167 3 154 3 134 3 187 3 109 3 210 41:
Read 40 items
> my.df <- as.data.frame( matrix(tmp, ncol=2, byrow=TRUE) )
> names(my.df) <- c('Category','Variable')
>
> my.df$Category <- factor(my.df$Category)
>
> fit1 <- aov( Variable ~ Category, data=my.df )
> summary(fit1)

            Df Sum Sq Mean Sq F value  Pr(>F)  
Category     2  13005    6503  2.7324 0.09355 .
Residuals   17  40456    2380                  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

>
> out1 <- replicate(99, summary(aov( sample(Variable) ~ Category,
data=my.df ) ) )
>
>
> # now look at a histogram of the p-values
> tmp <- sapply( out1, function(x) x['Pr(>F)'][1,1] )
> hist(tmp)
>
Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow_at_intermountainmail.org (801) 408-8111
> -----Original Message-----
> From: r-help-bounces_at_stat.math.ethz.ch
> [mailto:r-help-bounces_at_stat.math.ethz.ch] On Behalf Of
> Tavpritesh Sethi
> Sent: Tuesday, June 26, 2007 8:08 AM
> To: r-help_at_stat.math.ethz.ch
> Subject: [R] how to iterate
>
> for the following example dataset:-
> Category Variable 1 127 1 261 1 142 1 183 1 234 1 162 2
> 173 2 321 2 168 2
> 197 2 213 2 261 3 198 3 126 3 167 3 154 3 134 3 187 3 109 3
> 210 I have performed Anova on the measured variable
> (column#2) for the groups
> 1,2&3 (column#1). Now I want to randomize the values in C#2
> and reperform the test, say, a hundred times. Please suggest
> a way for this iteration. The loop I tried to write didn't work.
> Thanks.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
> ______________________________________________ R-help_at_stat.math.ethz.ch 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.
Received on Tue 26 Jun 2007 - 16:03:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 26 Jun 2007 - 16:32:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.