Psyc 181 (2/2016)

R Commandsand Output for Data Analysis Problems

Problem 1-1cd

dollars= c(30, 20, 15, 10, 10, 60, 20, 25, 20, 30, 10, 5, 50, 40, 20, 10, 10, 0, 20, 50)

t.test(dollars, mu = 15, conf.level = 0.95)

sd(dollars)

One Sample t-test

data: dollars

t = 2.1315, df = 19, p-value = 0.04633

alternative hypothesis: true mean is not equal to 15

95 percent confidence interval:

15.13979 30.36021

sample estimates:

mean of x

22.75

sd(dollars)

[1] 16.26062

Note: If the data had been saved in an SPSS .sav file called HW1-1.sav on the working directory, the following commands will give the same results as shown above. First, install the foreign package using the command: install.packages("foreign", dep = TRUE)

library(foreign, pos=4)

data=read.spss("HW1-1.sav", to.data.frame = T)

attach(data)

t.test(dollars, mu = 15, conf.level = 0.95)

sd(dollars)

Note: When reading SPSS files, R will display the warning: Unrecognized record type 7, subtype 18 encountered in system file. This warning can be ignored.

Problem 1-1e

[copy sizeCIMean1code and paste at R prompt]

sizeCImean1(.05, 264.39, 10)

[1] 41

Problem 1-2cd

hours= c(5.5, 5.0, 6.5, 7.0, 4.5, 6.0, 5.0, 7.5, 5.0, 6.0, 8.0, 5.0, 6.5, 5.5, 7.0)

t.test(hours, mu = 6.8, conf.level = 0.95)

sd(hours)

One Sample t-test

data: hours

t = -2.9447, df = 14, p-value = 0.01066

alternative hypothesis: true mean is not equal to 6.8

95 percent confidence interval:

5.417306 6.582694

sample estimates:

mean of x

6

sd(hours)

[1] 1.052209

Problem 1-1e

sizeCImean1(.05, 1.107, .5)

[1] 69

Problem2-1c

group1 =c(32, 39, 26, 35, 43, 27, 40, 37, 34, 29)

group2 =c(36, 44, 47, 42, 49, 39, 46, 31, 33, 48)

t.test(group1,group2, conf.level = 0.95, var.equal=T)

sd(group1)

sd(group2)

Two Sample t-test

data: group1 and group2

t = -2.6793, df = 18, p-value = 0.01531

alternative hypothesis: true difference in means is not equal to 0

95 percent confidence interval:

-13.024129 -1.575871

sample estimates:

mean of x mean of y

34.2 41.5

sd(group1)

[1] 5.711587

sd(group2)

[1] 6.450667

Problem2-1d

[copy sizeCIMean2 code and paste at R prompt]

sizeCImean2(.05, 37.1, 5)

[1] 46

Problem2-2c

group1 = c(41,59,34,76,59,44,32,29,68,71,50,62,36,55,39,72,63,45,38,60,48,63)

group2 = c(64,49,54,36,49,64,74,35,58,40,60,51,68,67,25,37,40,53,72,38,61,40)

t.test(group1,group2, conf.level = 0.95, var.equal=T)

sd(group1)

sd(group2)

Two Sample t-test

data: group1 and group2

t = 0.097, df = 42, p-value = 0.9232

alternative hypothesis: true difference in means is not equal to 0

95 percent confidence interval:

-8.100917 8.919099

sample estimates:

mean of x mean of y

52.00000 51.59091

sd(group1)

[1] 14.19926

sd(group2)

[1] 13.76904

Problem2-2d

sizeCImean2(.05, 195.6, 8)

[1] 94

Problem2-3c

placebo= c(940, 1120, 1000, 880, 1140, 950, 900, 1060)

betablock= c(1270, 1050, 1010, 1190, 1030, 1230, 1140, 980)

t.test(placebo,betablock, conf.level = 0.95, var.equal=T)

sd(placebo)

sd(betablock)

Two Sample t-test

data: placebo and betablock

t = -2.1816, df = 14, p-value = 0.04668

alternative hypothesis: true difference in means is not equal to 0

95 percent confidence interval:

-225.578092 -1.921908

sample estimates:

mean of x mean of y

998.75 1112.50

sd(placebo)

[1] 98.62447

sd(betablock)

[1] 109.6423

