Hallo Is there an elegant way to do the following: Dataset consists of 2 variables: var1: some measurements, and var2: a grouping variable with two values, 1 and 2. There are (say) 10 measurements from group 1 and 15 measurements from group 2. The idea is to study the permutation distribution of mean(group 1) * mean(group2). One way would be to permute 1s and 2s and select the corresponding measurements; calculate the difference in means. Redo this 1000 times, say. Etc. Any help is much appreciated. Thanks Jacob Jacob L van Wyk Department of Statistics University of Johannesburg, APK P O Box 524 Auckland Park 2006 South Africa Tel: +27 11 489 3080 Fax: +27 11 489 2832 [[alternative HTML version deleted]]
> data1 <- expand.grid(var1=1:15, var2=1:2)> test <- replicate(1000, with(data.frame(var1=data1$var1, var2=sample(data1$var2)), diff(tapply(var1, var2, mean)))) > hist(test) ------------------------------------------------------------------- Jacques VESLOT CNRS UMR 8090 I.B.L (2?me ?tage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr ------------------------------------------------------------------- Jacob van Wyk a ?crit :> Hallo > > Is there an elegant way to do the following: > > Dataset consists of 2 variables: var1: some measurements, and var2: a grouping variable with two values, 1 and 2. > There are (say) 10 measurements from group 1 and 15 measurements from group 2. > The idea is to study the permutation distribution of mean(group 1) * mean(group2). > One way would be to permute 1s and 2s and select the corresponding measurements; calculate the difference in means. > Redo this 1000 times, say. Etc. > > Any help is much appreciated. > Thanks > Jacob > > > Jacob L van Wyk > Department of Statistics > University of Johannesburg, APK > P O Box 524 > Auckland Park 2006 > South Africa > Tel: +27 11 489 3080 > Fax: +27 11 489 2832 > > > > [[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. >
On Thu, 20 Jul 2006, Jacob van Wyk wrote:> Hallo > > Is there an elegant way to do the following: > > Dataset consists of 2 variables: var1: some measurements, and var2: a grouping variable with two values, 1 and 2. > There are (say) 10 measurements from group 1 and 15 measurements from group 2. > The idea is to study the permutation distribution of > mean(group 1) * mean(group2).^^^^^^^^^^^^^^^^^^^^^^^^^^^^> One way would be to permute 1s and 2s and select the corresponding > measurements; calculate the difference in means.^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ what test statistic do you want to use? Product or difference of means? The latter one is easy: library("coin") independence_test(var1 ~ var2, data = <your data>, ...) Torsten> Redo this 1000 times, say. Etc. > > Any help is much appreciated. > Thanks > Jacob > > > Jacob L van Wyk > Department of Statistics > University of Johannesburg, APK > P O Box 524 > Auckland Park 2006 > South Africa > Tel: +27 11 489 3080 > Fax: +27 11 489 2832 > > > > [[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. > >
On Thu, 20 Jul 2006, Jacob van Wyk wrote:> Hallo > > Is there an elegant way to do the following: > > Dataset consists of 2 variables: var1: some measurements, and var2: a grouping variable with two values, 1 and 2. > There are (say) 10 measurements from group 1 and 15 measurements from group 2. > The idea is to study the permutation distribution of mean(group 1) * mean(group2). > One way would be to permute 1s and 2s and select the corresponding measurements; calculate the difference in means. > Redo this 1000 times, say. Etc.There are only choose(25,10) == 3268760 values. You can enumerate all the sums of the values in one group following: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/76450.html from which the products of the means are easily obtained. Takes about 5 seconds on my 2GHz AMD running Windows XP. HTH, Chuck Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0717