# Introduction

The aim of this study is to investigate whether an association exists between serum bilirubin with sex, age, treatment and standardised blood clotting time.

# Methods

## Statistical Analysis

* We are going to used the pbc data set from the survival library. 

* Continuous variables are presented as mean and standard deviation while categorical variables as counts and percentages. Differences in serum bilirubin, age and standardised blood clotting time between males and females were analyzed by the unpaired Student's t tests for continuous variables. To investigate the association between serum bilirubin with sex, age, treatment and standardised blood clotting time a linear regression was performed. A p-value <0.05 was considered statistically significant and no correction for multiple testing was performed.

```{r, echo=TRUE, message=FALSE, warning=FALSE}
library(lattice)
library(knitr)
library(survival)
library(effects)
library(arsenal)
```

```{r, results='asis', echo=TRUE, message=FALSE, warning=FALSE}
R.Version()$version.string
packageVersion("lattice")
packageVersion("knitr")
packageVersion("survival")
packageVersion("effects")
packageVersion("arsenal")
```

# Results

Table 1 presents descriptive statistics with the results of the t-test analysis.

```{r, echo=FALSE, include=TRUE, results='asis'}
pbc$trt <- factor(pbc$trt, levels = c(1, 2, NA), 
                  labels = c("D-penicillmain", "placebo"))
tab1 <- tableby(sex ~ bili + age + protime, data = pbc)
kable(summary(tab1), caption = "Table 1: Descriptive statistics with test")
```

Figure 1 represents the desnity plots of serum bilirubin per gender.

```{r, echo=FALSE, include=TRUE, fig.cap="Figure 1: Density plots of serum bilirubin per gender"}
pbc_male_bili <- pbc$bili[pbc$sex == "m"]
pbc_female_bili <- pbc$bili[pbc$sex == "f"]
plot(density(pbc_male_bili), col = rgb(0,0,1,0.5), ylim = c(0,0.40), main = "Density plots", xlab = "bili", ylab = "")
polygon(density(pbc_male_bili), col = rgb(0,0,1,0.5), border = "blue")
lines(density(pbc_female_bili), col = rgb(1,0,0,0.5))
polygon(density(pbc_female_bili), col = rgb(1,0,0,0.5), border = "red")
legend(20,0.03, c("male", "female"), 
       col = c(rgb(0,0,1,0.5), rgb(1,0,0,0.5)), lty = 1)
```


## Regression analysis {.tabset .tabset-fade}

The results of the regression analysis are presented in Table 2. Since we expect that the effect of sex, treatment and standardised blood clotting time on serum bilirubin would be different per age range, we assumed two models. One model includes only main effects and the other model includes an interaction term of age with all the other variables.

### Linear regression without interactions
```{r, echo=FALSE}
fm1 <- lm(bili ~ sex + age + trt + protime, data = pbc)
tab <- summary(fm1)$coefficients
kable(tab[, c(1,2,4)], dig = 4, caption = "Table 2: The coefficients, standard errors and p-values")
```

### Linear regression with interactions
```{r, echo=FALSE}
fm2 <- lm(bili ~ age * (sex + trt + protime), data = pbc)
tab <- summary(fm2)$coefficients
kable(tab[, c(1,2,4)], dig = 4, caption = "Table 2: The coefficients, standard errors and p-values")
```

## Effect plots {.tabset .tabset-fade}

The effect plots are based on the model with interaction terms.

### Serum bilirubin with age
```{r, echo=TRUE, message=FALSE, warning=FALSE}
plot(effect("age", fm2))
```

### Serum bilirubin with treatment
```{r, echo=TRUE, message=FALSE, warning=FALSE}
plot(effect("trt", fm2))
```

### Serum bilirubin with standardised blood clotting time
```{r, echo=TRUE, message=FALSE, warning=FALSE}
plot(effect("protime", fm2))
```

### Serum bilirubin with standardised blood clotting time and sex
```{r, echo=TRUE, message=FALSE, warning=FALSE}
plot(effect(c("protime", "sex"), fm2))
```




# Conclusions

We may conclude that:

* A strong clinical association was found between serum cholesterol and standardised blood clotting time
* A weak association was found between sex and serum bilirubin
  * The same holds for age and treatment


Strengths and weaknesses of our study are:

1. Small sample size


