Practice exam 4
Block 1 - Diagnostic analytics and causality
2A retail chain measures the delivery time (days) of n = 40 deliveries (simulated data). What do you conclude from this output about the average delivery time?
One Sample t-test
data: lev
t = 20.192, df = 39, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
4.64761 5.68239
sample estimates:
mean of x
5.165
3Which sentence describes the purpose of a causal relationship scheme best?
4A webshop records five order values (in euro): 4, 8, 6, 10 and 12 (simulated data). What is the standard deviation s of this sample?
Block 2 - Descriptive statistics, sampling and correlation
5A researcher wants to know how many Dutch people shop groceries online and puts a questionnaire only on a tech news site. What is the biggest risk?
6A poll among 2.3 million people predicts an election wrongly, because the list consisted of car owners and phone users. What does this teach?
7The order value of customers is strongly right-skewed. An analyst draws many samples of n = 40 and looks at the means. What does the central limit theorem say?
8With n = 12 observations an analyst does not know sigma and uses s. Which critical value does she use for the 95% interval?
Block 3 - Hypothesis testing
9A manager wants to show that a new website increases mean time on site (mu0 = 120 s). Which hypotheses do you formulate?
10When do you choose a two-sided test?
11What follows from the 99% interval (0.318 to 0.401) for H0: mu = 0.30 with alpha = 0.01, two-sided?
> t.test(Gov$Leverage, mu = 0.3)
One Sample t-test
data: Gov$Leverage
t = 3.7721, df = 182, p-value = 0.0002188
alternative hypothesis: true mean is not equal to 0.3
95 percent confidence interval:
0.3283719 0.3906065
sample estimates:
mean of x
0.3594892
> t.test(Gov$Leverage, mu = 0.3, conf.level = 0.99)
One Sample t-test
data: Gov$Leverage
t = 3.7721, df = 182, p-value = 0.0002188
alternative hypothesis: true mean is not equal to 0.3
99 percent confidence interval:
0.3184358 0.4005426
sample estimates:
mean of x
0.3594892
12A sample has n = 36, mean 80 and standard deviation 12. Use t* = 2.03. What is the upper bound of the 95% confidence interval?
13After reverse coding Risk02, Risk05 and Risk08 alpha is 0.7978. Which conclusion follows from the "alpha if item dropped" column?
> Ent <- na.omit(Ent)
> Ent2 <- Ent
> for (i in c("Risk02", "Risk05", "Risk08")) Ent2[[i]] <- 6 - Ent2[[i]]
> a2 <- psych::alpha(Ent2, warnings = FALSE)
> round(a2$total$raw_alpha, 4)
[1] 0.7978
> round(a2$alpha.drop["raw_alpha"], 4)
raw_alpha
Risk01 0.7912
Risk02 0.7788
Risk03 0.7693
Risk05 0.7711
Risk06 0.7875
Risk07 0.7816
Risk08 0.7676
Risk09 0.7547
> round(cor(Ent2, use = "complete.obs")[, 1], 3)
Risk01 Risk02 Risk03 Risk05 Risk06 Risk07 Risk08 Risk09
1.000 0.274 0.328 0.314 0.229 0.211 0.223 0.332
14How do you lower the probability of a Type II error without raising the probability of a Type I error?
Block 4 - Data cleaning and management
15table(d$gender) shows four categories: female, male, Male and M. What is the problem and what do you do?
16A variable has minimum 50 and maximum 90. What is the normalized (min-max) value of x = 70?
Block 5 - Linear regression
17An HR department models the annual salary (in euros) of 240 alumni using years of education, years of experience and a dummy vrouw (1 = woman). The dependent variable is ln(salaris). Simulated data. What is the estimated percentage difference in salary for one extra year of education, holding experience and gender equal?
> rK <- lm(log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
> summary(rK)
Call:
lm(formula = log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
Residuals:
Min 1Q Median 3Q Max
-0.60643 -0.18152 0.00117 0.17144 0.75468
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.449195 0.086327 109.458 < 2e-16 ***
opleiding 0.070291 0.005293 13.280 < 2e-16 ***
ervaring 0.012553 0.001840 6.824 7.41e-11 ***
vrouw -0.056155 0.032043 -1.752 0.081 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2461 on 236 degrees of freedom
Multiple R-squared: 0.5145, Adjusted R-squared: 0.5084
F-statistic: 83.38 on 3 and 236 DF, p-value: < 2.2e-16
18An HR department models the annual salary (in euros) of 240 alumni using years of education, years of experience and a dummy vrouw (1 = woman). The dependent variable is ln(salaris). Simulated data. The dummy vrouw has p = 0.081. Which conclusion is correct?
> rK <- lm(log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
> summary(rK)
Call:
lm(formula = log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
Residuals:
Min 1Q Median 3Q Max
-0.60643 -0.18152 0.00117 0.17144 0.75468
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.449195 0.086327 109.458 < 2e-16 ***
opleiding 0.070291 0.005293 13.280 < 2e-16 ***
ervaring 0.012553 0.001840 6.824 7.41e-11 ***
vrouw -0.056155 0.032043 -1.752 0.081 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2461 on 236 degrees of freedom
Multiple R-squared: 0.5145, Adjusted R-squared: 0.5084
F-statistic: 83.38 on 3 and 236 DF, p-value: < 2.2e-16
19An HR department models the annual salary (in euros) of 240 alumni using years of education, years of experience and a dummy vrouw (1 = woman). The dependent variable is ln(salaris). Simulated data. By how many percent is the expected salary of a woman lower than that of a man with the same education and experience, according to the log model?
> rK <- lm(log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
> summary(rK)
Call:
lm(formula = log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
Residuals:
Min 1Q Median 3Q Max
-0.60643 -0.18152 0.00117 0.17144 0.75468
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.449195 0.086327 109.458 < 2e-16 ***
opleiding 0.070291 0.005293 13.280 < 2e-16 ***
ervaring 0.012553 0.001840 6.824 7.41e-11 ***
vrouw -0.056155 0.032043 -1.752 0.081 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2461 on 236 degrees of freedom
Multiple R-squared: 0.5145, Adjusted R-squared: 0.5084
F-statistic: 83.38 on 3 and 236 DF, p-value: < 2.2e-16
20Why would an analyst use ln(salaris) instead of salaris as the dependent variable?
21An HR department models the annual salary (in euros) of 240 alumni using years of education, years of experience and a dummy vrouw (1 = woman). The dependent variable is ln(salaris). Simulated data. A colleague sees both outputs and says: "the log model has R² = 0.5145 and the level model 0.4851, so the log model fits better." What is the correct reaction?
> rK <- lm(log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
> summary(rK)
Call:
lm(formula = log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
Residuals:
Min 1Q Median 3Q Max
-0.60643 -0.18152 0.00117 0.17144 0.75468
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.449195 0.086327 109.458 < 2e-16 ***
opleiding 0.070291 0.005293 13.280 < 2e-16 ***
ervaring 0.012553 0.001840 6.824 7.41e-11 ***
vrouw -0.056155 0.032043 -1.752 0.081 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2461 on 236 degrees of freedom
Multiple R-squared: 0.5145, Adjusted R-squared: 0.5084
F-statistic: 83.38 on 3 and 236 DF, p-value: < 2.2e-16
> rL <- lm(salaris ~ opleiding + ervaring + vrouw, data = sal)
> round(coef(summary(rL)), 3)
Estimate Std. Error t value Pr(>|t|)
(Intercept) -8870.064 4102.149 -2.162 0.032
opleiding 3172.988 251.520 12.615 0.000
ervaring 542.843 87.415 6.210 0.000
vrouw -2767.541 1522.656 -1.818 0.070
> round(summary(rL)$r.squared, 4)
[1] 0.4851
22An HR department models the annual salary (in euros) of 240 alumni using years of education, years of experience and a dummy vrouw (1 = woman). The dependent variable is ln(salaris). Simulated data. The intercept is 9.449. Which statement is correct?
> rK <- lm(log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
> summary(rK)
Call:
lm(formula = log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
Residuals:
Min 1Q Median 3Q Max
-0.60643 -0.18152 0.00117 0.17144 0.75468
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.449195 0.086327 109.458 < 2e-16 ***
opleiding 0.070291 0.005293 13.280 < 2e-16 ***
ervaring 0.012553 0.001840 6.824 7.41e-11 ***
vrouw -0.056155 0.032043 -1.752 0.081 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2461 on 236 degrees of freedom
Multiple R-squared: 0.5145, Adjusted R-squared: 0.5084
F-statistic: 83.38 on 3 and 236 DF, p-value: < 2.2e-16
23An HR department models the annual salary (in euros) of 240 alumni using years of education, years of experience and a dummy vrouw (1 = woman). The dependent variable is ln(salaris). Simulated data. What does the log model predict for the annual salary (in euros, after back-transforming with exp) of a woman with 16 years of education and 10 years of experience?
> rK <- lm(log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
> summary(rK)
Call:
lm(formula = log(salaris) ~ opleiding + ervaring + vrouw, data = sal)
Residuals:
Min 1Q Median 3Q Max
-0.60643 -0.18152 0.00117 0.17144 0.75468
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.449195 0.086327 109.458 < 2e-16 ***
opleiding 0.070291 0.005293 13.280 < 2e-16 ***
ervaring 0.012553 0.001840 6.824 7.41e-11 ***
vrouw -0.056155 0.032043 -1.752 0.081 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2461 on 236 degrees of freedom
Multiple R-squared: 0.5145, Adjusted R-squared: 0.5084
F-statistic: 83.38 on 3 and 236 DF, p-value: < 2.2e-16
Block 6 - Logistic regression, overfitting and validation
24Below is the confusion matrix of 500 households at threshold 0.5 (simulated data). In this matrix 1 comes first (TP top left), as on the exam. What is the accuracy of the model?
Werkelijk
Voorspeld 1 0
1 17 12
0 115 356
25Use the coefficients (intercept -3.059258, Inkomen 0.043241, Koophuis 1.010191, Leeftijd -0.014108). What is the predicted probability of acceptance for a renter (Koophuis = 0) aged 25 with Inkomen 30 (€30,000)?
26The acceptance model has an AUC of 0.7142 on the test set. What does that mean?
auc_train auc_test 0.6891 0.7142
27The model has a null deviance of 577.20 and a residual deviance of 527.77. What is the McFadden pseudo-R²?
Null deviance: 577.20 on 499 degrees of freedom Residual deviance: 527.77 on 496 degrees of freedom
28Leeftijd has p = 0.06. A student says: there is a 6% chance that H0 is true. What is correct?
29A model has an AUC of 0.50. What does that mean?
30At cutoff 0.7 the output shows sensitivity 0.0000 and precision NA. The highest predicted probability in the model is 0.6555. What is going on?
[5,] 0.7 0.736 0.0000 1.0000 NA Min. 1st Qu. Median Mean 3rd Qu. Max. 0.03563 0.15462 0.24419 0.26400 0.36012 0.65550
Block 7 - Open questions on R output
7.1Tasks (together at most 200 words): 1. Interpret the coefficients of Bezoeken and Groepsles in business language, including significance at α = 0.05 (4 points). 2. Calculate the accuracy of the small model on the training set and on the test set (2 points). 3. Assess the analyst's choice of the large model (3 points).
A gym chain predicts whether members renew their membership (Verlengt = 1). For 300 members (simulated data), Bezoeken (average number of visits per month), Groepsles (Ja = takes part in group classes, reference category Nee) and Afstand (km to the club) were recorded. The chain estimates a logistic regression on 150 randomly chosen members (training set) and tests on the other 150 (test set), with a threshold of 0.5. An analyst then estimates a much larger model with 29 parameters (interactions and four extra variables) and chooses it because it scores better on the training set.
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.05020 0.66589 -3.079 0.00208 **
Bezoeken 0.42751 0.09034 4.732 2.22e-06 ***
GroepslesJa 0.29279 0.38315 0.764 0.44476
Afstand -0.10452 0.04555 -2.294 0.02177 *
Null deviance: 206.98 on 149 degrees of freedom
Residual deviance: 171.47 on 146 degrees of freedom
AIC: 179.47
Small model, training set: Small model, test set:
Waargenomen Waargenomen
Voorspeld 0 1 Voorspeld 0 1
0 60 28 0 48 33
1 21 41 1 24 45
Large model (29 parameters): training set 0.853 accuracy, test set 0.580 accuracy.
Answer builder
7.2Write a short reflection on the output. Address the following points (250 words maximum in total): 1. Interpret the main regression coefficients from the output. 2. Interpret the p-values and what they say about statistical significance. 3. Assess the model fit and the predictive power of the model. 4. What concerns are there about the sample (bias, representativeness) and how do internal and external validity affect your conclusions?
A researcher models the annual energy intensity (pEnergy) of 211 buildings using the percentage of cooling space (pCool). Dataset Energy02 from the course. The first model uses all buildings; the second omits two buildings with pCool above 35. Write a short reflection (at most 250 words in total) on the output.
> rH <- lm(pEnergy ~ pCool, data = En)
> summary(rH)
Call:
lm(formula = pEnergy ~ pCool, data = En)
Residuals:
Min 1Q Median 3Q Max
-32.311 -7.480 -0.487 8.722 44.359
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 36.9610 1.3782 26.818 <2e-16 ***
pCool 0.1400 0.1127 1.242 0.216
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 11.25 on 209 degrees of freedom
Multiple R-squared: 0.007326, Adjusted R-squared: 0.002577
F-statistic: 1.542 on 1 and 209 DF, p-value: 0.2156
> rI <- lm(pEnergy ~ pCool, data = En[En$pCool < 35, ])
> summary(rI)
Call:
lm(formula = pEnergy ~ pCool, data = En[En$pCool < 35, ])
Residuals:
Min 1Q Median 3Q Max
-32.455 -7.585 -0.524 8.755 45.027
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 34.7521 1.9765 17.583 <2e-16 ***
pCool 0.3779 0.1891 1.999 0.047 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 11.23 on 207 degrees of freedom
Multiple R-squared: 0.01893, Adjusted R-squared: 0.01419
F-statistic: 3.994 on 1 and 207 DF, p-value: 0.04697
Answer builder
7.3Assignments (together at most 150 words): 1. Name the role of burn-out complaints and of support of the team leader in the causal relationship scheme (2 points). 2. Formulate one testable hypothesis about the effect of workload on sick leave, and give the corresponding null hypothesis (3 points). 3. Explain why it is important that the hospital records the hypothesis before the analysis (2 points).
A hospital investigates whether a high workload leads to more sick leave among nurses. The HR manager thinks a high workload causes burn-out complaints and that burn-out complaints lead to sick leave. He suspects that a supportive team leader reduces the effect of workload on burn-out. The hospital wants to record the hypothesis in advance and only then analyse the data of the Internal Medicine department.