This HTML file uses code_folding. You can look at any accompanying code by pressing the little code boxes and then hide it again to get a smoother look at the report. Each project also uses a tabset layout. Under the headlines are tabs, each containing answers to a part of the project.

Project 1 (25%)



Summary

Discharge can be modeled as a function of water level with the following relationship \[ Q(h) = a h^{f(h)} \]

where \(Q\) is the discharge, \(h\) is the water level, \(a\) is a parameter and \(f(h)\) is a function of water level. Let \(y(h)\) = \(\log(Q(h))\) and \(\beta_1=\log(a)\). The relationship between \(y\) and \(h\) is given by

\[ y(h) = \beta_0 + f(h)\log(h). \] Assume that \(f(h)\) can be modeled as

\[ f(h) = \beta_1 + \beta_2 (h - h_{\textrm{c}}) + \beta_3 (h - h_{\textrm{c}})^2 + \beta_4 (h - h_{\textrm{c}})^3 + \beta_5 (h - h_{\textrm{c}})^4 + \beta_6 (h - h_{\textrm{c}})^5 \] where \(h_{\textrm{c}}\) is a constant close to the sample mean of the observed water level found in the dataset that is being analyzed. Based on this, the following statistical model for the observed pairs \((y_i,h_i)\) is proposed, namely,

\[ y_i = \beta_0 + \{\beta_1 + \beta_2 (h_i - h_{\textrm{c}}) + \beta_3 (h_i - h_{\textrm{c}})^2 + \beta_4 (h_i - h_{\textrm{c}})^3 + \beta_5 (h_i - h_{\textrm{c}})^4 + \beta_6 (h_i - h_{\textrm{c}})^5\}\log(h_i) + \epsilon_i \]

where \(\epsilon_i \sim \textrm{N}(0,\sigma^2)\), \(i=1,...,n\), and \(\epsilon_i\) is independent of \(\epsilon_j\) if \(i\neq j\). \

The file dc.csv contains \(n=124\) simulated pairs of \(Q\) and \(h\) (\(Q\) in column 2; \(h\) in column 3). Here \(h_{\textrm{c}}=2.25\) m. The file also contains vectors with the following variables

\[ x_{i1} = \log(h_i), \quad x_{i2}=(h_i - h_{\textrm{c}})\log(h_i) , \] \[ x_{i3}=(h_i - h_{\textrm{c}})^2 \log(h_i), \quad x_{i4}=(h_i - h_{\textrm{c}})^3 \log(h_i), \] \[ x_{i5}=(h_i - h_{\textrm{c}})^4 \log(h_i), \quad x_{i6}=(h_i - h_{\textrm{c}})^5 \log(h_i), \]

where \(x_{i1}\) is in column 4, \(x_{i2}\) is in column 5, and so on.


(a)

Plot the discharge observations versus the water level observations (water level on the x-axis). Is the relationship linear? Plot the logarithm of the discharge observations versus the logarithm of the water level observations. Is the relationship linear?


Figure 1 below shows that the relationship is not perfectly linear. It is convex near the origin but then seems to stabilize into a linear function. In spite of this there is a trace of heteroskedastic variance.

Figure 1. Discharge versus water level plotted on a linear scale and log-log scale.

Figure 1. Discharge versus water level plotted on a linear scale and log-log scale.


(b)

Fit the model \(y_i = \beta_0 + \beta_1\log(h_i) + \epsilon_i\). Plot the estimate of the line \(y = \beta_0 + \beta_1\log(h)\) as a function of \(\log(h)\) along with the observed data (new figure). Does this model appear to describe the expected value of \(y\) given \(h\) adequately well? Also, plot the residuals as a function of \(\log(h)\). Does the residual plot indicate that the standard deviation of the error term, \(\epsilon\), is a constant as a function of \(\log(h)\)?


The simple linear model does not capture parabolic curvature in the data. This can be seen both when comparing the predicted means to the actual data, and in the obvious parabolic trend in the residuals. The residual plot shows no obvious sign of heteroscedasticity but the extra parabolic trend makes such analysis harder.

