Docsity

Predicting Cardiovascular Disease Risk: A Logistic Regression Analysis, Summaries of Computer Science

Toggle sidebar
bg1
Regression Models Prediction of the Risk of Cardiovasular
Heart Disease(CHD)
Introduction and objective
Cardiovascular diseases is one the leading cause of death in in the United States and other
developed countries. The early prognosis of cardiovascular diseases can aid in making decisions
on lifestyle changes in high risk patients and in turn reduce the complications. Framingham
study is an dataset with the follow-up 10-year risk of future coronary heart disease (CHD). It
includes over 4,000 records and 15 attributes of patients’ information.
The objective of this logistic regression intends to pinpoint the most relevant/risk factors of
heart disease as well as predict the overall risk using regression machine learning. The method
of checking assumption of linear regression is readily available. Here I would like to explore
how to check the assumption of logistic regression. Feature selection using stepwise selection or
Lasso regression to pinpoint the relevant risk factors
Data description
The dataset is publically available on the Kaggle website, and it is from an ongoing ongoing
cardiovascular study on residents of the town of Framingham, Massachusetts. The
classification goal is to predict whether the patient has 10-year risk of future coronary heart
disease (CHD).
male: male or female;
age: age of the patient;
currentSmoker: whether or not the patient is a current smoker (Nominal)
cigsPerDay: the number of cigarettes that the person smoked on average in one day.
BPMeds: whether or not the patient was on blood pressure medication (Nominal)
prevalentStroke: whether or not the patient had previously had a stroke (Nominal)
prevalentHyp: whether or not the patient was hypertensive (Nominal)
diabetes: whether or not the patient had diabetes (Nominal)
totChol: total cholesterol level (Continuous)
sysBP: systolic blood pressure (Continuous)
diaBP: diastolic blood pressure (Continuous)
BMI: Body Mass Index (Continuous)
heartRate: heart rate
glucose: glucose level (Continuous)
10 year risk of coronary heart disease CHD (binary: “1”, means “Yes”, “0” means “No”)
pf3
pf4
pf5

Partial preview of the text

Download Predicting Cardiovascular Disease Risk: A Logistic Regression Analysis and more Summaries Computer Science in PDF only on Docsity!

Regression Models Prediction of the Risk of Cardiovasular

Heart Disease(CHD)

Introduction and objective

Cardiovascular diseases is one the leading cause of death in in the United States and other developed countries. The early prognosis of cardiovascular diseases can aid in making decisions on lifestyle changes in high risk patients and in turn reduce the complications. Framingham study is an dataset with the follow-up 10-year risk of future coronary heart disease (CHD). It includes over 4,000 records and 15 attributes of patients’ information. The objective of this logistic regression intends to pinpoint the most relevant/risk factors of heart disease as well as predict the overall risk using regression machine learning. The method of checking assumption of linear regression is readily available. Here I would like to explore how to check the assumption of logistic regression. Feature selection using stepwise selection or Lasso regression to pinpoint the relevant risk factors

Data description

The dataset is publically available on the Kaggle website, and it is from an ongoing ongoing cardiovascular study on residents of the town of Framingham, Massachusetts. The classification goal is to predict whether the patient has 10-year risk of future coronary heart disease (CHD).  male: male or female;  age: age of the patient;  currentSmoker: whether or not the patient is a current smoker (Nominal) cigsPerDay: the number of cigarettes that the person smoked on average in one day.  BPMeds: whether or not the patient was on blood pressure medication (Nominal) prevalentStroke: whether or not the patient had previously had a stroke (Nominal) prevalentHyp: whether or not the patient was hypertensive (Nominal)  diabetes: whether or not the patient had diabetes (Nominal)  totChol: total cholesterol level (Continuous)  sysBP: systolic blood pressure (Continuous)  diaBP: diastolic blood pressure (Continuous)  BMI: Body Mass Index (Continuous)  heartRate: heart rate  glucose: glucose level (Continuous)  10 year risk of coronary heart disease CHD (binary: “1”, means “Yes”, “0” means “No”)

Logistic Regression to predict the CHD Outcome

