STATS 330 Revision

1. The selling prices (in British pounds) at auction of 32 antique grandfather clocks were

recorded. The age of each clock (in years) and the number of people who participated in

the bidding were also recorded.

Age Bidders Price Age Bidders Price Age Bidders Price
2. 13 1235 115 12 1080 127 7 845
3. 9 1522 156 6 1047 182 11 1979
4. 12 1822 132 10 1253 137 9 1297
5. 9 946 137 15 1713 117 11 1024
6. 8 1147 153 6 1092 117 13 1152
7. 10 1336 170 14 2131 182 8 1550
8. 11 1884 184 10 2041 143 6 854
9. 9 1483 108 14 1055 175 8 1545
10. 6 729 179 9 1792 111 15 1175
11. 8 1593 111 7 785 115 7 744
12. 5 1356 168 7 1262 (a) A conditional plot of Price versus Age given the level of Bidders was created using coplot. This Plot suggest that Age and Bidders. I. What is meant by the statement “Age and Bidders”. II. Explain what feature of the conditional plot indicates that there is an interaction between Age and Bidders (your explanation should clearly identify how the plot would be different if the two variables did not interact). [5 marks] (b) The output for the regression model containing the Age:Bidders interaction is: T value Estimate Std. Error (Pr > | | t) (Intercept) Age 320.4580 295.1413 1.086 0.28684 0.8781 2.0322 0.432 0.66896 Bidders -93.2648 29.8916 -3.120 0.00416 **

## Bidders: 1.2978 0.2123 6.112 1.35E-06*

Signilf. Codes: 0 0.001 0.01 0.05. 0.1 1 Residual standard error: 88.91 on 28 degrees of freedom Multiple R-squared: 0.9539,Adjusted R-squared: 0.9489 F-squared: 1 on 3 and 11 DF, p-value: 1. Consider the following line of this output. F-statistic: 193 on 3 and 28df, p-value: < 2.2E-16 What does indicate about the expressive model? ii. Consider the following statement: As the fitted coefficient for Bidders is negative, this model indicates that E(Price) decreases as the number of bidders increases. Do you agree with this statement? Explain your answer. [5 marks] (c) Suppose that a seller has a clock that is 150 years old. i. Based on our fitted model, write down the relationship between E(Price) and Bidders for this clock. ii. How does this relationship change as the value of Age is increased? [5 marks]

13. The Stat2Data package in R contains a data set that records the prices of horses advertised for sale on the internet. The data was collected by a group of students from California Polytechnic State University. The information they collected for each horse included: Price — Price in US dollars. Age — Age of the horse in years. Height — Height of the horse in hands m=male. This data was used to create a data frame horse.df in R.

Price Age Height Sex

14. 38000 3 16.75 m
15. 40000 5 17.00 m
16. 12000 8 16.00 f
17. 25000 4 16.25 m
18. 35000 8 16.25 f
19. 35000 5 16.50 m

summary(horse.df)

Price Age Height Sex

Min. : 1100 Min. : 0.500 Min. : 14.25f

1st Qu.:15750 1st Qu.: 5.000 1st Qu.: 16.00M :29

Median: 25,000, Median: 7.000, Median :16.50

Mean :27957 Mean: 7.489 Mean :16.33

3rd Qu.:40000 3rd Qu.: 8.500 3rd Qu.:16.75

Max. :60000 Max. :20.000 Max. :17.25

The following regression model was fitted using this data:

horse.lm=lm(log(Price)~Age*Sex+Height,data=horse.df)

summary(horse.lm)

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 4.19038 2.14289 1.955 0.057201.

Age-0.14882 0.02116-7.035 1.3E-08
*

Sexm-0.53174 0.29584-1.797 0.079464.

Height 0.41017 0.13818 2.968 0.004926 **

Age:Sexm 0.13585 0.03253 4.1760.000146
*

Residual standard error: 0.4666 on 42 degrees of freedom