Note: If the data had been saved in an SPSS or PSPP .sav file called HW2-3.sav on the working directory with a group indicator variable (1 for placebo and 2 for betablock)in the first column and the 16 SAT scores in the second column, the following commands will give the same results as shown above.

library(foreign, pos = 4)

data = read.spss("HW2-3.sav", to.data.frame = T)

attach(data)

t.test(SAT~group, conf.level = 0.95, var.equal = T)

sd(SAT[(group==1)]); sd(SAT[(group==2)])

Problem2-3d

sizeCImean2(.05, 10873, 100)

[1] 34

Problem3-1bc

pdsc=c(12, 10, 11, 14, 15, 9, 11, 12, 13, 10, 15, 10, 12, 13, 17, 11, 16, 13, 12, 14, 17, 12, 16, 18, 14, 21, 17, 16, 17, 22, 16, 22, 19, 20, 18, 16)

groups=c(1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3)

group=factor(groups, labels=c("Escitalopram", "Citalopram", "Placebo"))

panicData=data.frame(pdsc, group)

out=aov(pdsc~group, data=panicData)

summary(out)

TukeyHSD(out)

print(model.tables(out,"means"))

Df Sum Sq Mean Sq F value Pr(>F)

group 2 245.2 122.58 21.8 9.25e-07 ***

Residuals 33 185.6 5.62

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

TukeyHSD(out)

Tukey multiple comparisons of means

95% family-wise confidence level

Fit: aov(formula = pdsc ~ group, data = panicData)

$group

diff lwr upr p adj

Citalopram-Escitalopram 2.416667 0.04105701 4.792276 0.0454940

Placebo-Escitalopram 6.333333 3.95772367 8.708943 0.0000006

Placebo-Citalopram 3.916667 1.54105701 6.292276 0.0008425

print(model.tables(out,"means"))

Tables of means

group

Escitalopram Citalopram Placebo

11.833 14.250 18.167

Note: If the data had been saved in an SPSS or PSPP .sav file called HW3-1.sav on the working directory, the following commands will give the same results as shown above.

library(foreign, pos=4)

data=read.spss("HW3-1.sav", to.data.frame = T)

attach(data)

group= factor(drug, labels=c("Escitalopram", "Citalopram", "Placebo"))

out=aov(PDSC~group)

summary(out)

TukeyHSD(out)

Problem3-1d

Install MBESS package using the following command: install.packages("MBESS", dep = TRUE)

library(MBESS)

# set R2 equal to sample eta-squared (or sample partial eta-squared)

# set N equal to total sample size

# set K equal to number of levels of factor minus one

ci.R2(R2=.569, N=36, K=2, conf.level=.95, Random.Predictors=F)

$Lower.Conf.Limit.R2

[1] 0.301424

$Upper.Conf.Limit.R2

[1] 0.6937411

Problem3-1e

[copysizeCImeanBS (or sizeCIMean2) code and paste at R prompt]

h = c(1, -1, 0)

sizeCImeanBS(.0167, 5.62, 2.5, h)

[,1]

[1,] 42

Problem3-2c

score= c(14, 15, 11, 7, 16, 12, 15, 16, 10, 9, 18, 24, 14, 18, 22, 21, 16, 17, 14, 13, 16, 11, 10, 17, 13, 18, 12, 16, 6, 15, 18, 17, 11, 9, 9, 13, 18, 15, 14, 11)

gender=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2)

payment=c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2)

gender=factor(gender, labels=c("male", "female"))

payment=factor(payment, labels=c("flat_rate", "per_item"))

mydata=data.frame(score, gender, payment)

out=aov(score~gender+payment+gender*payment, data=mydata)

summary(out)

print(model.tables(out,"means"))

Df Sum Sq Mean Sq F value Pr(>F)

gender 1 27.2 27.23 2.200 0.1467

payment 1 70.2 70.23 5.675 0.0226 *

gender:payment 1 65.0 65.02 5.255 0.0278 *

Residuals 36 445.5 12.38

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

print(model.tables(out,"means"))

Tables of means

gender

male female

15.10 13.45

payment

flat_rate per_item

12.95 15.60

gender:payment

payment

gender flat_rateper_item

male 12.5 17.7

female 13.4 13.5

[continued]

group1 =c(14, 15, 11, 7, 16, 12, 15, 16, 10, 9)

group2 =c(18, 24, 14, 18, 22, 21, 16, 17, 14, 13)

group3 =c(16, 11, 10, 17, 13, 18, 12, 16, 6, 15)

