Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please give me the code of what to input to do this in R. In a repeat-measure or

ID: 3363447 • Letter: P

Question

Please give me the code of what to input to do this in R.

In a repeat-measure or paired t.test, an individual or object is measured repeatedly. The null hypothesis here, instead of no difference between means, is no mean difference between the first and second measures.

The sleep dataset shows the effect of 2 different soporific drugs on 10 patients, where each patient is given each drug.


Use the t.test function to test the effect of group (the drug) on extra (additional sleep time).


Do you see evidence of a difference in mean effect?


Modify Part 1 to use a paired t.test (you will need to change one function argument).


How does your answer differ from Part 1?
What variation does the paired t.test account for that the unpaired t.test ignores?

Explanation / Answer

Sol:

datset in package stats.

require(stats)
print(sleep)

code for t test:

## Student's t-test

with(sleep,
t.test(extra[group == 1],
extra[group == 2]))

output:

Welch Two Sample t-test

data: extra[group == 1] and extra[group == 2]

t = -1.8608, df = 17.776, p-value = 0.07939

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

95 percent confidence interval:

-3.3654832 0.2054832

sample estimates:

mean of x mean of y

0.75 2.33

p=0.07939

p>0.05

Means are not significant.

## Student's paired t-test

code:

with(sleep,
t.test(extra[group == 1],
extra[group == 2], paired = TRUE))

output:

Paired t-test

data: extra[group == 1] and extra[group == 2]

t = -4.0621, df = 9, p-value = 0.002833

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

95 percent confidence interval:

-2.4598858 -0.7001142

sample estimates:

mean of the differences

-1.58

intrepretation:

p=0.002833

p<0.05,

reject null hypothesis.

there is signiificant difference in means.

What variation does the paired t.test account for that the unpaired t.test ignores?

In the independent t test for difference in means

the subjects are not related whereas the subjects are related in paired t test.

In paired t test we use pooled standard deviation,that is variability in the data can be reduced by using pairs of individuals.

that is in ttest without paired variation is large whereas in paired t test variation is small as we used pooled standard deviation in calculation.

Paired t-test

data: extra[group == 1] and extra[group == 2]

t = -4.0621, df = 9, p-value = 0.002833

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

95 percent confidence interval:

-2.4598858 -0.7001142

sample estimates:

mean of the differences

-1.58

intrepretation:

p=