Figure 2: Left: Observed points overlaid on predicted line. Right: Residuals plotted by log(waterlevel)

Figure 2: Left: Observed points overlaid on predicted line. Right: Residuals plotted by log(waterlevel)


(c)

Fit the model \(y_i = \beta_0 + \beta_1 x_{i1} + ...+ \beta_6 x_{i6} + \epsilon_i\). Plot the estimate of the curve \(y = \beta_0 + \beta_1 x_{1} + ...+ \beta_6 x_{6}\) as a function of \(\log(h)\) along with the observed data (new figure). Does this model appear to describe the expected value of \(y\) given \(h\) adequadely well? Also, plot the residuals as a function of \(\log(h)\). Does the residual plot indicate that the standard deviation of the error term, \(\epsilon\), is a constant as a function of \(\log(h)\)?


This model fits the data well. The left part of figure 3 shows that the predicted mean responses lie well inside the observed data. On the right of figure 3 we see that there is no discernible pattern in the residuals, but there might be a trace of heteroskedasticity.

Figure 3: Left: Observed points overlaid on predicted line. Right: Residuals plotted by log(waterlevel)

Figure 3: Left: Observed points overlaid on predicted line. Right: Residuals plotted by log(waterlevel)

The absolute values of residuals were regressed on predicted values to get a quick check for unequal variances. Table 1 shows a trend of slightly decreasing variance but the effect is not significant. Figure 4 shows this weak trend with an overlaid local smoother.

Table 1: Residuals regressed on fitted values.
Term Estimate SE t p
(Intercept) 0.050 0.013 3.815 0.000
mod2$fit -0.003 0.002 -1.283 0.202
Figure 4: Absolute values of residuals plotted by log(waterlevel)

Figure 4: Absolute values of residuals plotted by log(waterlevel)


(d)

Use AIC to find which of the models below is best in terms of predicting discharge. The models that should be tested are \(y_i = \beta_0 + \sum_{j=1}^{k} \beta_j x_{ij} + \epsilon_i\) where \(k=1,2,3,4,5,6\).


One model was trained for each value of \(K\). Figure 5 and table 2 show that the lowest AIC score was found for \(K = 3\).

Figure 5: AIC plotted for each K = 1, 2, ..., 6

Figure 5: AIC plotted for each K = 1, 2, …, 6

Table 2: Model AIC for each K = 1, 2, …, 6
K AIC
3 -421.73
4 -419.78
6 -418.27
5 -418.04
2 -417.67
1 -174.98

(e)

Compute an estimate and a 95% confidence interval for the expected value of \(y\) when \(h=3.19\) based on the model selected in (d), that is, the quantity of interest is \(\textrm{E}(y(h)) = \beta_0 + \sum_{j=1}^{k^*} \beta_j x_{j}(h)\) where \(k^*\) was selected in (d). Denote the estimate of \(\textrm{E}(y(h))\) with \(\hat{y}(h)\) where \(\hat{y}(h) = \hat{\beta}_0 + \sum_{j=1}^{k^*} \hat{\beta}_j x_{j}(h)\) Also, compute an estimate of \(\exp(\textrm{E}(y(h)))\), and a 95% confidence interval for \(\exp(\textrm{E}(y(h)))\) when \(h=3.19\).


Table 3 shows the expected values with 95% confidence intervals both for log(discharge) and discharge. Keep in mind that while the standard deviation for log(discharge) is additive it becomes multiplicative on the original scale.

Table 3: Prediction and 95% confidence interval for discharge at log-scale and regular scale.
95% confidence interval
Type Fitted \(\hat \sigma\) Lower Upper
log(discharge) 6.147 0.007 6.133 6.160
discharge 467.192 1.007 460.941 473.527

Project 2 (50%)



Summary

The goal of this project is to find a linear regression model that can be used to predict body fat with body circumference measurements as well as age, height and weight. Accurate measurement of body fat are costly and it is practical to have a simple and low-cost method for estimating body fat. In this project we are given a dataset with estimates of the percentage of body fat determined by underwater weighing for 252 men along with their various body circumference measurements. More information about this dataset can be found at

