[R-sig-teaching] Computing correlations including the p values
William Revelle
lists at revelle.net
Wed Apr 4 05:00:37 CEST 2012
Dear AbouEl-Makarim Aboueissa,
As people have pointed out before, if you are interested in how to use R to teach statistics, this is the appropriate mailing list, if you want to learn how to use R, the appropriate mailing list is the r-help mailing list.
However, to answer your question:
To get the p-values of a group of correlations, you might try the corr.test function in psych.
Unfortunately, although this will give you the correct correlations, it will not give the correct p values for different sets of x and y.
So you need to work a little harder
> x1<-c(12,3,45,32,34,56,7,89)
> x2<-c(6,8,9,6,7,44,33,22)
> x3<-c(45,7,6,89,23,45,67,22)
>
> y1<-c(21,43,77,32,23,45,78,90)
> y2<-c(32,56,78,90,34,23,11,23)
> y3<-c(8,90,34,68,72,17,27,35)
> df <- data.frame(x1,x2,x3,y1,y2,y3)
> c <- corr.test(df)
rs <- c$r[4:6,1:3]
ps <- c$p[4:6,1:3]
Bill
On Apr 3, 2012, at 9:32 PM, Ista Zahn wrote:
> On Tue, Apr 3, 2012 at 10:24 PM, AbouEl-Makarim Aboueissa
> <aaboueissa at usm.maine.edu> wrote:
>> Hi,
>>
>> I am able to get the correlations as:
>>
>> xxx<-cbind(x1,x2,x3)
>> yyy<-cbind(y1,y2,y3)
>> cor(xxx,yyy)
>> This yields same results as yours.
>>
>> But I could not get the p values yet.
>
> What have you tried? What went wrong? Getting the p.values is not a
> straightforward extension of the approach I illustrated earlier, but
> it is something you can figure out with a few google searches. If you
> run into problems I'll be glad to help, but please do make an effort
> to figure it out on your own.
>
> Best,
> Ista
>
>>
>> thanks
>> abou
>>
>>
>>>>> Ista Zahn <istazahn at gmail.com> 4/3/2012 8:05 PM >>>
>>
>> Hi,
>>
>> For the correlations you just need to understand how matrix indecies work in
>> R:
>>
>> cor(cbind(x1, x2, x3, y1, y2, y3))[4:6, 1:3]
>>
>> I'll leave it to you to figure out the p values part.
>>
>> Best,
>> Ista
>>
>> On Tue, Apr 3, 2012 at 7:48 PM, AbouEl-Makarim Aboueissa
>> <aaboueissa at usm.maine.edu> wrote:
>>> Dear All: (revise of the previous message)
>>>
>>> I have another silly question. How I can compute the correlations of two
>>> groups of variables including the p values. For example how to compute the
>>> correlations of the X's with Y's only of these two groups of variables
>>>
>>> x1<-c(12,3,45,32,34,56,7,89)
>>> x2<-c(6,8,9,6,7,44,33,22)
>>> x3<-c(45,7,6,89,23,45,67,22)
>>>
>>> y1<-c(21,43,77,32,23,45,78,90)
>>> y2<-c(32,56,78,90,34,23,11,23)
>>> y3<-c(8,90,34,68,72,17,27,35)
>>>
>>>
>>> This what I need to get:
>>>
>>> y1 y2 y3
>>>
>>> x1 corr(x1,y1) corr(x1,y2) corr(x1,y3)
>>> p value p value p value
>>>
>>> x2 corr(x2,y1) corr(x2,y2) corr(x2,y3)
>>> p value p value p value
>>>
>>> x3 corr(x3,y1) corr(x3,y2) corr(x3,y3)
>>> p value p value p value
>>>
>>>
>>>
>>> Thank you very much
>>> abou
>>>
>>>
>>> ==========================
>>> AbouEl-Makarim Aboueissa, Ph.D.
>>> Associate Professor of Statistics
>>> Graduate Program Coordinator
>>> Department of Mathematics & Statistics
>>> University of Southern Maine
>>> 96 Falmouth Street
>>> P.O. Box 9300
>>> Portland, ME 04104-9300
>>> USA
>>>
>>>
>>> Tel: (207) 228-8389
>>> Fax: (207) 780-5607
>>> Email: aaboueissa at usm.maine.edu
>>> aboueiss at yahoo.com
>>>
>>> Office: 301C Payson Smith
>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-teaching at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
>
> _______________________________________________
> R-sig-teaching at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
>
William Revelle http://personality-project.org/revelle.html
Professor http://personality-project.org
Department of Psychology http://www.wcas.northwestern.edu/psych/
Northwestern University http://www.northwestern.edu/
Use R for psychology http://personality-project.org/r
It is 5 minutes to midnight http://www.thebulletin.org
More information about the R-sig-teaching
mailing list