Multiple R-squared: 0.6884, Adjusted R-squared: 0.6587

F-statistic: 23.2 on 4 and 42 DF, p-value: 3.582e-10

(a) The fitted model uses log(Price) as the response. The assumptions for the ordinary

regression model are linearity, independence, constant variance and Normality. Which of

these assumptions are affected by using log(Price) rather than Price as the response?

20. marks

(b) For the fitted model, Sex is a factor and its indicator variable is set up using f as the

baseline level. An explanatory variable Age:Sexm which represents the interaction be-

tween Age and Sex has also been set up. For the first six observations of horse.df (given

on the previous page) write down the values of Sexm and Age:Sexm. 2 marks

(c) The output for the anova command is:

anova(horse.lm)

Response: log(Price)

Df Sum Sq Mean Sq F value Pr(>F)

Age 1 7.1303 7.1303 32.745 9.955e-07
*

Sex 1 6.9854 6.9854 32.080 1.207e-06
*

Height 1 2.2938 2.2938 10.534 0.0023039 **

Age:Sex 1 3.7970 3.7970 17.437 0.0001465
*

Residuals 42 9.1456 0.2178

The p-value for Sex in this table is much smaller than the p-value for Sexm in the summary

output on the previous page. However the p-value for Age:Sex in this table and that for

Age:Sexm in the summary output are the same. Explain why this occurs. 3 marks

(d) Use the fitted model to compare the impact Age, Sex and Height have on Price.

21. marks
22. An advertisement for diamonds was included in the February 18, 2000 edition of The Business Times. This advertisement gave the following characteristics for 308 diamonds: price Price in Singapore dollars. carats Size measured in carats. colour Colour rating on the GIA colour scale which goes from D (colourless) through Z (light colour). The diamonds listed all had ratings of D, E, F, G, H or I. clarity Clarity rating on the GIA clarity scale. The diamonds listed all had ratings of IF (internally flawless), VVS1, VVS2, VS1 or VS2. VS1 and VS2 indicate very slightly flawed diamonds whereas VVS1 and VVS2 indicate very very slightly flawed diamonds. For VS1 and VVS1 the flaw is only visible from the pavilion (bottom) and for VS2 and VVS2 the flaw is only visible from the crown (top). cert The certification agency: Gemmological Institute of America (GIA), International Gem- mological Institute (IGI) or Hoge Raad Voor Diamant (HRD). This data was read into a data frame named diamond.df in R and the following output obtained:

summary(diamond.df)

carats colour clarity cert price

MIN. : 0.1800D :16 IF :44 GIA:151 MIN. : 638

1st Qu.:0.3500 E:44 VS1 :81 HRD: 79 1st Qu.: 1625

Median :0.6200 F:82 VS2 :53 IGI: 78 Median: 4215

Mean: 0.6309g :65 VVS1:52 Mean: 5019

3rd Qu.:0.8500 H:61 VVS2:78 3rd Qu.: 7446

Max. :1.1000 I:40 Max. :16008

(a) The diamond data was used to construct a regression model that relates the price of

a diamond to the remaining characteristics. The following set of diagnostic plots was

obtained for the linear model:

diamond1.lm<-lm(price~carats+colour+clarity+cert,data=diamond.df)

plot(diamond1.lm)

23. 2000 6000 10000 Based on these plots discuss how well this model fits the data. Give reasons for any conclusions you (5 marks) (b) It was decided to modify the regression model by using √ price as the response. Consider the following output:

diamond2.lm<-lm(price^.5~carats+colour+clarity+cert,data=diamond.df)

new.df=data.frame(carats=1, colour = “F”, clarity=”VS2″, cert=”HRD”)

predict(diamond2.lm,new.df,interval = “confidence”)

fit lwr upr

24. 98.00119 97.06094 98.94144

predict(diamond2.lm,new.df,interval = “prediction”)

fit lwr upr