http://lib.stat.cmu.edu/datasets/bodyfat
https://cran.r-project.org/web/packages/mfp/mfp.pdf

The dataset is a available in R as bodyfat and it is within the package mfp, see

https://www.rdocumentation.org/packages/mfp/versions/1.5.2/topics/bodyfat

The dataset contains 252 observations and 17 variables:

  1. case: index
  2. brozek: percentage of body fat using Brozek’s equation: 457/density - 414.2
  3. siri: percentage of body fat using Siri’s equation: 495/density - 450
  4. density: density determined from underwater weighing
  5. age: in years
  6. weight: in lbs
  7. height: in inches
  8. neck: circumference in cm
  9. chest: circumference in cm
  10. abdomen: circumference in cm
  11. hip: circumference in cm
  12. thigh: circumference in cm
  13. knee: circumference in cm
  14. ankle: circumference in cm
  15. biceps: circumference in cm
  16. forearm: circumference in cm
  17. wrist: circumference in cm

(a)

Fit a linear model for percentage of body fat based on Siri’s equation. Start with setting the height of individual nr. 42 equal to 69.50 inches. Also, remove individual 182 from the dataset. Use all the potential predictors, that is, use age, weight, height and all the circumference variables. Report the summary of the estimation.


Table 4 shows summary statistics for the model. Four predictors were significant at the \(\alpha = .05\) level, age and neck, abdomen, forearm and wrist circumference. The model \(R^2\) is \(0.744\), \(R^2_{adj} = 0.73\) and \(AIC = 1461\) on \(237\) residual degrees of freedom.

Table 4: Summary table for model
Term Estimate SE t.val p
(Intercept) -18.1 22.398 -0.808 .42
Age 0.064 0.032 1.975 .049
Weight -0.089 0.062 -1.439 .152
Height -0.06 0.179 -0.334 .739
Neck -0.474 0.236 -2.012 .045
Chest -0.032 0.104 -0.31 .757
Abdomen 0.955 0.090 10.595 < .001
Hip -0.192 0.145 -1.326 .186
Thigh 0.231 0.147 1.571 .117
Knee 0.015 0.248 0.059 .953
Ankle 0.167 0.223 0.751 .454
Biceps 0.192 0.173 1.112 .267
Forearm 0.444 0.200 2.225 .027
Wrist -1.669 0.533 -3.129 .002
Model fit:
\(R^2\) = 0.744, Adjusted \(R^2\) = 0.73, AIC = 1461, Residual DF = 237

(b)

Use the model in (a) to determine whether a Box–Cox transformation is needed or no transformation is needed. Explain your reasoning. If a Box–Cox transformation is needed, explain how the value of \(\lambda\) was selected. If the Box–Cox transformation is needed then use it in the remaining scenarios.


The BoxCox transformation applies the function

\[ \begin{cases} \frac{y^\lambda - 1}{\lambda}, \lambda \neq 0 \\ \mathrm{log}(y), \lambda = 0 \end{cases} \]

to the dependent variable and and performs a profile likelihood test to see if the transformation should be applied. Values of \(\lambda = 0, 0.05, ..., 1.95, 2\) were chosen. For those values the maximum likelihood was found at \(\lambda = 1\), that is with no transformation of the dependent variable. The conclusion was therefore that further analysis be performed with the dependent variable as is.

Figure 6: log-Likelihood plot for Box-Cox transformation of bodyfat data

Figure 6: log-Likelihood plot for Box-Cox transformation of bodyfat data


(c)

Draw four figures showing scatterplots and sample correlation with the percentage of body fat variable included in each figure. Can you see any potential problems with the data through these figures? You can group as follows:

  1. siri, age, weight, height
  2. siri, neck, chest, abdomen, hip
  3. siri, thigh, knee, ankle
  4. siri, biceps, forearm, wrist

Figures 7-10 below show that there is much multicollinearity in the predictor variables. This could pose problems for the model fitting process. Figure 11 shows a correlation plot with predictors arrenged according to hierarchical clustering. We see that there are clusters of variables that are more collinear than others. For example: knee, thigh and hip circumference and weight are more correlated with each other than they are with age, height and forearm circumference.