Within the broad framework of General Linear Models (GLM), Logistic regression conducts binary classification by generating class probabilities.

  • STEP 1: Load the Libraries
  • STEP 2: Data Preparation and Exploratory data analysis Import data
  • Examine if any missing value
  • Convert the outcome as factor and others into character
  • Visualization the Distribution by histogram (countious variables)
  • Noticed the Non-normality of cigPerDay:Transform Feature of cigsPeday
  • library bestNormalize to suggest which transform is the best
  • Visualization the association of outcome between variables no difference in Heart rate, I will drop it out from this analysis
  • Visualization the association of outcome between factor variables prevalentStroke as the outcome of this event is rare
  • Visualization the correlations with matrix for numerical variables Noticed the diaBP and sysBP strong correlation Final dataset after description exploration: drop out heartRate, prevalentStroke and transform cigPerDay
  • Step 4 Building a logistic regression model The logistic regression method several key assumptions: 1.The outcome is a binary or dichotomous variable like yes vs no, positive vs negative, 1 vs 0. 2.There is a linearity of independent variables and log odds of the outcome variables. logit function is logodd = log(probability/1-probability), where p is the probabilities of the outcome 3.There is no influential values (extreme values or outliers) in the continuous predictors 4.There is no high intercorrelations (i.e. multicollinearity) among the predictors. 5.It requires the observations to be independent of each other. So, the observations should not come from repeated measurements.

Logistic regression diagnostics

Assumption 1 — Linearity of independent variables and log-odds

  • How to check: Visualize by scatter plot
  • Verify by boxTidell for linearity Results: The smoothed scatter plots show that variables are all quite linearly associated with the CHD outcome in logit scale. Sometime the visualization is not straight forward, we can use boxTidell to test. Here is the example of diaBP

Assumption 5 — Sufficiently large sample size

One rule of thumb is that there should be at least 10 observations with the least frequent outcome for each independent variable. We can check this by retrieving the value counts for each variable.(mainly for categorical). prevalentStroke will be leave out from analysis

Check out if significance of Interaction term

Creating a Regression Model using caret (Classification and Regression

Training) Package

Feature Selection via AIC stepwise and Lasso regression

Stepwise logistice regression

  • The stepwise logistic regression can be easily computed using the R function stepAIC() available in the MASS package. It performs model selection by AIC. It has an option called direction, which can have the following values: “both”, “forward”, “backward”
  • stepwise selection reduced the complexity of the model without compromising its accuracy x (Intercept) -2. male1 0. age 0. currentSmoker1 -0. cigsPerDay 0. BPMeds1 0. prevalentHyp1 0. sysBP 0. glucose 0. So, with the stepwise selection of the predictors are down to 8 parameters(male, age, sysBP, glucose,cigperday, bpmed,prestroke, prehypertension) but accuracy is the same.

Fit the lasso Regression Model

  • -we’ll use the glmnet() function to fit the lasso regression model and specify alpha=
  • -The R function model.matrix() helps to create the matrix of predictors and also automatically converts categorical predictors to appropriate dummy variables, which is required for the glmnet() function. glmnet() glmnet(x, y, family = "binomial", alpha = 1, lambda = NULL) for computing penalized logistic regression
  • x: matrix of predictor variables
  • y: the response or outcome variable, which is a binary variable.
  • family: the response type. Use “binomial” for a binary outcome variable
  • alpha: the elasticnet mixing parameter. Allowed values include: – “1”: for lasso regression – “0”: for ridge regression – a value between 0 and 1 (say 0.3) for elastic net regression. – lamba: a numeric value defining the amount of shrinkage. Should be specify by analyst. The best lambda for your data, can be defined as the lambda that minimize the cross-validation prediction error rate. This can be determined automatically using the function cv.glmnet(). -To determine what value to use for lambda, we’ll perform k-fold cross-validation and identify the lambda value that produces the lowest test mean squared error (MSE) The plot displays the cross-validation error according to the log of lambda.Generally, the purpose of regularization is to balance accuracy and simplicity. This means, a model with the smallest number of predictors that also gives a good accuracy. To this end, the function cv.glmnet() finds also the value of lambda that gives the simplest model but also lies within one standard error of the optimal value of lambda. This value is called lambda.1se. Fit the final model on the training data with the minimal lamda and 1se lambda Demonstration of lasso feature selection and return a final model Curves: the predictor coefficients as the penalty term increases. Numbers on top: The number of variables in the regression model we see here is the curves collapsing to zero as the lambda increases. Dashed lines indicate the lambda.min and lambda.1se values from cross-validation as before. As the lambda increase, the penalty level increase, more element are left out the model b/O coefficient importance

Comparison of glm model and the lasso model

Data here show the slightly decreased Accuracy and Kappa in the Lasso Regression. Usually with the simple model treads out with decreased prediction performance

Interpretation of the predictors’ risk

14 x 2 Matrix of class "dgeMatrix"

coef OR

age 0.38823577 1.

male1 0.25650296 1.

sysBP 0.22775770 1.

prevalentHyp1 0.10632948 1.

glucose 0.10524958 1.

cigsPerDay 0.08968899 1.

BPMeds1 0.04821041 1.