link <- url("https://gregorkb.github.io/data/STAT_516_fa_2026_square_circle_measurements.csv")
sqcirc <- read.csv(link)STAT 516 hw 6
Each student in a statistics class, according to a random assignment, was given a sheet of paper on which was printed one of the following:
- A circle and the instruction to draw a circle with twice the diameter.
- A circle and the instruction to draw a circle with twice the area.
- A square and the instruction to draw a square with twice the side length.
- A square and the instruction to draw a square with twice the area.
After the sheets were collected they were scanned into a single PDF and uploaded to ChatGPT with the prompt:
I am uploading a pdf. Each page has a set of instructions and a drawing made by a student. On pages that ask the student to draw a square, measure the side length of the square. On pages that ask the student to draw a circle, measure the diameter of the circle. The paper is 8.5 by 11 inches. Store the output in a csv file. The csv file should have three columns. One column should have the entries “square” or “circle” according to whether the student was asked to draw a square or a circle, another should have “diameter” or “area”, the former if the student was asked to double the side length or diameter of the shape and the latter if the student was asked to double the area of the shape.
The resulting comma separated values file can be read into R with the following code:
The side length of the printed squares and the diameter of the printed circles were both \(2\) inches. To double the area of these shapes, one needs to multiply the side length or diameter by \(\sqrt{2}\), so the side length/diameter needed to double the area of the square/circle was \(2\sqrt{2}\). In the case of doubling the side length/diameter the target side length/diameter was \(4\).
The code below adds a column to the data set containing the difference between the side length/diameter of the drawn circle/square and the target side length/diameter, depending on the doubling instruction. Moreover, it removes a few observations in order to make the number of replicates at each combination of shape and doubling instruction equal.
sqcirc$err <- sqcirc$measurement_inches - ifelse(sqcirc$doubling_instruction == "area",sqrt(2)*2,4)
rmv <- c(1,3,4,8,14)
sqcirc_bal <- sqcirc[-rmv,]The data set is printed here:
sqcirc_bal shape doubling_instruction measurement_inches err
2 circle diameter 2.77 -1.2300000
5 square area 3.49 0.6615729
6 circle diameter 4.83 0.8300000
7 square area 3.65 0.8215729
9 square area 3.39 0.5615729
10 square area 3.88 1.0515729
11 circle diameter 3.35 -0.6500000
12 square diameter 4.54 0.5400000
13 circle area 3.21 0.3815729
15 circle diameter 3.92 -0.0800000
16 square diameter 3.93 -0.0700000
17 circle area 3.16 0.3315729
18 circle area 3.69 0.8615729
19 circle area 4.04 1.2115729
20 square diameter 4.07 0.0700000
21 square diameter 3.83 -0.1700000
Regarding the values in the newly created “error” column as the responses, consider fitting the two-way treatment effects model \[ Y_{ijk} = \mu + \tau_i + \gamma_j + (\tau\gamma)_{ij} + \varepsilon_{ijk} \] for \(k =1,\dots,n_{ij}\), \(i = 1,\dots,a\), \(j = 1,\dots,b\), where \(\varepsilon_{ijk}\) are independent error terms having the \(\mathcal{N}(0,\sigma^2)\) distribution.
1.
Visualize the data with side-by-side boxplots or dotplots.
boxplot(err ~ shape + doubling_instruction, data = sqcirc_bal)stripchart(err ~ shape + doubling_instruction, data = sqcirc_bal, method = "jitter",vertical = T)2.
What are the two factors in the experiment and how many levels does each one have?
The first factor is 'shape' with the levels 'square'
and 'circle'. The second factor is 'doubling instruction'
with levels 'diameter' and 'area'.
4.
Give the number of replicates in each treatment group.
We can show the number of replicates at each
combination of factor levels with this code:
table(sqcirc_bal$shape,sqcirc_bal$doubling_instruction)
area diameter
circle 4 4
square 4 4
5.
Give the means of the responses at all factor level combinations.
We can show the mean of the responses at each
combination of factor levels with this code:
aggregate(err ~ shape + doubling_instruction, mean,data = sqcirc_bal) shape doubling_instruction err
1 circle area 0.6965729
2 square area 0.7740729
3 circle diameter -0.2825000
4 square diameter 0.0925000
6.
Give \(\hat \sigma\), the estimate of the standard deviation \(\sigma\) of the error terms.
lm_out <- lm(err ~ shape + doubling_instruction + shape:doubling_instruction,
data = sqcirc_bal)
a <- 2
b <- 2
n <- 4
ehat <- lm_out$residuals
SSerror <- sum(ehat**2)
MSerror <- SSerror/(a*b*(n-1))
sigma_hat <- sqrt(MSerror)We obtain the value 0.5219774.
7.
Check carefully whether the assumptions of the two-way ANOVA model are satisfied.
plot(lm_out,which = 1,add.smooth = F)lm_levene <- lm(abs(ehat) ~ shape + doubling_instruction + shape:doubling_instruction,
data = sqcirc_bal)
summary(lm_levene)
Call:
lm(formula = abs(ehat) ~ shape + doubling_instruction + shape:doubling_instruction,
data = sqcirc_bal)
Residuals:
Min 1Q Median 3Q Max
-0.455 -0.130 0.000 0.130 0.455
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.3400 0.1268 2.681 0.020 *
shapesquare -0.1775 0.1794 -0.990 0.342
doubling_instructiondiameter 0.3175 0.1794 1.770 0.102
shapesquare:doubling_instructiondiameter -0.2563 0.2536 -1.010 0.332
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2536 on 12 degrees of freedom
Multiple R-squared: 0.4301, Adjusted R-squared: 0.2877
F-statistic: 3.019 on 3 and 12 DF, p-value: 0.07167
The residuals versus fitted values plot
shows some evidence of unequal variances across the treatment groups;
however, Levene's test fails to reject the null hypothesis of
equal variances (see p-value in above output). If more data were
collected, one might find that the variances really are unequal.
plot(lm_out,which = 2)The points in the normal QQ plot of the
residuals line close to a straigh line, suggesting it is safe
to assume that the responses are normally distributed around
the treatment group means.
8.
Even though the assumptions might not be satisfied, give the value of the test statistic for the overall \(F\) test as well as the associated \(p\) value. Give an interpretation of these values.
y <- sqcirc_bal$err
y.. <- mean(y)
SStot <- sum((y - y..)**2)
SStrt <- SStot - SSerror
MStrt <- SStrt / (a*b - 1)
Ftest <- MStrt / MSerror
pval <- 1 - pf(Ftest,a*b-1,a*b*(n-1))The value of the test statistic is 3.732661
and the p value is 0.04185442. This suggests that at least one of the
factors has some kind of effect on the response. Whether there are
main effects or interactions is, however, still unclear.
9.
Obtain the complete ANOVA table containing the \(F\) test statistics and associated \(p\) values for testing the significance of the main effects as well as the interaction effect.
anova(lm_out)Analysis of Variance Table
Response: err
Df Sum Sq Mean Sq F value Pr(>F)
shape 1 0.2048 0.20476 0.7515 0.4030
doubling_instruction 1 2.7577 2.75774 10.1216 0.0079 **
shape:doubling_instruction 1 0.0885 0.08851 0.3248 0.5792
Residuals 12 3.2695 0.27246
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
10.
Generate interaction plots for the two factors. State whether you believe there is an interaction between the two factors (From here on you may assume that the model assumptions are satisfied, though you may not agree that this is so).
interaction.plot(sqcirc_bal$shape,sqcirc_bal$doubling_instruction,sqcirc_bal$err)interaction.plot(sqcirc_bal$doubling_instruction,sqcirc_bal$shape,sqcirc_bal$err)The p value for the interaction effect is
quite large, so there is insufficient evidence
in the data to conclude the existence of an
interaction effect.
11.
State whether you believe there is a significant main effect associated with either of the two factors. Explain your answer.
It appears that the doubling instruction factor does
have a main effect, as its p value in the ANOVA table is quite small.
It appears from plots that students have a tendency to
overestimate the side length/diameter needed to double the area of
a square/circle. The shape factor does not appear to have
a significant main effect, due to its large p value in the
ANOVA table.
12.
Give a confidence interval for the mean side length/diameter of squares/circles drawn under the instruction to double the side length/diameter (this is a marginal mean). Choose your own level of confidence.
alpha <- 0.05
y.diameter <- mean(sqcirc_bal$err[sqcirc_bal$doubling_instruction == "diameter"])
me <- qt(1-alpha/2,a*b*(n-1)) * sqrt(MSerror) * sqrt(1/(2*n))
lo <- y.diameter - me
up <- y.diameter + meAt 95% confidence we obtain the interval [-0.4970931,0.3070931].
Since this interval contains zero, we conclude that, when asked to
double the side length/diameter of a square/circle, students show
neither a tendency to draw too large or too small a shape.
13.
Which do the data suggest is more difficult, drawing a picture of a circle/square with twice the diameter/side length or with twice the area of the one shown? Provide a confidence interval in support of your answer (it should be a confidence interval comparing marginal means).
y.area <- mean(sqcirc_bal$err[sqcirc_bal$doubling_instruction == "area"])
y.diameter <- mean(sqcirc_bal$err[sqcirc_bal$doubling_instruction == "diameter"])
me <- qt(1-alpha/2,a*b*(n-1)) * sqrt(MSerror) * sqrt(2/(2*n))
lo <- y.area - y.diameter - me
up <- y.area - y.diameter + meA 95% confidence interval for the difference in
marginal means (area minus diameter) is [0.2616773,1.398968].
Since this interval lies entirely above zero, we conclude that
students tend to overestimate the side length/diameter
needed to double the area of a square/circle.