Figure 7: Scatterplot matrix for siri, age, weight and height

Figure 7: Scatterplot matrix for siri, age, weight and height

Figure 8: Scatterplot matrix for siri, neck, chest, abdomen and hip

Figure 8: Scatterplot matrix for siri, neck, chest, abdomen and hip

Figure 9: Scatterplot matrix for siri, thigh, knee and ankle

Figure 9: Scatterplot matrix for siri, thigh, knee and ankle

Figure 10: Scatterplot matrix for siri, biceps, forearm and wrist

Figure 10: Scatterplot matrix for siri, biceps, forearm and wrist

Figure 11: Correlation plot for the bodyfat data

Figure 11: Correlation plot for the bodyfat data


(d)

Use the diagnostic tools to detect possible problems with the model in (a) and to identify outliers. In particular, use the following tools: (i) plot studentized residuals versus index (case); (ii) plot leverage versus index; (iii) plot Jackknife residuals versus index; (iv) plot a qq-plot of the Jackknife residuals with prediction bounds for each of the ordered Jackknife residual (under the assumption that the error terms, \(\epsilon_i\), are normally distributed). Furthermore, apply a Bonferroni outlier test to the three most extreme Jackknife residuals. Is there a reason to remove any observations from the dataset?


Figure 12 shows residuals, leverages and cook’s distance measures plotted against indices and predicted values. For the Jackknife plots 95% Bonferroni-corrected intervals are added for outlier tests. As can be seen, no points have so high Jackknife residuals as to be considered outliers. Figure 13 below shows qq-plots for standardized, studentized and Jackknife residuals along with 95% confidence bands. All residuals are within the bounds so there is no reason to remove any observations.

Figure 12: Diagnostics plot for bodyfat model. Dashed lines are 95% confidence intervals for kjackknife outlier test with bonferroni correction.

Figure 12: Diagnostics plot for bodyfat model. Dashed lines are 95% confidence intervals for kjackknife outlier test with bonferroni correction.

cap <- "QQ plot for raw (normal) and studentized (t) residuals."
fig_num <- fig_num + 1
cap <- paste0("Figure ", fig_num, ": ", cap)
diag_data %>%
      select(resid, studres, jackknife, label, type) %>%
      mutate(resid = (resid - mean(resid)) / sd(resid)) %>%
      gather(resid_type, residual, resid, studres, jackknife) %>%
      arrange(resid_type, residual) %>%
      group_by(resid_type) %>%
      mutate(obs_q = row_number() / (n() + 1),
             q = ifelse(type == "studres", 
                        qt(obs_q, 64),
                        qnorm(obs_q)),
             qlow = ifelse(type == "studres",
                           qt(qbeta(0.05/2, row_number(), n() - row_number() + 1), 64),
                           qnorm(qbeta(0.05/2, row_number(), n() - row_number() + 1))),
             qupp = ifelse(type == "studres",
                           qt(qbeta(1 - 0.05/2, row_number(), n() - row_number() + 1), 64),
                           qnorm(qbeta(1 - 0.05/2, row_number(), n() - row_number() + 1)))) %>%
      ungroup %>%
      mutate(resid_type = factor(resid_type, levels = c("resid", "studres", "jackknife"),
                                 labels = c("Raw", "Studentized", "Jackknife")),
             alpha = ifelse(type == "Normal", 1, 0.2)) %>%
      ggplot(aes(q, residual, col = type)) +
      geom_abline(intercept = 0, slope = 1, lty = 2, col = "grey50") +
      geom_line(aes(y = qlow), lty = 3, col = "grey30") +
      geom_line(aes(y = qupp), lty = 3, col = "grey30") +
      geom_ribbon(aes(ymin = qlow, ymax = qupp), alpha = 0.1, col = NA) +
      geom_point(aes(alpha = alpha)) +
      geom_text(aes(label = label), size = 5, show.legend = FALSE) +
      scale_color_jama() +
      scale_alpha_continuous(range = c(0.5, 1)) +
      guides(col = guide_legend(title = "Type of observation",
                                title.position = "top",
                                title.hjust = 0.5),
             labels = c("High leverage", "High residual", "Normal"),
             alpha = "none") +
      facet_grid("resid_type", scales = "free") +
      labs(x = "Empirical",
           y = "Theoretical")