group4 =c(18, 17, 11, 9, 9, 13, 18, 15, 14, 11)

m1 =mean(group1)

m2 =mean(group2)

m3 =mean(group3)

m4 =mean(group4)

sd1 =sd(group1)

sd2 =sd(group2)

sd3 =sd(group3)

sd4 =sd(group4)

m =c(m1, m2, m3, m4)

sd=c(sd1, sd2, sd3, sd4)

n =c(length(group1),length(group2), length(group3), length(group4))

[copyCIMeancode and paste at R prompt]

h =c(1, -1, 0, 0)

CIMean(.025, m, sd, n, h)

Estimate SE t df p-value LL UL

Equal Variances Assumed: -5.2 1.573213 -3.305337 36.00000 0.002154912 -8.879842 -1.520158

Equal Variances Not Assumed: -5.2 1.536952 -3.383319 17.61093 0.003393857 -8.965364 -1.434636

h =c(0, 0, 1, -1)

CIMean(.025, m, sd, n, h)

Estimate SE t df p-value LL UL

Equal Variances Assumed: -0.1 1.573213 -0.06356417 36.0000 0.9496689 -3.779842 3.579842

Equal Variances Not Assumed: -0.1 1.608657 -0.06216365 17.9165 0.9511208 -4.034831 3.834831

Problem3-2d

[copy sizeCIMean2 code and paste at R prompt]

sizeCImean2(.025, 12.38, 3)

[1] 56

Problem3-3a

speed = c(265,300,253,270,240,245,251,210,214,290,334,302,268,311,308,250,274,265,295,300)

style = c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2)

size = c(1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2)

style= factor(style, labels=c("Ariel", "Times"))

size= factor(size, labels=c("12", "10"))

mydata=data.frame(speed, style, size)

out=aov(speed~style + size + style*size, data=mydata)

summary(out)

print(model.tables(out,"means"))

Df Sum Sq Mean Sq F value Pr(>F)

style 1 6808 6808 10.661 0.00486 **

size 1 3302 3302 5.172 0.03708 *

style:size 1 22 22 0.035 0.85492

Residuals 16 10217 639

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

style

Ariel Times

253.8 290.7

size

12 10

285.1 259.4

Problem3-3b

group1 = c(265,300,253,270,240)

group2 = c(245,251,210,214,290)

group3 = c(334,302,268,311,308)

group4 = c(250,274,265,295,300)

m1 = mean(group1)

m2 = mean(group2)

m3 = mean(group3)

m4 = mean(group4)

sd1 = sd(group1)

sd2 = sd(group2)

sd3 = sd(group3)

sd4 = sd(group4)

m = c(m1, m2, m3, m4)

sd = c(sd1, sd2, sd3, sd4)

n = c(length(group1), length(group2), length(group3), length(group4))

[copyCIMeanBScode and paste at R prompt]

h =c(.5, .5, -.5, -.5)

CIMeanBS(.05, m, sd, n, h)

Estimate SE t df p-value LL UL

Equal Variances Assumed: -36.9 11.30111 -3.265167 16.00000 0.004863265 -60.85727 -12.94273

Equal Variances Not Assumed: -36.9 11.30111 -3.265167 13.98525 0.005646721 -61.14086 -12.65914

h =c(.5, -.5, .5, -.5)

CIMeanBS(.05, m, sd, n, h)

Estimate SE t df p-value LL UL

Equal Variances Assumed: 25.7 11.30111 2.274114 16.00000 0.03708247 1.742725 49.65727

Equal Variances Not Assumed: 25.7 11.30111 2.274114 13.98525 0.03924479 1.459140 49.94086

Problem3-3c

[copysizeCImeanBS code and paste at R prompt]

h = c(.5, .5, -.5, -.5)

sizeCImeanBS(.025, 639, 20, h)

[,1]

[1,] 33

Homework 4-1de

volume = c(23, 21, 21, 20, 24, 23, 22, 23, 19, 24, 23, 22, 23, 22)

hours = c(3, 0, 2, 0, 5, 4, 1, 2, 0, 8, 4, 3, 5, 6)

out= lm(volume~hours)

summary(out)

confint(out)

plot(volume, hours)

Residuals:

Min 1Q Median 3Q Max

-1.7112 -0.5926 0.1235 0.7231 1.3565

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 20.7112 0.4218 49.10 3.33e-15 ***

