---
title: "Additional exercise 12"
author: "Per August Jarval Moen"
date: "2024"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

We begin by loading the data:

```{r}
link="http://www.uio.no/studier/emner/matnat/math/STK3100/data/lowbirthweight.txt"
data=read.table(link,header=T)
data$low = as.factor(data$low)
data$smoke = as.factor(data$smoke)
data$ht = as.factor(data$ht)
data$ui = as.factor(data$ui)
data$ftv = as.factor(data$ftv)
data$ptl = as.factor(data$ptl)
data$race = as.factor(data$race)
```

## a

We fit a logistic regression model using low as response and the other eight variables given above as covariates:

```{r}
fullmodel = glm(low ~age + lwt + race + smoke+ht + ui + ftv+ptl, 
                family = binomial(link="logit"), data = data)
summary(fullmodel)
```

## b

We use the tip and use the \textbf{drop1} function to drop a single term at a time. By specifying "Chisq" we use the

```{r}
drop1(fullmodel,test="Chisq")
```

From the output, we should remove ftv. Continuing:

```{r}
newmodel = glm(low ~age + lwt + race + smoke+ht + ui +ptl, 
               family = binomial(link="logit"), data = data)
drop1(newmodel,test="Chisq")
```

From the new model we should remove age:

```{r}
newmodel = glm(low ~ lwt + race + smoke+ht + ui +ptl, 
               family = binomial(link="logit"), data = data)
drop1(newmodel,test="Chisq")
```

Finally we remove ui:

```{r}
newmodel = glm(low ~ lwt + race + smoke+ht  +ptl, 
               family = binomial(link="logit"), data = data)
drop1(newmodel,test="Chisq")
summary(newmodel)
```

After removing ui, all covariates are significant.

The final model is interpreted as such:

-   The odds ratio of low birth weight associated with a unit increase in the mother's weight is estimated to be $\exp(-0.0165) = 0.983$, keeping the other covariates fixed. That is, an increase of one pound in the mother's weight reduces the odds of low birth weight by approximately $2\%$.

-   The odds ratio of low birth weight of babies with white mothers versus black mothers is estimated to be $\exp(-1.25) = 0.29$, keeping the other covariates fixed. That is, the odds of a white mother having a baby with low birth weight is approximately $29\%$ of the odds for a black mother with the same characteristics.

-   The odds ratio of low birth weight of babies with mothers of race "other" versus black mothers is estimated to be $\exp(-0.39) = 0.68$, keeping the other covariates fixed. That is, the odds of a mother with race "other" having a baby with low birth weight is approximately $68\%$ of the odds for a black mother with the same characteristics.

-   The remaining coefficients are interpreted similarly.
