STAT 516 hw 5
Students in a class were randomly assigned to receive a piece of paper on which was printed a pie chart, a bar chart, or a stacked bar chart (these are shown below). Students were given five seconds to guess, from looking at the chart, what percentage the chart represented for category “B”.
Here are the guesses:
pie,bar,stacked
15.00,10.00,10.00
20.00,17.00,10.00
14.00,13.00,10.00
15.00,25.00,18.00
15.00,25.00,20.00
14.00,25.00,18.00
15.00,16.67,15.00It is of interest whether there is any difference in the abilities of these types of charts to effectively convey percentages made up by the parts of a whole. The true percentage associated with the category “B” was
1.
Import (however it seems best) the data into R and make side-by-side boxplots of the response values (the responses are not the raw guesses but the absolute deviations of the guesses from
trt <- as.factor(c(rep("pie",7),rep("bar",7),rep("stacked",7)))
pct <- c(15,20,14,15,15,14,15,
10,17,13,25,25,25,16.37,
10,10,10,18,20,18,15)
Y <- abs(pct - 15) # absolute difference from 15
boxplot(Y~trt)2.
Give the mean and standard deviation of the response values as well as the number of replications for each chart type.
means <- aggregate(Y, by = list(trt), mean)
sds <- aggregate(Y, by = list(trt), sd)
ns <- aggregate(Y, by = list(trt), length)
tab <- cbind(means,sds[,2],ns[,2])
colnames(tab) <- c("chart","mean","std. dev.","n")
tab chart mean std. dev. n
1 bar 5.767143 4.124264 7
2 pie 1.000000 1.825742 7
3 stacked 3.714286 1.889822 7
3.
Compute all quantities in the analysis of variance (ANOVA) table below without using the lm() function.
| Source | Df | SS | MS | F value | p-value |
|---|---|---|---|---|---|
| Treatment | |||||
| Error | |||||
| Total |
Y.. <- mean(Y)
Yi. <- aggregate(Y ~ trt, FUN=mean)[,2]
n <- aggregate(Y ~ trt,FUN = length)[,2]
a <- length(Yi.)
N <- sum(n)
SStot <- sum((Y - Y..)**2)
SStrt <- sum(n*(Yi. - Y..)^2)
SSerror <- SStot - SStrt
MStrt <- SStrt / (a - 1)
MSerror <- SSerror / (N - a)
Ftest <- MStrt / MSerror
pval <- 1 - pf(Ftest, a-1, N - a)4.
Obtain the ANOVA table using the lm() and anova() function (from here on you may use the lm() function).
lm_out <- lm(Y ~ trt)
anova(lm_out)Analysis of Variance Table
Response: Y
Df Sum Sq Mean Sq F value Pr(>F)
trt 2 80.05 40.025 5.0211 0.0185 *
Residuals 18 143.49 7.971
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
5.
Give the null hypothesis for which the value
The null hypothesis is that all the chart type means are the same.
6.
State your conclusions with respect to the null hypothesis in the previous part.
We will reject the null hypotheses at
any significance level greater than 0.01849927,
so the evidence is quite strong that there is
some difference among the means for the
different chart types.
7.
Check whether the assumptions of the one-way ANOVA model are satisfied.
plot(lm_out,which=1, add.smooth = F)plot(lm_out,which = 2)The assumption of equal variances is
dubious. The assumption of normality is also
somewhat dubious, as the normal quantile-quantile plot
exhibits some deviations from normality in the
residuals.
8.
Conduct Levene’s test for equal variances in the response values across chart types.
library(car)Warning: package 'car' was built under R version 4.4.3
Loading required package: carData
leveneTest(Y ~ trt, center = mean)Levene's Test for Homogeneity of Variance (center = mean)
Df F value Pr(>F)
group 2 8.4852 0.002536 **
18
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Levene's test rejects the null hypothesis
of equal variances.
9.
Give the values of
lm_out
Call:
lm(formula = Y ~ trt)
Coefficients:
(Intercept) trtpie trtstacked
5.767 -4.767 -2.053
The estimate for mu, 5.767143, is the
mean of the bar chart responses, the estimate for
tau_2, -4.767143, is the mean of the pie
chart responses minus the mean of the bar chart
responses, and the estimate for
tau_3, -2.052857, is the mean of the stacked bar chart
responses minues the mean of the bar chart
responses.
10.
Proceeding as though the assumptions were satisfied, perform a careful analysis in order to determine, if possible, which of the three chart types is best for giving an accurate impression of a percentage. Give a careful summary of your findings.
# do tukey's
aov_out <- aov(lm_out)
tukey_out <- TukeyHSD(aov_out)
tukey_out Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = lm_out)
$trt
diff lwr upr p adj
pie-bar -4.767143 -8.618757 -0.9155285 0.0142951
stacked-bar -2.052857 -5.904471 1.7987572 0.3817976
stacked-pie 2.714286 -1.137329 6.5659000 0.1982937
plot(tukey_out)To answer this question we should
compare all pairs of means with Tukey's method.
The result of this shows that the pie chart
is better than the bar chart; however, the
pie chart cannot be said to be better than
the stacked bar chart, nor is the difference
between the bar and the stacked bar charts statistically significant. We may
say tentatively that the pie chart emerges
as a possible winner; but one would have to
collect more data in order to make this claim
with great confidence.
11.
Now take the pie chart as a benchmark against which the other two chart types are to be compared. Investigate carefully whether the ability of the pie chart to convey a percentage is different from that of the bar and the stacked bar charts. Carefully summarize your findings.
library(DescTools)Warning: package 'DescTools' was built under R version 4.4.1
Attaching package: 'DescTools'
The following object is masked from 'package:car':
Recode
DunnettTest(Y ~ trt, control="pie")
Dunnett's test for comparing several treatments with a control :
95% family-wise confidence level
$pie
diff lwr.ci upr.ci pval
bar-pie 4.767143 1.1467997 8.387486 0.0102 *
stacked-pie 2.714286 -0.9060574 6.334629 0.1547
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Now we compare the bar and stacked
bar chart means with the pie chart mean
using Dunnett's method. The results are
scarely different from those of Tukey's method
for comparing all pairs of means.
12.
Should we have expected the findings from parts 10. and 11. to be very different? Why or why not?
We should not expect the findings
to be very different, since, given that there
are only three treatment groups, Tukey's
method makes 3 comparisons and Dunnett's makes
two comparisons. Since the numbers of
comparisons made by the two methods differ only by
one, the methods yield quite similar
results. Dunnett's will give confidence
intervals narrower than the Tukey intervals by a
greater margin if the number of treatment
groups is larger.