Home‎ > ‎Schedule‎ > ‎

### R commands for Feb 23

 # Hinton's study time data p.265studytimedata = data.frame(study.time=c(40,43,18,10,25,33,27,17,30,47),exam.score=c(58,73,56,47,58,54,45,32,68,69))plot(studytimedata[,1:2])#Calculating pearson's r via z-scorespopsd <- function(x,n)(sqrt(var(x)*(n-1)/n))n = length(studytimedata\$exam.score)studytimedata\$study.time.z    =  (studytimedata\$study.time - mean(studytimedata\$study.time))/popsd(studytimedata\$study.time,n)studytimedata\$exam.score.z  = (studytimedata\$exam.score - mean(studytimedata\$exam.score))/popsd(studytimedata\$exam.score,n)plot(studytimedata[,3:4])r = sum(studytimedata\$study.time.z * studytimedata\$exam.score.z)/ndf = n -2#Or use the cor commandcor(studytimedata\$study.time,studytimedata\$exam.score)#Calculating practical significanceSP = sum((studytimedata\$study.time - mean(studytimedata\$study.time))*(studytimedata\$exam.score - mean(studytimedata\$exam.score)))SSx = sum((studytimedata\$study.time - mean(studytimedata\$study.time))^2)SSy = sum((studytimedata\$exam.score - mean(studytimedata\$exam.score))^2)r2 = SP^2/(SSx*SSy)# relation to rr = sqrt(r2)r = SP/sqrt(SSx*SSy)# regression model Y = A + B*XB = r*(sd(studytimedata\$exam.score)/sd(studytimedata\$study.time))lm(studytimedata\$exam.score  ~ studytimedata\$study.time)