hours 0.4661 0.1092 4.27 0.00109 **

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.9575 on 12 degrees of freedom Note: MSe = .95752

Multiple R-squared: 0.6031, Adjusted R-squared: 0.57

F-statistic: 18.23 on 1 and 12 DF, p-value: 0.001088

confint(out)

2.5 % 97.5 %

(Intercept) 19.7922481 21.6302217

hours 0.2282612 0.7039579

Homework 4-1f

[copysizeCIslope code and paste at R prompt]

sizeCIslope(.05, 0.92, 5.9, .25)

[1] 40

Problem4-2de

child = c(16.10, 11.20, 13.20, 14.10, 7.20, 13.00, 10.50, 11.70, 15.80, 7.20, 13.10, 17.90, 14.20, 10.70, 16.70, 12.20, 13.40, 9.60, 13.90, 15.80, 18.40, 11.90, 16.30, 15.50, 19.10, 8.80, 14.60, 15.00, 16.00, 11.90)

parent =c(12.20, 12.60, 8.90, 13.50, 14.10, 8.20, 11.70, 15.20, 19.30, 11.20, 13.90, 16.00, 16.70, 13.00, 13.60, 11.30, 19.20, 13.60, 12.60, 13.10, 20.20, 13.00, 11.80, 11.80, 22.20, 10.10, 14.50, 19.30, 19.70, 18.80)

out= lm(child~parent)

summary(out)

confint(out)

cor.test(child, parent, alternative="two.sided", method="pearson")

plot(child, parent)

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 7.5914 2.1205 3.580 0.00128 **

parent 0.4110 0.1433 2.868 0.00776 **

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.751 on 28 degrees of freedom

Multiple R-squared: 0.2271, Adjusted R-squared: 0.1995

F-statistic: 8.226 on 1 and 28 DF, p-value: 0.007764

confint(out)

2.5 % 97.5 %

(Intercept) 3.247773 11.9349873

parent 0.117458 0.7045155

cor.test(child, parent, alternative="two.sided", method="pearson")

Pearson's product-moment correlation

data: child and parent

t = 2.8681, df = 28, p-value = 0.007764

alternative hypothesis: true correlation is not equal to 0

95 percent confidence interval:

0.1403478 0.7141834

sample estimates:

cor

0.4765226

Note: If the data had been saved in an SPSS or PSPP .sav file called HW4-2.sav on the working directory, the following commands will give the same results as shown above.

library(foreign, pos=4)

Dataset =read.spss("HW4-2.sav", to.data.frame = T)

attach(Dataset)

out= lm(child~parent, data=Dataset)

summary(out)

confint(out)

cor.test(child, parent, alternative="two.sided", method="pearson")

plot(parent, child)

Problem4-2h

[copysizeCIcorr code and paste at R prompt]

sizeCIcorr(.05, .14, .25)

[1] 237

Problem4-3bcde

[copyCIcorrand sizeCIcorrcode and paste at R prompt]

CIcorr(.05, .82, 200)

[1] 0.7687137 0.8608088

CIcorr(.05, .68, 200)

[1] 0.5976429 0.7481570

CIcorr(.05, .87, 200)

[1] 0.8316421 0.9000953

sizeCIcorr(.05, .598, .1)

[1] 638

Problem5-1d

sonaggr= c(50, 62, 62, 50, 49, 60, 40, 36, 79, 39, 36, 55, 52, 42, 59, 50, 57, 60, 58, 67)

hours= c(5, 6, 2, 5, 3, 6, 4, 2, 7, 4, 0, 4, 2, 0, 4, 4, 5, 7, 4, 3)

fatheraggr= c(62, 54, 73, 39, 51, 57, 30, 45, 64, 33, 45, 46, 52, 35, 51, 42, 38, 65, 47, 76)

out= lm(sonaggr~fatheraggr+hours)

summary(out)

confint(out)

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 17.4598 6.1211 2.852 0.011018 *

fatheraggr 0.5128 0.1173 4.371 0.000416 ***

hours 2.5774 0.7635 3.376 0.003591 **

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 6.415 on 17 degrees of freedom

Multiple R-squared: 0.6985, Adjusted R-squared: 0.663

F-statistic: 19.69 on 2 and 17 DF, p-value: 3.748e-05

confint(out)

2.5 % 97.5 %

(Intercept) 4.5454324 30.3742633

fatheraggr 0.2652648 0.7602899

hours 0.9665498 4.1883029

