[R] Using perm.t.test() upon Matrix/Dataframe columns parted by factor instead of t.test()
dwinsemius at comcast.net
Fri Jul 29 15:37:17 CEST 2011
On Jul 29, 2011, at 9:11 AM, R. Michael Weylandt <michael.weylandt at gmail.com
> Just a hunch I can't test from my phone, but in your final lapply
> you are passing a function of x that has no x in it, so I wouldn't
> be surprised if R was unhappy about that.
> Change the latter M's to x and see if that helps.
Not likely. 'x' is a formal argument of the function. He's using
lapply on a matrix. lapply is generally used for lists. but in this
case it results in sending individual numbers one-by-one to that
function, They are them each being t.tested against a ten item vector.
Failure is the predictable outcome but he did not see fit to reproduce
the informative error message that told him there was a mismatch of
He should use:
apply(M, 2, function(x)
> Michael Weylandt
> On Jul 29, 2011, at 6:30 AM, Gunnar Oehmichen <oehm8895 at uni-
> landau.de> wrote:
>> Hello dear subscribed Users,
>> this is my first post, so please forgive me for any inconveniences.
>> The following problem: I have a dataframe containing a factor column.
>> For each column i would like to compare means as parted by the
>> factor. Using the normal t.test function I have already achieved my
>> goal. But i think, that for my original data, a permutational
>> t.test would be better suited. Herein lies the problem. Whereas i
>> can specify the factor as group parting in the formular expression
>> I am not able to do this with perm.t.test() from deducer. Have fun
>> with this trivial undergraduate problem.
>> c(rep("A", 5), rep("B", 5))->Faktor
>> matrix(rnorm(100, mean=20, sd=4), nrow=10, ncol=10)->M
>> colnames(M) <- c("species1","species2",
>> ###Conventional T-Test to test for differences of each species per
>> M, function(x)
>> t.test(x~ Faktor)
>> ###Trying it for perm.t.test without the helpful formular
>> expression. Does not work
>> M, function(x)
>> perm.t.test(subset(M, Faktor=="A"),
>> subset(M, Faktor=="B"))
>> Thank you very much for your help,
>> R-help at r-project.org mailing list
>> 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 r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help