```{r include = FALSE}
knitr::opts_chunk$set(include = params$answers,
                      comment="")

library(ggplot2)
library(dplyr)
library(GLMsData)
```

---

In this practical, we will compare the estimates of the linear and the 
generalized linear model when the dependent variable is a 
dichotomous variable. The data set for this practical is
`lungcap` from the package `GLMsData`. To load the data into workspace you need 
to use the function `data()`.

```{r}

```

# Lungcap

The data set `lungcap` contains data on four characteristics of smokers and 
non-smokers (check its help page for details). In this exercise, we will use 
these characteristics to predict the probability of being a smoker.  

a. Display the summary of the data, and check the variables for skew.

```{r}

```

b. Display a frequency table for the variable `Smoke` to see how many smokers 
and non-smokers there are in the data. Use the function `xtabs()`.
 
```{r}

```

## Linear model

We will start again by treating the variable `Smoke` as continuous with a 
distribution from the Gaussian family.

a. Fit the generalized linear model `Smoke ~ Age` with the argument 
`family = "gaussian"`, and display and interpret its summary.

```{r}

```

b. Display a scatterplot with `Age` on the x-axis and `Smoke` on the y-axis, and 
add the linear regression line regression line.

```{r}

```

c. Display and interpret the diagnostic residual plots for the linear model.

```{r fig.asp = 1}

```

## Logistic regression model

We will now treat `Smoke` as a dichotomous variable with `glm()`.

a. Fit the logistic regression model `Smoke ~ Age`, and display and interpret 
its summary.

```{r}

```

b. Display a scatterplot with `Age` on the x-axis and `Smoke` on the y-axis. Add 
a line representing the probability of smoking predicted by the logistic 
regression model, and compare (the range of) the predicted values to those of 
the linear model.

```{r}
lungcap %>% 
  mutate(pred = ## add code here ) %>% 
  ggplot() + 
  ## add code here 
  ## add code here
  theme_minimal()
```

## Model selection

a. Find the most parsimonious main-effects logistic regression model when all 
variables in `lungcap` are allowed to enter the model as predictors. Use the `step()`
function.

```{r}

```


b. Find the most parsimonious logistic regression model allowing  all pairwise 
interactions between the predictors to enter the model.

```{r}

```

c. Which model is the most parsimonious, the one with or the one without the pairwise interactions?

---

End of practical
