Math 243 – Summer 2012 1 1 Here is a simple model that relates

Math 243 – Summer 2012
PS 8
1 Here is a simple model that relates foot width to length in
1
A
children, fit to the data in KidsFeet:
sum(kids$width) (sum(resid(mod)) +
sum(fitted(mod)))
kids = fetchData("kidsfeet.csv")
Retrieving data from
http://www.mosaic-web.org/go/datasets/kidsfeet.csv
B
sum(kids$width^2) (sum(resid(mod)^2) +
mod = lm(width ~ length, data = kids)
coef(mod)
(Intercept)
2.8623
length
0.2479
sum(fitted(mod)^2))
C
sum(resid(mod)) sum(fitted(mod))
a) Using the coefficients, calculate the predicted foot width
from this model for a child with foot length 27cm.
D
sum(resid(mod)^2) sum(fitted(mod)^2)
2.86 3.10 7.93 9.12 9.56 12.24 28.62
b) The sum of squares of the residuals from the model provides a simple indication of how far typical values are
from the model. In this sense, the standard deviation of
the residuals tells us how much uncertainty there is in the
prediction. (Later on, we’ll see that another term needs
to be added to this uncertainty.) What is the sum of
squares of the residuals?
4.73 5.81 5.94 6.10 6.21
Note: It might seem natural to use the == operator to
compare the equality of two values, for instance A == B.
However, arithmetic on the computer is subject to small
round-off errors, too small to be important when looking
at the quantities themselves but sufficient to cause the ==
operator to say the quantities are different. So, it’s usually better to compare numbers by subtracting one from
the other and checking whether the result is very small.
2 Consider the data collected by Francis Galton in the 1880s,
stored in a modern format in the galton.csv file. In this file,
heights is the variable containing the child’s heights, while
c) What is the sum of squares of the fitted values for the the father’s and mother’s height is contained in the variables
kids in KidsFeet?
father and mother. The family variable is a numerical code
identifying children in the same family; the number of kids in
this family is in nkids.
42.5 286.3 3157.7 8492.0 15582.1
> galton = fetchData("galton.csv")
> lm( height ~ father, data=galton)
d) What is the sum of squares of the foot widths for the kids
Coefficients:
in KidsFeet.
(Intercept)
father
39.1104
0.3994
3163.5 3167.2 3285.1 3314.8 3341.7
(a) What is the model’s prediction for the height of a child
whose father is 72 inches tall? 67.1 67.4 67.9 68.2
e) There is a simple relationship between the sum of squares
of the response variable, the residuals, and the fitted val- (b) Construct a model using both the father’s and mother’s
ues. You can confirm this directly. Which of the following
heights, using just the main effect but not including their
R statements is appropriate to do this:
interaction. What is the model’s prediction for the height
Math 243 – Summer 2012
PS 8
of a child whose father is 72 inches tall and mother is 65
inches tall? 67.4 68.1 68.9 69.2
(c) Construct a model using mother and father’s height, including the main effects as well as the interaction. What
is the model’s prediction for the height of a child whose
father is 72 inches tall and mother is 65 inches tall?
67.4 68.1 68.9 69.2
Galton did not have our modern techniques for including
multiple variables into a model. So, he tried an expedient, defining a single variable, “mid-parent,” that reflected
both the father’s and mother’s height. We can mimic this
approach by defining the variable in the same way Galton
did:
2
height
5
4
5
6
7
6
water
2
1
1.5
3
3
2
light
shady
bright
bright
shady
bright
shady
compost
none
none
some
rich
some
rich
nitrogen
little
lot
little
lot
little
lot
(a) In the model expression height ∼ water, which is the explanatory variable?
A height
B water
C light
D compost
E Can’t tell from this information.
(b) Ranger Alan proposes the specific model formula
> midparent=(galton$father+1.08*galton$mother)/2
Galton used the multiplier of 1.08 to adjust for the fact that
the mothers were, as a group, shorter than the fathers.
Fit a model to the Galton data using the mid-parent variable and child’s sex, using both the main effects and the
interaction. This will lead to a separate coefficient on midparent for male and female children.
(d) What is the predicted height for a girl whose father is 67
inches and mother 64 inches? 63.6 63.9 64.2 65.4 65.7
height = 2 ∗ water + 1.
Copy the table to a piece of paper and fill in the table
showing the model values and the residuals.
height water model values resids
5
2
4
1
5
1.5
6
3
7
3
6
2
(c) Ranger Bill proposes the specific model formula
The following questions are about the size of the residuals
from models.
(e) Without knowing anything about a randomly selected child
except that he or she was in Galton’s data set, we can say
that the child’s height is a random variable with a certain
mean and standard deviation. What is this standard deviation?
2.51 2.73 2.95 3.44 3.58 3.67 3.72
(f) Now consider that we are promised to be told the sex of
the child, but no other information. We are going to make
a prediction of the child’s height once we get this information, and we are asked to say, ahead of time, how good
this prediction will be. A sensible way to do this is to give
the standard deviation of the residuals from the best fitting model based on the child’s sex. What is this standard
deviation of residuals?
2.51 2.73 2.95 3.44 3.58 3.67 3.72
height = water + 3.
Again, fill in the model values and residuals.
height water model values resids
5
2
4
1
5
1.5
6
3
7
3
6
2
(d) Based on your answers to the previous to parts, which of
the two models is better? Give a specific definition of “better” and explain your answer quantitatively.
(e) Write down the set of indicator variables that arise from
the categorical variable compost.
(f) The fitted values are exactly the same for the two models
water ∼ compost and water ∼ compost-1. This suggests
that the 1 vector (1, 1, 1, 1, 1, 1) is redundant with the set
of indicator variables due to the variable compost. Explain
why this redundancy occurs. Is it because of something
special about the “compost” variable?
3 Here are some (made-up) data from an experiment growing (g) Estimate, as best you can using only very simple calculatrees. The height was measured for trees in different locations
that had been watered and fertilized in different ways.
tions, the coefficients on the model water ∼ compost-1.
(Note: there is no intercept term in this model.)
PS 8
Math 243 – Summer 2012
3
(h) Ranger Charley observes that the the following model is Compare the velocity you find from your model fit to the acperfect because all of the residuals are zero.
cepted velocity of sound (at room temperature, at sea level, in
dry air): 343 m/s. There should be a reasonable match. If not,
height ∼ 1+water+light+compost+nitrogen
check whether your data were entered properly and whether
Charley believes that using this model will enable him to you specified your model correctly.
make excellent predictions about the height of trees in the Part 2.
future. Ranger Donald, on the other hand, calls Charley’s
regression “ridiculous rot” and claims that Charley’s explanatory terms could fit perfectly any set of 6 numbers. The students who recorded the data wrote down the transit
Donald says that the perfect fit of Charley’s model does time to 4 digits of precision, but recorded the position to only 1
not give any evidence that the model is of any use whatso- or 2 digits, although they might simply have left off the trailing
zeros that would indicate a higher precision.
ever. Who do you think is right, Donald or Charley?
Use the data to find out how precise the position measurement
is. To do this, make two assumptions that are very reasonable
4 The “modern physics” course has a lab where students mea- in this case:
sure the speed of sound. The apparatus consists of an air-filled
tube with a sound generator at one end and a microphone that
a) The velocity model is highly accurate, that is, sound travcan be set at any specified position within the tube. Using an
els at a constant velocity through the tube.
oscilloscope, the transit time between the sound generator and
microphone can be measured precisely. Knowing the position p
b) The transit time measurements are correct. This assumpand transit time t allows the speed of sound v to be calculated,
tion reflects current technology. Time measurements can
based on the simple model:
be made very precisely, even with inexpensive equipment.
distance = velocity × time
or
p = vt.
Given these assumptions, you should be able to calculate the
position from the transit time and velocity. If the measured
Here are some data recorded by a student group calling them- position differs from this model value — as reflected by the
selves “CDT”.
residuals — then the measured position is imprecise. So, a
reasonable way to infer the precision of the position is by the
position transit time
typical size of residuals.
(m)
(millisec)
0.2
0.6839
How big is a typical residual? One appropriate way to measure
0.4
1.252
this is with the standard deviation of the residuals.
0.6
1.852
0.8
2.458
• Give a numerical value for this.
1.0
3.097
0.001 0.006 0.010 0.017 0.084 0.128
1.2
3.619
1.4
4.181
Part 3.
Part 1.
Enter these data into a spreadsheet in the standard casevariable format. Then fit an appropriate model. Note that
the relationship p = vt between position, velocity, and time
translates into a statistical model of the form p ∼ t - 1 where
the velocity will be the coefficient on the t term.
The students’ lab report doesn’t indicate how they know for
certain that the sound generator is at position zero. One way
to figure this out is to measure the generator’s position from
the data themselves. Denoting the actual position of the sound
generator as p0 , then the equation relating position and transit
time is
p − p0 = vt
or
p = p0 + vt
What are the units of the model coefficient corresponding to
This suggests fitting a model of the form p ∼ 1 + t, where the
velocity, given the form of the data in the table above?
coefficient on 1 will be p0 and the coefficient on t will be v.
A meters per second
Fit this model to the data.
B miles per hour
C millimeters per second
• What is the estimated value of p0 ?
D meters per millisecond
-0.032 0.012 0.000 0.012 0.032
E millimeters per millisecond
F No units. It’s a pure number.
Notice that adding new terms to the model reduces the stanG No way to know from the information prodard deviation of the residuals.
vided.
Math 243 – Summer 2012
PS 8
4
• What is the new value of the standard deviation of the model time ∼ year + sex + year:sex. This model captures
residuals?
some of the variability in the record times, but doesn’t reflect
0.001 0.006 0.010 0.017 0.084 0.128
something that’s obvious from a plot of the data: that records
improved quickly in the early years (especially for women) but
Compare the estimated speed of sound found from the model the improvment is much slower in recent years. The point of
p ∼ t to the established value: 343 m/s . Notice that the es- this exercise is to show how the residuals provide information
timate is better than the one from the model p ∼ t - 1 that about this.
didn’t take into account the position of the sound generator.
• Find the cases in the residuals that are outliers. Explain
what it is about these cases that fits in with the failure
5 Which of these statements will compute the sum of square
of the model to reflect the slowing improvement in world
residuals of the model stored in the object mod?
records.
A
• Plot the residuals versus the fitted model values. What
resid(mod)
pattern do you see that isn’t consistent with the idea that
the residuals are unrelated to the fitted values?
B
sum(resid(mod))
• Plot the residuals versus year. Describe the pattern you
see.
Now use the kids-feet data kidsfeet.csv and the model width
∼ length + sex + length:sex.
C
sum(resid(mod))^2
Look at the residuals in the three suggested ways. Are there
any outliers? Describe any patterns you see in relationship to
the fitted model values and the explanatory variable length.
D
sum(resid(mod)^2)
7 The graph shows some data on natural gas usage (in ccf)
versus temperature (in deg. F) along with a model of the relationship.
E
sum(resid(mod^2))
F
None of the above.
6 It can be helpful to look closely at the residuals from a model.
Here are some things you can easily do:
a) Look for outliers in the residuals. If they exist, it can be
worthwhile to look into the cases involved more deeply.
(a) What are the units of the residuals from a model in which
They might be anomalous or misleading in some way.
natural gas usage is the response variable?
b) Plot the residuals versus the fitted model values. Ideally
ccf degF ccf.per.degF none
there should be no evident relationship between the two
— the points should be a random scatter. When there is a (b) Using the graph, estimate the magnitude of a typical residual, that is, approximately how far a typical case is from
strong relationship, even though it might be complicated,
the model relationship. (Ignore whether the residual is posthe model may be missing some important term.
itive or negative. Just consider how far the case is from the
c) Plot the residuals versus the values of an important exmodel, whether it be above or below the model curve.)
planatory variable. (If there are multiple explanatory
2ccf 20ccf 50ccf 100ccf
variables, there would be multiple plots to look at.)
Again, ideally there should be no evident relationship. (c) There are two cases that are outliers with respect to the
If there is, there is something to think about.
model relationship between the variables. Approximately
how big are the residuals in these two cases?
2ccf 20ccf 50ccf 100ccf
Using the world-record swim data, swim100m.csv construct the
Math 243 – Summer 2012
PS 8
Now ignore the model and focus just on those two outlier
cases and their relationship to the other data points.
(d) Are the two cases outliers with respect to natural gas usage? True or False
5
(e) Are the two cases outliers with respect to temperature?
True or False