Figure 13: QQ plot for raw (normal) and studentized (t) residuals.

Figure 13: QQ plot for raw (normal) and studentized (t) residuals.


(e)

Plot the residuals versus (i) the fitted values; (ii) age; (iii) abdomen circumference; (iv) wrist circumference. Do these plot indicate that the proposed linear model is inadequate? In particular, is the variance constant? Does \(y\) vary non-linearly with these predictors? Also, plot the residuals versus the other predictors without showing the plots. Report if any of these plots indicate that the proposed linear regression model is inadequate.


Figure 14 shows residuals plotted against predicted values, and the predictors age, and abdomen and wrist circumference. There is no sign of heteroskedasticity in the residuals and there does not seem to be a need for quadratic or cubic functions of the predictors. The same analysis was performed for other predictors with the same results.

Figure 14: Residuals versus predicted values, age, and abdomen and waist circumference.

Figure 14: Residuals versus predicted values, age, and abdomen and waist circumference.


(f)

Here we use the dataset with removed observations (if suggested by (d)) and a model with additional quadratic and cubic terms (if suggested by (e)). The task is to find a good model for predicting the percentage of body fat using a subset of the predictors suggested by AIC. You can use the function stepAIC in the MASS package or another selection method based on AIC. Present the final prediction model with a formula.


Following this, an optimal model was found by stepwise predictor choice based on AIC scores using the stepAIC function from the MASS package. Table 5 below shows summary statistics for coefficients and model fit and the model formula can be seen below that.

Table 5: Summary table for model selected by step-wise AIC comparison.
Term Estimate SE t.val p
(Intercept) -21.781 11.749 -1.854 .065
Age 0.065 0.031 2.111 .036
Weight -0.089 0.040 -2.22 .027
Neck -0.46 0.225 -2.048 .042
Abdomen 0.942 0.072 13.092 < .001
Hip -0.194 0.138 -1.404 .162
Thigh 0.293 0.129 2.264 .024
Forearm 0.505 0.187 2.708 .007
Wrist -1.553 0.510 -3.048 .003
Model fit:
\(R^2\) = 0.742, Adjusted \(R^2\) = 0.734, AIC = 1453, Residual DF = 242

Below is the formula for predicting bodyfat based on Siri’s equation using the variables chosen via stepwise AIC comparisons.

\[ \begin{aligned} \textrm{siri} = &- 21.781 \\ &+ 0.065 \cdot age \\ &- 0.089 \cdot weight \\ &- 0.46 \cdot neck \\ &+ 0.942 \cdot abdomen \\ &- 0.194 \cdot hip \\ &+ 0.293 \cdot thigh \\ &+ 0.505 \cdot forearm \\ &- 1.553 \cdot wrist \end{aligned} \]


(g)

Interpret the parameters in the model selected in (f) (except for the intercept).


The coefficients for the model predictors relate to the variable’s effect on a person’s Siri score.

  • age: Each year of age increases a person’s score by 0.065
  • weight: Each lbs of decreases a person’s score by 0.089

The remaining coefficients relate to circumference of bodyparts in centimeters so that each extra centimeter in circumference

  • neck: decreases Siri score by 0.46
  • abdomen: increases Siri score by 0.942
  • hip: decreases Siri score by 0.194
  • thigh: increases Siri score by 0.293
  • forearm: increases Siri score by 0.505
  • wrist: decreases Siri score by 1.553

(h)

Predict the percentage of body fat and compute a 95% confidence interval for an individual with the following predictor values using the model selected in (f).

\(\texttt{age}=40\) years old

\(\texttt{weight}=180\) lbs

\(\texttt{height}=71\) inches

\(\texttt{neck}=38\) cm

\(\texttt{chest}=95\) cm

\(\texttt{abdomen}=92\) cm