25. I. Use this output to find a 95% confidence interval and a 95% prediction interval for the Price of a 1 carat diamond certified by HRD that has colour “F” and Clarity “VS2”. II. In the context of this example, clearly explain why the prediction interval is wider than the confidence interval. (5 marks) (c) The factor cert was included in the model since it was thought that the reputation of the certification agency (GIA, IGI or HRD) may have an impact on price. Consider using the anova function to evaluate the relevance of cert in the model using an F-test:

diamond2.lm<-lm(price^.5~carats+colour+clarity+cert,

data=diamond.df)

anova(diamond2.lm)

Analysis of Variance Table

Df Sum Sq Mean Sq F value Pr(>F)

Carats 1 177237 177237 32036.7488 < 2.2e-16
*

Colour 5 5227 1045 188.9561 < 2.2e-16
*

Clarity 4 2950 737 133.3014 < 2.2e-16
*

Cert 2 107 54 9.6783 8.49e-05
*

Residuals 295 1632 6

If the regressors are ordered differently in the model, the value of the F-statistic for cert

Changes from 9.6783 to 5617.27 in the Anova table.

diamond2A.lm<-lm(price^.5~cert+carats+colour+clarity,

data=diamond.df)

anova(diamond2A.lm)

Analysis of Variance Table

Df Sum Sq Mean Sq F value Pr(>F)

Cert 2 62153 31076 5617.27 < 2.2e-16
*

Carats 1 115217 115217 20826.30 < 2.2e-16
*

Colour 5 5356 1071 193.62 < 2.2e-16
*

Clarity 4 2795 699 126.28 < 2.2e-16
*

Residuals 295 1632 6

Both tests result in very small p-values but they are testing different hypotheses.

i. Carefully explain the difference between the tests for cert in these two tables.

ii. Which test is more relevant in investigating whether the reputation of the certifica-

tion agency has an impact on price? Explain your answer. (5 marks)

(d) The output from summary for the

Square root

price model used in parts (b) and (c) is:

summary(diamond2A.lm)

Call:

Lm (formula = price^0.5 ~ cert + carats + colour + clarity,

data = diamond.df)

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 25.62462 0.84435 30.348 < 2e-16
*

CERTHRD 0.03969 0.35509 0.112 0.911

Certi-1.80848 0.42466-4.259 2.77e-05
*

CARATS 91.47532 0.62917 145.391 < 2E-16
*

ColourE -5.52416 0.68862-8.022 2.47e-14
*

Colourf-8.17357 0.64641-12.645 < 2e-16
*

Colourg-10.71430 0.66350-16.148 < 2e-16
*

Colourh-14.12727 0.67184-21.028 < 2E-16
*

Colouri-18.23773 0.70429-25.895 < 2E-16
*

ClarityvS1-8.45895 0.52868-16.000 < 2E-16
*

Clarityvs2-10.96488 0.56679-19.346 < 2e-16
*

Clarityvvs1-2.69994 0.52951-5.099 6.12e-07
*

Clarityvvs2-5.95314 0.49254-12.087 < 2E-16
*

Consider the coefficients for the four indicator (dummy) variables used for the factor

clarity.

I. What does the estimated coefficient for Clarityvs1 (-8.45895) represent in terms of

the levels of clarity?

ii. What is the estimated difference in the expected

Square root

price for very very slightly flawed

diamonds where the flaw is only visible from the pavilion (VVS1) and where the flaw

is only visible from the crown (VVS2)?

iii. Suppose we want to formally test (i.e. find a p-value) the hypothesis that there is

no difference in the average price of VVS1 and VVS2 diamonds (given that all other

characteristics are the same). Suggest a simple method of adjusting the regression

model so that the required p-value is calculated for us. (5 marks)

26. Sahoo and H.S. Pandalai (Natural Resources Research, vol. 8, 1999) used logistic regression to predict the probability of a gold deposit being present based the concentrations of Arsenic (As) and Antimony (Sb) in ground water samples were taken from a total of 64 sites — of these, 28 had a gold deposit present. The concentrations of As and Sb in the samples were measured as parts per million (ppm). (a) The fitted model logistic for this data is:

gold.glm<-glm(gold~As+Sb,family=binomial,data=gold.df)

summary(gold.glm)

Coefficients:

Estimate Std. Error z value Pr(>|z|)

(Intercept) -4.9664 1.3675-3.6320.000281
*

As 1.2490 0.3777 3.307 0.000943
*

Sb 0.9235 0.4486 2.059 0.039518 *

Deviance: 87.720 on 63 degrees of freedom Residual devance: 18.306 on 61 degrees of freedom AIC. 24.301. Let PI represent the probability that a gold deposit is present. Write down the logistic form of the expressive model (i.e. pi = . . .) . ii. Find a 95% confidence interval for the coefficient for As. iii. Interpret the coefficient for As in terms of the impact of the concentration of As on the odds of a gold deposit being present. (5 marks) (b) The following output was obtained using the anova function.

anova(gold.glm,test=”Chisq”)

Terms added sequentially (first to last)

Df Deviance Resid. Df Resid. Dev Pr(>Chi)

NULL 63 87.720

As 1 65.117 62 22.603 7.057e-16
*

Sb 1 4.297 61 18.306 0.03818 *

i. What hypothesis is being tested by the line

As 1 65.117 62 22.603 7.057e-16
*

in this table? What do you conclude from this test?

ii. The output for summary(gold.glm) also provides a test for As.

Estimate Std. Error z value Pr(>|z|)

As 1.2490 0.3777 3.307 0.000943
*

How does this test differ from the test in (i)?

(5 marks)

i. Which points are identified as being usual by these plots? For each of these points

describe what makes it unusual. Note that using HMD and deviance changes as

diagnostics were not covered this semester so you can ignore those two plots and

Just look at the Cook’s distance plot.

ii. Briefly describe how you would further investigate the unusual points you identified.

(5 marks)

(d) Suppose the fitted model is to be used to predict the presence of gold deposits for other

sites (it is not known whether gold is present at these sites). A gold deposit is predicted to

be present if the estimated probability is more than one half and is otherwise predicted to

be absent. The following table summarizes the performance of this prediction procedure

when it is applied to the 64 observations in the data set.

Prediction

Actual gold present gold absent

gold present 26 2

gold absent 1 35

i. Based on this table, estimate the sensitivity and the specificity for this prediction

model. Explain why these estimates are too optimistic.

ii. Suggest a different method for estimating the sensitivity and specificity that still

uses the original data but should give more realistic estimates.

(5 marks)

27. The data for this question come from an ecological study conducted by Dr Rick Linhurst (1979, PhD thesis, North Carolina State). The study focussed on the relationship between the biomass (weight per unit area) of spartina (a type of grass found in coastal salt marshes) and the properties of the soil at different sites in the Cape Fear estuary of North Carolina. Data was collected from three different locations: Oak Island (OI), Smith Island (SI) and Snow’s Marsh (SM). At each location, there were areas where the spartina vegetation was short (SHRT), other areas where it was tall (TALL) and still other areas where it had died and re-vegetated (DVEG). For each combination of location and vegetation type, five sites were selected and the biomass of spartina was measured. Consider the following conditional plot for this data. (a) Consider creating a regression model that relates biomass (BIO) to location (Loc) and vegetation type (Type). The plot on the previous page indicates that it may be appro- priate to i. use log(BIO) as the response and ii. include the Loc:Type interaction in the model. Explain how the plot indicates that each of these actions may be appropriate. [4 marks] (b) Consider a regression model that uses the logged biomass (BIO) as the response and vegetation type (Type) and location (Loc) as regressors.

model1.lm<-lm(log(BIO) ~ Loc*Type,data=spartina.df)

summary(model1.lm)

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 6.6805 0.1466 45.575 < 2e-16
*

Locsi-0.8659 0.2073-4.1770.000179
*

LocSM 0.6189 0.2073 2.985 0.005066 **

