#The first part of this syntax will illustrait how to compute the confidence intervals for correlation coefficients
#rank order correlations, phi correlation, and point biserial will be covered
install.packages("stats")
#this package has a large amount of statistcal functions; we will be using the cor.test function
#the cor.test function provides a test of significance and CI for a basic correlation coefficient
#Use the data set C0202DT
d=read.table(file=file.choose(),header=TRUE)
attach(d)
d
cor.test(TIME,PUBS)
#this gives us all test/CI information for the correlation b/t TIME and PUBS
#we can do this with the point biserial coefficient as well
#use data set C0203DT for this exercise
#we will have to recode the variables again given the dichotomous variable (stimulus) is not numerical
#if you have not installed car yet, do so by the command install.packages("car")
library(car)
e=read.table(file=file.choose(),header=TRUE)
attach(e)
e
STIM=recode(STIMULUS.,"'None'=0;else=1")
# we have created a new recoded variable for STIm
cor.test(TASK,STIM)
#this is our point biserial correlation with test and CI
#we can do this with a phi coefficient the same way: use data set C0204DT
f=read.table(file=file.choose(),header=TRUE)
attach(f)
f
cor.test(HOMEOWN,CANDIDAT)
#to do this with a rank order, the cor.test function has a built in command
#use data set C0205DT
g=read.table(file=file.choose(),header=TRUE)
attach(g)
g
cor.test(X,Y,method="spearman")
#this is CI/test for spearman rank order(rho) correlation
#---------------
#This second part of the syntax will cover polyserial and tetrachoric correlation
#Use data set C0203DT from the book CD for the first worked example
#there was no data set in the book for the tetrachoric, so no example will be provided
install.packages("polycor")
library("polycor")
#This is a package that can compute the biserial/tetrachoric correlation among other things
d=read.table(file=file.choose(),header=TRUE)
Attach(d)
d
polyserial(TASK,STIMULUS.)
#This is the biserial correlation b/t a continuous (TASK) and an artificially dichotomized (STIMULUS.) variable
#A tetrachoric correlation can be computed using the polychor(X,Y) where X and Y are both artificially dichotomized variables
#Note that this package has the ability to produce standard errors,use maximmum likelihood estimates, and test bivariate normality
#To view these options simply type ?polychor or ?polyserial