# Examples – Comparing two conditions using R.

Problem : The tension bond strangth of portland cement mortar is an important characteristic of the product. An engineer in interested in comparing the strength of a modified formulation in which polymer latex emulsions have been added during mixing to the strength of the unmodified mortar. The experimanter has collected 10 observations on strength for the modified forumlation and another 10 observations on strength for the unmodified formulation. The data is

Two sample t-test equal variances, two sided :
>t.test(data2\$modified,data2\$unmodified,var.equal=TRUE,alternative=”two.sided”)
Two Sample t-test
data: data2\$modified and data2\$unmodified
t = -9.1094, df = 18, p-value = 3.678e-08

alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-1.4250734 -0.8909266
sample estimates:
mean of x mean of y
16.764 17.922

Of course, our assumption has been that the distribution of data for both the samples is normal. We can test this assumption using the quartile-quartile plot. see
here for details on qqnorm plots. A plot for modified sample is A plot for the unmodified sample is Paired t-test:
problem: consider a hardness testing machine that presses a rod with a pointed tip into a metal specimen with a known force. By measuring the depth of the depression caused by the tip, the hardness of the specimen is determined. Two different tips are available for this macine, and although the precision of the measurements made by the two tips seems to be the same, it is suspected that one tip produces different hardness reading than the other. AN exmperiment is conducted in which the two tips are used within the same specimen and 10 runs of the experiment are made. The data is as shown below

> hard
\$tip1
 7 3 3 4 8 3 2 9 5 4

\$tip2
 6 3 5 3 8 2 4 9 4 5

The paired test is
> t.test(hard\$tip1,hard\$tip2,paired=TRUE,var.equal=TRUE,alternative=”two.sided”)
Paired t-test
data: hard\$tip1 and hard\$tip2
t = -0.2641, df = 9, p-value = 0.7976

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

95 percent confidence interval:
-0.9564389 0.7564389

sample estimates:
mean of the differences
-0.1

comparing variances:

It is sometimes useful to compare variances of two samples. Consider the mortar example. we can compare the variances using R as follows
> var.test(data2\$unmodified,data2\$modified)
F test to compare two variances
data: data2\$unmodified and data2\$modified

F = 0.6138, num df = 9, denom df = 9, p-value = 0.4785
alternative hypothesis: true ratio of variances is not equal to 1

95 percent confidence interval:
0.1524534 2.4710609

sample estimates:
ratio of variances
0.6137766