---
title: "Pooling and Selection of Cox Regression Models"
author: "Martijn W Heymans"
date: "`r Sys.Date()`"
output:
  bookdown::html_document2
vignette: >
  %\VignetteIndexEntry{psfmi_CoxModels}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

# Introduction

With the `psfmi` package you can pool Cox regression models by using  
the following pooling methods: RR (Rubin's Rules), D1, D2, and MPR 
(Median R Rule). You can also use forward or backward selection from
the pooled model. This vignette show you examples of how to apply these 
procedures.

# Examples 

* [Cox regression]
    + [Pooling without BS and method D1] 
    + [Pooling with FS and method MPR] 
    + [Pooling with FS including interaction terms and method D1]
    + [Pooling with BS including spline coefficients and method D1]
    + [Pooling with FS including spline coefficients and method MPR]

## Pooling without BS and method D1

If you set p.crit at 1 than no selection of variables takes place. 
Either using direction = "FW" or direction = "BW" will produce the same
result.

```{r}

  library(psfmi)
  pool_coxr <- psfmi_coxr(data=lbpmicox, nimp=5, impvar="Impnr", time="Time", status="Status",
  predictors=c("Duration", "Radiation", "Onset", "Function", "Age",
  "Previous", "Tampascale", "JobControl", "JobDemand", "Social"), p.crit=1,
  cat.predictors=c("Expect_cat"), method="D1", direction = "BW")
  
  pool_coxr$RR_model
  
```  

Back to [Examples]

## Pooling with FS and method MPR

```{r, eval=TRUE}

  library(psfmi)
  pool_coxr <- psfmi_coxr(data=lbpmicox, nimp=5, impvar="Impnr", time="Time", status="Status",
  predictors=c("Duration", "Radiation", "Onset", "Function", "Age",
  "Previous", "Tampascale"), p.crit=0.05,
  cat.predictors=c("Expect_cat"), method="MPR", direction = "FW")
  
  pool_coxr$RR_model_final
  
  pool_coxr$predictors_in
  
```  

Back to [Examples]

## Pooling with FS including interaction terms and method D1

Pooling Cox regression models over 5 imputed datasets with backward selection
using a p-value of 0.05 and as method D2 including interaction terms with 
a categorical predictor and forcing the predictor Tampascale in the models 
during backward selection.

```{r}

  library(psfmi)
  pool_coxr <- psfmi_coxr(data=lbpmicox, nimp=5, impvar="Impnr", time="Time", status="Status",
  predictors=c("Duration", "Previous",  "Radiation", "Onset",
  "Function", "Tampascale" ), p.crit=0.05, cat.predictors=c("Satisfaction",
  "Expect_cat"), int.predictors=c("Tampascale:Radiation",
  "Expect_cat:Tampascale"), keep.predictors = "Tampascale", method="D1", direction = "FW")
  
  pool_coxr$RR_model_final
  
  pool_coxr$predictors_in
  
```  

Back to [Examples]

## Pooling with BS including spline coefficients and method D1

Pooling Cox regression models over 5 imputed datasets with backward selection
using a p-value of 0.05 and as method D1 including a restricted cubic spline 
predictor and forcing Tampascale in the models during backward selection.

```{r}

  library(psfmi)
  pool_coxr <- psfmi_coxr(data=lbpmicox, nimp=5, impvar="Impnr", time="Time", status="Status",
  predictors=c("Duration", "Previous",  "Radiation", "Onset", "Function"), 
  p.crit=0.05, cat.predictors=c("Satisfaction"), spline.predictors=c("Tampascale"),
  int.predictors=c("Tampascale:Radiation"), keep.predictors = "Tampascale", 
  nknots=3, method="D1", direction = "BW")
  
  pool_coxr$RR_model_final
  
  pool_coxr$predictors_out
  
```  

Back to [Examples]

## Pooling with FS including spline coefficients and method MPR

Pooling Cox regression models over 5 imputed datasets with backward selection
using a p-value of 0.05 and as method D1 including a restricted cubic spline 
predictor and forcing Tampascale in the models during backward selection.

```{r}

  library(psfmi)
  pool_coxr <- psfmi_coxr(data=lbpmicox, nimp=5, impvar="Impnr", time="Time", status="Status",
  predictors=c("Duration", "Previous",  "Radiation", "Onset", "Function"), 
  p.crit=0.05, cat.predictors=c("Satisfaction"), spline.predictors=c("Tampascale"),
  int.predictors=c("Tampascale:Radiation"), keep.predictors = "Tampascale", 
  nknots=3, method="D1", direction = "MPR")
  
  pool_coxr$RR_model_final
  
  pool_coxr$predictors_in
  
```  

Back to [Examples]