Thursday, January 25, 2018

Calculation from the book- Correlation and Paired t-test

Lecture 31: Calculation of the Coefficient of correlation

cor(xx, use="complete.obs", method="pearson" )  #xx is data frame

Source: Garrett,H.E.- Statistics in Psychology and Education
Page: 140
>a=data.frame(x=c(50,54,56,59,60,62,61,65,67,71,71,74),y=c(22,25,34,28,26,30,32,30,28,34,36,40))
> a
x y
1 50 22
2 54 25
3 56 34
4 59 28
5 60 26
6 62 30
7 61 32
8 65 30
9 67 28
10 71 34
11 71 36
12 74 40
> Mx=sum(a$x)/nrow(a)# Mean of x variable =62.5
> My=sum(a$y)/nrow(a)# Mean of y variable =30.4
> dx=a$x-Mx# Mean deviated X score
> dy=a$y-My# Mean deviated Y score
> dx2=dx^2# Squared Mean deviation of X
> dy2=dy^2# Squared Mean deviation of y
> dxy=dx*dy #multiplication of dx and dy
> sumdxy=sum(dxy)# sum of dxy=321.50
> sumdx2=sum(dx2)#sum of x2=595
> sumdy2=sum(dy2)#sum of y2=282.92
> sumdxy/sqrt(sumdx2*sumdy2)
>corr=sumdxy/sqrt(sumdx2*sumdy2)# Result of the coefficient of correlation=0.7835978
> corr2# squared correlation for estimation of Z=0.61
> z=corr2/sqrt((1-corr2)/(12-2))
> z # Result of Fisher's Z # 3.125411
[1] 3.125411



==========================================================================
Lecture32 : Estimation of paired t- test
#ddroy_sta
Source: Source: Garrett,H.E.- Statistics in Psychology and Education 
Page no.227
Non-Manual
>a=data.frame(x=c(50,42,51,26,35,42,60,41,70,55,62,38),y=c(62,40,61,35,30,52,68,51,84,63,72,50))
> t.test(a$x,a$y,paired=TRUE)
Paired t-test
data: a$x and a$y
t = -4.8851, df = 11, p-value = 0.0004829
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-11.60439 -4.39561
sample estimates:
mean of the differences
-8
Manual
a=data.frame(x=c(50,42,51,26,35,42,60,41,70,55,62,38),y=c(62,40,61,35,30,52,68,51,84,63,72,50))
n=nrow(a)
dxy=a$y-a$x
mean=mean(dxy)
smallx=dxy-mean
smallx2=smallx^2
sumsmallx2=sum(smallx2)
sdd=sqrt(sumsmallx2/(n-1))
semd=sdd/sqrt(n)
t=mean/semd
a.x a.y dxy smallx smallx2
1 50 62 12 4 16
2 42 40 -2 -10 100
3 51 61 10 2 4
4 26 35 9 1 1
5 35 30 -5 -13 169
6 42 52 10 2 4
7 60 68 8 0 0
8 41 51 10 2 4
9 70 84 14 6 36
10 55 63 8 0 0
11 62 72 10 2 4
12 38 50 12 4 16
> t
[1] 4.885121
>
plot(dxy,pch=16, ylab="change from trial 1 to trial 2")# Tendency of difference
plot(a$x,a$y, pch=16,xlab="Trial1",ylab="Trial2")
> abline(0,1, col="blue", lwd=2)

N.B.:There are many online t-test, it gives bad result. I have tested it from our own book and it gives good result like book. you can check now












Image may contain: bird












Circles below or to the right of the blue one-to-one line indicate observations with a higher value for Typical than for Odd.


LikeShow More Reactions
Comment

No comments:

Post a Comment