This is the third part of a series surrounding survival analysis. For part 1, click here. For part 2, click here. This particular post follows the final part of fitting a Cox proportional hazards model; residual checking and model validation. Solutions can be found for these exercises here. Exercise 1 Load the survival and survminer libraries. Build our […]

## Survival Analysis: Solutions (Part 3)

Below are the solutions to these exercises on Survival Analysis Part-3. ############### # # # Exercise 1 # # # ############### library(survival) library(survminer) data(“lung”) lung$status <- as.factor(lung$status) # 1 Censored 2 Dead final_model <- coxph(Surv(time, status == 2) ~ sex + ph.karno + wt.loss + sex*ph.karno, data = lung) ############### # # # Exercise 2 […]

## Introduction to Statistical Testing and Sampling Solutions (Part 2)

Below are the solutions to these exercises on Statistical testing and sampling ############### # # # Exercise 1 # # # ############### set.seed(123) lifespans <- data.frame(index = 1:200, lifespans = rgamma(200, shape = 2, rate = 1.2)*50) library(ggplot2) library(dplyr) lifespans %>% ggplot(aes(x = lifespans)) + stat_density() ############### # # # Exercise 2 # # # […]

## Introduction to Statistical Testing and Sampling Exercises (Part 2)

This is part 2 in a series on statistical theory using R. For part 1, go here. This tutorial concerns itself with MLE calculations and bootstrapping. Answers to the exercises are available here. Exercise 1 Set a seed to 123 and create the following dataframe: lifespans = data.frame(index = 1:200, lifespans = rgamma(200, shape = 2, […]

## Introduction to Statistical Testing and Sampling: Solutions (Part 1)

Below are the solutions to these exercises on Building a Neural Network. ############### # # # Exercise 1 # # # ############### set.seed(123) normal_draws <- rnorm(1000, mean = 10, sd = 2) hist(normal_draws) ############### # # # Exercise 2 # # # ############### qqnorm(normal_draws) qqline(normal_draws) ############### # # # Exercise 3 # # # ############### […]

## Introduction to Statistical Testing and Sampling: Exercises (Part 1)

For a majority of users, the primary use of R is for statistical testing and analysis. At the heart of this, within the frequentist world, lies hypothesis testing and distribution sampling. The skill in conducting this sort of work is being able to identify an appropriate distribution on which to model the question and test […]

## Predicting Housing Prices with Linear Regression Solutions

Below are the solutions to these exercises on Regression Modeling with the Boston Housing dataset. ############### # # # Exercise 1 # # # ############### library(mlbench) library(dplyr) library(ggplot2) library(reshape2) data(“BostonHousing”) housing <- BostonHousing str(housing) ## ‘data.frame’: 506 obs. of 14 variables: ## $ crim : num 0.00632 0.02731 0.02729 0.03237 0.06905 … ## $ zn […]

## Predicting Housing Prices with Linear Regression Exercises

Regression techniques are a crucial skill in any data scientist or statisticians toolkit. It is even crucial for people who are unfamiliar with regression modeling. It is a nice way to introduce yourself to the topic through a simple linear model. A linear model is an explanation of how a continuous response variable behaves, dependent […]

## Survival Analysis: Solutions (Part 2)

Below are the solutions to these exercises on Survival Analysis Part-2. ############### # # # Exercise 1 # # # ############### library(survival) library(survminer) data(“lung”) lung$status <- as.factor(lung$status) # 1 Censored 2 Dead lung$wtloss.bin <- cut(lung$wt.loss, breaks = 15) sex.obj <- survfit(Surv(time, status == 2) ~ sex, data = lung) wt.obj <- survfit(Surv(time, status == 2) […]

## Survival Analysis: Exercises (Part 2)

This is the second part of a series on conducting Survival Analysis in R using Survival and Survminer. It is advised to first complete the first set of exercises (here) before attempting these, as there is a direct continuation of knowledge. The second part of this series focuses on more complex and insightful methods through […]