Note: If the data had been saved in an SPSS or PSPP .sav file called HW5-1.sav on the working directory, the following commands will give the same results as shown above.

library(foreign, pos=4)

Dataset =read.spss("HW5-1.sav", to.data.frame=T)

attach(Dataset)

out= lm(sonaggr~fatheraggr+hours, data=Dataset)

summary(out)

confint(out)

Problem5-1e

efather = residuals(lm(fatheraggr ~ hours, data = Dataset))

ehours = residuals(lm(hours ~ fatheraggr, data = Dataset))

cor(sonaggr, efather)

cor(sonaggr, ehours)

cor(sonaggr, efather)

[1] 0.5820847

cor(sonaggr, ehours)

[1] 0.4495506

[pasteCIsemipartcorr at R prompt]

CIsemipartcorr(.05, .582, .699, 20)

[1] 0.2525662 0.7905182

CIsemipartcorr(.05, .450, .699, 20)

[1] 0.1359897 0.6818499

Problem5-1f

library(MBESS)

# set R2 equal to sample squared multiple correlation

# set N equal to total sample size

# set K equal to number of predictor variables

ci.R2(R2=.6985, N=20, K=2, conf.level=.95, Random.Predictors=T)

$Lower.Conf.Limit.R2

[1] 0.3368534

$Upper.Conf.Limit.R2

[1] 0.8551323

Problem5-1g

[copysizeCImulticorr code and paste at R prompt]

sizeCImultcorr(.05, 2, .6, .2)

[1] 152

Problem5-2c

lifesat=c(11,12,11,11,9,8,8,6,8,10,8,7,9,11,9,10,11,11,11,10,7,9,8,9,10,6,6,11,12,7,7,10,9,11,8, 8,7,8,9,9)

commit=c(5,4,4,5,5,4,4,5,4,4,4,6,4,4,4,6,5,5,3,3,5,6,5,5,4,6,4,5,5,3,4,5,4,3,3,5,5,3,5,5)

jobsat=c(20,22,18,21,19,11,15,15,18,17,17,18,16,19,15,21,21,20,18,16,17,20,13,19,18,16,13,21,22,

12,23,15,16,16,15,19,16,13,19,20)

out= lm(jobsat~lifesat+commit)

summary(out)

confint(out)

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 1.4019 2.5933 0.541 0.592022

lifesat 1.0069 0.1970 5.113 9.96e-06 ***

commit 1.5697 0.3844 4.083 0.000228 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.095 on 37 degrees of freedom

Multiple R-squared: 0.5169, Adjusted R-squared: 0.4908

F-statistic: 19.79 on 2 and 37 DF, p-value: 1.429e-06

2.5 % 97.5 %

(Intercept) -3.8525734 6.656453

lifesat 0.6078764 1.406022

commit 0.7908063 2.348595

Problem5-2d

library(MBESS)

# set R2 equal to sample squared multiple correlation

# set N equal to total sample size

# set K equal to number of predictor variables

ci.R2(R2=.5169, N=40, K=2, conf.level=.95, Random.Predictors=T)

$Lower.Conf.Limit.R2

[1] 0.2514043

$Upper.Conf.Limit.R2

[1] 0.6946407

Problem5-3d

read= c(20, 36, 72, 40, 95, 71, 65, 48, 55, 85, 92, 45)

TVhours=c(15, 12, 8, 10, 5, 8, 8, 10, 10, 7, 4, 12)

IQ=c(82, 96, 112, 90, 130, 121, 115, 98, 105, 120, 128, 95)

out= lm(read~TVhours+ IQ)

summary(out)

confint(out)

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) -9.4151 38.0910 -0.247 0.81032

TVhours -3.0628 1.2699 -2.412 0.03913 *

IQ 0.9062 0.2511 3.609 0.00567 **

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 4.506 on 9 degrees of freedom

Multiple R-squared: 0.9702, Adjusted R-squared: 0.9636

F-statistic: 146.5 on 2 and 9 DF, p-value: 1.362e-07

confint(out)

2.5 % 97.5 %

(Intercept) -95.5828158 76.7526479

TVhours -5.9354538 -0.1901863

IQ 0.3381213 1.4743065

Problem6-1c

oct= c(35, 19, 20, 31, 25, 20, 39, 29, 18, 22, 25, 30)

nov= c(27, 18, 22, 24, 15, 17, 30, 22, 14, 19, 19, 26)

t.test(oct, nov, paired=T)