\(\texttt{hip}=96\) cm

\(\texttt{thigh}=58\) cm

\(\texttt{knee}=38\) cm

\(\texttt{ankle}=22\) cm

\(\texttt{biceps}=32\) cm

\(\texttt{forearm}=29\) cm

\(\texttt{wrist}=18\) cm


Since we are predicting the Siri score for a specific individual, and not just the overall mean for individuals with those specific traits the confidence interval will be wider. To calculate this we use the variance-covariance matrix for the predictors as well as the residual variance in the overall model. The point-prediction as well as a 95% confidence interval can be seen in table 6.

Table 6: Predicted value and 95% prediction interval
95% Prediction Interval
Prediction Lower Upper
19.101 17.896 20.307

Project 3 (25%)



Summary

Here we analyze data that can be used to predict the presence of the chronic kidney disease. The response variable takes the values ‘has chronic kidney disease’ and ‘doesn’t have chronic kidney disease’.

The dataset contains 203 observations and 12 variables:

  1. ckdmem: there are 2 classes, ckd or notckd
  2. age: in years
  3. blood.pressure: in mm/Hg
  4. blood.glucose.random: in mgs/dl
  5. blood.urea: in mgs/dl
  6. serum.creatinine: in mgs/dl
  7. sodium: in mEq/L
  8. potassium: in mEq/L
  9. hemoglobin: in gms
  10. packed.cell.volume}
  11. white.blood.cell.count: in cells/cmm
  12. red.blood.cell.count: in cells/cmm

The dataset is a available in R as ckd and it is within the package teigen, see

https://www.rdocumentation.org/packages/teigen/versions/2.2.2/topics/ckd

The goal is to predict the probability of not having the chronic kidney disease in the case of an individual with given values for the above predictors. \