Typeshrt-0.3688 0.2073-1.779 0.083668.

TypeAll 0.4512 0.2073 2.176 0.036171 *

Locsi :TypeSHRT 0.2311 0.2932 0.788 0.435751

Locsm: typeshrt-0.7450 0.2932-2.541 0.015496 *

Locsi :TypeTALL 1.0486 0.2932 3.577 0.001015 **

LocSM: typetall-0.4358 0.2932-1.486 0.145882

Residual standard error: 0.3278 on 36 degrees of freedom Multiple R-squared: 0.8195,Adjusted R-squared: 0.7794 F-statistic: 20.43 on 8 and 36 DF, p-value: 3.142e-11 Use this model to estimate each of the following: i. the biomass of spartina for short vegetation at Smith Island. ii. the difference in the biomass of spartina between Re-vegetated Sites (Dveg) at Snow’s Marsh and at Oak Island. III. The difference in the biomass of Spartina Short vegetation and tall vegetation at Smith Island. [6 marks] (c) Recall that for each combination of location and vegetation type, five sites were selected and the biomass of spartina was measured. Characteristics of the soil were also measured at each site. One of these characteristics was the pH which indicates the acidity or alkalinity of the soil. The following search procedure was used to see whether it would be useful to include pH (or interactions involving pH) in the model. model2.lm<-lm(log(BIO) ~ Loc+Type+pH,data=spartina.df) model3.lm<-lm(log(BIO) ~ LocTypepH,data=spartina.df) spartstepln.lm<-step(object=model2.lm,scope=formula(model3.lm), direction=”both”) Briefly, describe the following aspects of this search procedure. i. The starting model. ii. The set of regressors being considered. iii. The procedure used at each step to select the next model. [4 marks] (d) Consider the model selected by this search procedure. Call: lm(formula = log(BIO) ~ Loc + Type + pH + Loc:Type + Loc:pH, Data = spartina. Df) Estimate Std. Error t value Pr (> | | t) (Intercept) e-08 * LocSI – 1.27 6.92216 0.92315 7.498 12.65295 Typeshrt-0.37689 0.17288-2.180 0.036491 * TypeTALL 1.75000-4.601 5.95e-05 * locsm-0.62059 1.74134-0.356 0.723821 typeshrt-0.37689 0.17288-2.180 0.036491 * TypeTALL 0.39757 0.26485 1.501 0.142840 pH-0.05055 0.19148-0.264 0.793424 LocSI:TypeSHRT 0.37952 0.24460 1.552 0.130294 Typeshrt-0.55440 0.36236-1.530 0.135559 Typsi: typetall-13.14536 3.20872-4.097 0.000255 * LocSM:TypeTALL -0.49372 0.35519-1.390 0.173828 LocSI:pH 3.55980 0.80948 4.398 0.000107 *

## LocSM:pH 0.25336 0.35515 0.713 0.480610

Residual standard error: 0.269 on 33 degrees of freedom Multiple R-squared: 0.8885,Adjusted R-squared: 0.8514 F-statistic: 23.91on 11 and 33df, p-value: 1.315E-12 Use this model to describe the impact that pH has on the biomass of Spartina. [6 Marks]

28. The number of different mussel species was recorded in 41 rivers along the east coast of the USA. Nine possible explanatory variables were recorded and described as follows: area – the area of drainage basin. sAC, sAP, sSL, sSV – the number of intermediate rivers to 4 major species-source river systems: Alabama-Coosa (sAC), Apalachicola (sAP) St. Lawrence (sSL), and Savannah (sSV). nitrate – nitrate concentration. hy – hydronium ion concentration. solres the amount of solid residue present in the water. logarea – it was thought that taking the log of the area might improve the model fit so this was also included as a potential regressor. Reference: Sepkoski, Jr., M.A. Rex (1974). “Distribution of Freshwater Mussels: Coastal Rivers as Biogeographic Islands, “Systematic Zoology, Vol. 23(2), pp. 165-188. The first six rows of the data frame for the mussels data:

species area sAC sAP sSV sSL nitrate solres hy logarea

Penobscot 9 8440 33 28 21 4 0.8 57 4.0 9.0407

Kennebec 8 5960 32 27 20 5 0.4 31 3.2 8.6928

Androscoggin 7 3510 31 26 19 6 0.6 65 2.5 8.1634

Saco 6 1730 30 25 18 7 0.8 33 2.5 7.4559

Merrimac 11 5020 29 24 17 8 2.6 78 6.3 8.5212

Blackstone 8 425 26 21 14 11 8.4 120 20.0 6.0521

The step function was used to conduct two searches for a suitable model using the following

R code:

null.glm<- glm(species~1,family = poisson, data=mussels.df)

full.glm<-glm(species~.,family = poisson, data=mussels.df)

formula(full.glm)

species ~ area + sAC + sAP + sSV + sSL + nitrate + solres + hy + logarea

step1.glm=step(null.glm,scope=formula(full.glm),trace=0,direction=”both”)

summary(step1.glm)

Estimate Std. Error z value Pr(>|z|)

(Intercept) 0.9483756 0.4701266 2.017 0.043667 *

Logarea 0.2495191 0.0513711 4.857 1.19e-06
*

SAC -0.0258976 0.0056666-4.570 4.87E-06
*

Solres-0.0022974 0.0006491-3.5401
*

HY-0.0329310 0.0112529-2.926 0.003429 **

CH4 0.0514423 0.0285902 1.799 0.071971.

Null deviance: 127.527 on 43 degrees of freedom

Residual devance: 46.426 on 38 degrees of freedom

AIC: 240.45

step2.glm=step(full.glm,scope=formula(full.glm),trace=0,direction=”both”)

summary(step2.glm)

Estimate Std. Error z value Pr(>|z|)

(Intercept) 0.765412 0.487918 1.569 0.116711

SAP -0.034419 0.007187-4.789 1.67E-06
*

SSV 0.016718 0.011265 1.484 0.137800

CH4 0.049525 0.028270 1.752 0.079799.

Solres-0.002328 0.000655-3.554 0.000379
*

HY-0.031616 0.011363-2.782 0.005394 **

Logarea 0.257352 0.051853 4.963 6.94e-07
*

Null deviance: 127.527 on 43 degrees of freedom

Residual devance: 44.303 on 37 degrees of freedom

AIC: 240.33

(a) Consider the two searches that were performed.

i. Briefly describe the procedure used for the first search (step1.glm).

ii. How does the second search differ from the first search?

iii. Consider the models step1.glm and step2.glm found by the two searches. Is either

model clearly better than the other one? Explain your answer. (5 marks)

(b) Consider the impact of hydronium concentration (hy) on the mean number of mussel

species found in a river.

i. Based on the output for model step1.glm, explain the impact on the mean number

of mussel species if the hydronium concentration is increased by 1 unit (and all

remaining explanatory variables are fixed).

ii. Use the following output to produce a 95% confidence interval for your estimate of

this impact.

confint(step1.glm)

2.5% 97.5%

0.020585439 1.864031858 (Intercept)

Logarea 0.149254036 0.350694327

SAC – 0.037083119-0.014862806

Solres – 0.003625416-0.001075839

Hy – 0.056618776-0.012315184

Nitrate – 0.006685696-0.105584270

iii. Estimate the impact of increasing hydronium concentration by 3 units on the mean

number of mussel species found in a river. (6 marks)

(C) If a goodness of fit test is performed for model step1. GLM, the p-value is equal to 0.19.

Explain how the p-value is calculated. What do you conclude about model step1.glm

from this test? (4 marks)

(d) Consider the following set of diagnostic plots for model step1.glm

Based on these plots describe any concerns or issues you have with the fitted model.

ii. Briefly explain how you would address each of the concerns/issues you have identi-

fied. (5 marks)

WX: codehelp