cor(oct, nov); sd(oct); sd(nov)

Paired t-test

data: oct and nov

t = 4.9625, df = 11, p-value = 0.0004271

alternative hypothesis: true difference in means is not equal to 0

95 percent confidence interval:

2.782403 7.217597

sample estimates:

mean of the differences

5

cor(oct, nov); sd(oct); sd(nov)

[1] 0.8667044

[1] 6.761634

[1] 4.96274

Problem6-1d

[copysizeCImeanWS code and paste at R prompt]

sizeCImeanWS(.05, 35.15, .867, 2.5)

[1] 23

Problem6-2c

wb1 =c(25, 20, 39, 29, 18, 22, 25, 30)

wb2 =c(22, 18, 34, 25, 16, 21, 22, 27)

wb3 =c(15, 17, 30, 22, 14, 19, 19, 26)

t.test(wb1, wb2, paired=T, conf.level = .9833)

t.test(wb1, wb3, paired=T, conf.level = .9833)

t.test(wb2, wb3, paired=T, conf.level = .9833)

sd(wb1); sd(wb2);sd(wb3)

cor(wb1, wb2); cor(wb1, wb3); cor(wb2, wb3)

Paired t-test

data: wb2 and wb3

t = 4.1501, df = 7, p-value = 0.004295

alternative hypothesis: true difference in means is not equal to 0

98.33 percent confidence interval:

0.7093593 5.0406407

sample estimates:

mean of the differences

2.875

sd(wb1); sd(wb2);sd(wb3)

[1] 6.676184

[1] 5.617257

[1] 5.496752

cor(wb1, wb2); cor(wb1, wb3); cor(wb2, wb3)

[1] 0.994237

[1] 0.9187123

[1] 0.9380638

Note: If the data had been saved in an SPSS or PSPP .sav file called HW6-2.sav on the working directory, the following commands will give the same results as shown above.

library(foreign, pos=4)

data=read.spss("HW6-2.sav", to.data.frame = T)

attach(data)

t.test(WB1, WB2, paired= T, conf.level = .9833)

t.test(WB1, WB3, paired= T, conf.level = .9833)

t.test(WB2, WB3, paired= T, conf.level = .9833)

sd(WB1); sd(WB2); sd(WB3)

cor(WB1, WB2); cor(WB1, WB3); cor(WB2, WB3)

Problem6-2d

[copysizeCImeanWS code and paste at R prompt]

sizeCImeanWS(.0167, 44.6, .919, 2)

[1] 42

Problem6-3cd

LR =c(21, 39, 32, 29, 27, 17, 27, 21, 28, 17, 12, 27)

LS =c(20, 36, 33, 27, 28, 14, 30, 20, 27, 15, 11, 22)

HR =c(21, 36, 30, 27, 28, 15, 27, 18, 29, 16, 11, 22)

HS =c(17, 33, 28, 27, 27, 16, 26, 20, 25, 15, 13, 22)

Interaction = (LR - LS) - (HR - HS)

Traffic <- (LR + LS)/2 - (HR + HS)/2

Mode <- (LR + HR)/2 - (LS + HS)/2

t.test(Interaction, mu = 0, conf.level = .95)

t.test(Traffic, mu = 0, conf.level = .975)

t.test(Mode, mu = 0, conf.level = .975)

One Sample t-test

data: Interaction

t = 0.2736, df = 11, p-value = 0.7895

alternative hypothesis: true mean is not equal to 0

95 percent confidence interval:

-1.761497 2.261497

One Sample t-test

data: Traffic

t = 3.5245, df = 11, p-value = 0.004761

alternative hypothesis: true mean is not equal to 0

97.5 percent confidence interval:

0.3413349 2.2419984

One Sample t-test

data: Mode

t = 2.6286, df = 11, p-value = 0.02347

alternative hypothesis: true mean is not equal to 0

97.5 percent confidence interval:

0.01407164 2.06926170

Problem7-1c

[copyCIprop1 code and paste at R prompt]

CIprop1(.05, 60, 500)

[1] 0.09434049 0.15169126

Problem 7-2d

[copyCIprop2 code and paste at R prompt]

CIprop2(.05, 41, 68, 150, 150)

[1] -0.28401891 -0.07124424

Problem 7-3c

[copyCIpropWScode and paste at R prompt]

CIpropWS(.05, 96, 68, 400)

[1] 0.007204993 0.132098489