The response variable is \[\begin{equation} y_{i} = \left\{\begin{array}{ll} \hbox{1 if the $i$-th individal doesn't have the chronic kidney disease,} \\ \hbox{0 if the $i$-th individal has the chronic kidney disease}, & \\ \end{array} \right. \nonumber \end{equation}\] where \(i=1,...,203\). Here we assume that the \(y_i\)’s are independent Bernoulli random variables, that is, \(y_i \sim \hbox{Bin}(1,\mu_i)\), \(i=1,...,n\). The following generalized linear model is proposed; \[\begin{equation} \eta_i=g(\mu_i) = \log(\mu_i)-\log(1-\mu_i) = \beta_0 + \sum_{j=1}^{p-1} \beta_j x_{ij}, \nonumber \end{equation}\] for \(i=1,...,203\), so \[\begin{equation} \mu_i = g^{-1}(\eta_i) = \frac{\exp\left(\beta_0+\sum_{j=1}^{p-1} \beta_j x_{ij}\right)}{1+\exp\left(\beta_0+\sum_{j=1}^{p-1} \beta_j x_{ij}\right)}. \nonumber \end{equation}\]


(a)

Here we look at logistic regression models for the chronic kidney disease dataset that use only two predictors. Find the two predictor model that gives the lowest AIC. Report a summary of the estimates of the selected model.


First a two-predictor model was found with LASSO regression using the glmnet package. The number of coefficients for each value of the penalizing parameter \(\lambda\) as well as which covariates were kept in the model can be seen in table 7. The optimal two-predictor model was found to be one with hemoglobin and packed.cell.volume.

Table 7: Predictors in LASSO model for differing values of \(\lambda\)
Predictors in model
N. Coef \(\lambda\) age blood.glucose.random blood.pressure hemoglobin packed.cell.volume red.blood.cell.count serum.creatinine sodium white.blood.cell.count
1 0.37 1
2 0.16 1 1
3 0.08 1 1 1
4 0.07 1 1 1 1
5 0.06 1 1 1 1 1
8 0.03 1 1 1 1 1 1 1 1
9 0.01 1 1 1 1 1 1 1 1 1

The model chosen via LASSO was retrained using regular linear regression. Summary statistics for the fitted parameters as well as model fit can be seen in table 8. MacFadden’s \(R^2\) was found by comparing the model fit to the fit of the null model via:

\[ R^2_{MF} = 1 - \frac{log(L_c)}{log(L_{null})} \]

Table 8: Summary table for model chosen via LASSO
Term Estimate SE t.val p
(Intercept) -31.625 5.909 -5.352 < .001
Hemoglobin 1.371 0.423 3.244 .001
Packed.cell.volume 0.332 0.118 2.806 .005
Model fit:
McFadden’s \(R^2\) = 0.814, AIC = 56, Residual DF = 200

As a sanity check the package bestglm was used to perform model selection by exhaustive search. This procedure also chose hemoglobin as one of the two predictors but the second one chosen was serum.creatinine. Summary statistics for the model parameters and model fit can be seen in table 8. This model had a lower \(R^2_{MF}\) and AIC than the LASSO model so it was used for the rest of the analysis.

Table 9: Summary table for model chosen via stepwise AIC
Term Estimate SE t.val p
(Intercept) -15.028 5.395 -2.786 .005
Serum.creatinine -6.17 2.175 -2.836 .005
Hemoglobin 1.717 0.427 4.022 < .001
Model fit:
McFadden’s \(R^2\) = 0.881, AIC = 38, Residual DF = 200

(b)

Draw a normal probability plot of the deviance residuals. Do the deviance residuals appear to follow a normal distribution? Draw the deviance residuals versus all the explanatory variables. Are any outliers found when looking at these plots? The deviance residuals are evaluated by the glm function, with help of the summary function.


Figure 15 below shows a density plot for deviance residuals as well as residuals plotted against each of the two model predictors. The density of the residuals seems to almost be normally distributed but with a sharper peak and longer tails. There are two cases with high residuals. Both of them are positive ckd cases but both have high hemoglobin and low serum.creatinine, values that seem to be more common among cases without ckd.

Figure 15: Top: Density plot of deviance residuals. Bottom: Deviance residuals plotted against predictor variables.

Figure 15: Top: Density plot of deviance residuals. Bottom: Deviance residuals plotted against predictor variables.


(c)

Interpret the parameters in the model selected in (a) (except for the intercept).


  • hemoglobin: For each gms the odds of not having CKD are multiplied by 5.568, thereby decreasing the risk of CKD.
  • serum.creatinine: For each mgs/dl the odds of having CKD are multiplied by 0.002 thereby increasing the risk of CKD.

(d)

What is the probability of not having the chronic kidney disease in the case of an individual that has the following explanatory variables;

  • \(\texttt{age}=54\) years old,
  • \(\texttt{blood.pressure}=83\) mm/Hg,
  • \(\texttt{blood.glucose.random}=135\) mgs/dl,
  • \(\texttt{blood.urea}= 15.3\) mgs/dl,
  • \(\texttt{serum.creatinine}=0.21\) mgs/dl,
  • \(\texttt{sodium}=134\) mEq/L,
  • \(\texttt{potassium}=4.6\) mEq/L,
  • \(\texttt{hemoglobin}=12.9\) gms,
  • \(\texttt{packed.cell.volume}=42\),
  • \(\texttt{white.blood.cell.count}=6310\) cells/cmm,
  • \(\texttt{red.blood.cell.count}=5.1\) cells/cmm.

The probability of not having chronic kidney disease, as predicted by the fitted model, is 99.71%


(f)

Plot the individals that don’t have the chronic kidney disease with blue dots and the individuals that have the chronic kidney disease with red dots on a graph with the first predictor on the x-axis and the second predictor on the y-axis. Plot a line on this graph that is such that the estimated probability of having the chronic kidney disease is equal to \(0.5\) along the line. Explain what this graph is showing.


Figure 16 shows the linear separation between cases having chronic kidney disease and those without based on hemoglobin and serum.creatinine. Individuals that land in the grey part of the plot are predicted to have a greater than \(50\%\) chance of chronid kidney disease and those in the orange part have a less than \(50\%\) chance. The figure shows a clear linear separation between the classes.

Figure 16: Linear separation plot of chronic kidney disease.

Figure 16: Linear separation plot of chronic kidney disease.