Answer To: PROG8430 – Data Analysis, Modeling and Algorithms Assignment 5 Classification DUE BEFORE 10PM APRIL...
Naveen answered on Apr 15 2021
# Installing required packages
install.packages('dplyr')
install.packages('pROC')
install.packages('MASS')
install.packages('klaR')
# Calling libraries
library(dplyr)
library(pROC)
library(MASS)
library(klaR)
# Reading data to R
Tumor <- read.csv('tumor21w-ky4vufl1-got3omwl.csv')
# Checking the data
head(Tumor)
# Structure of the data
str(Tumor)
# 1.1
# Changing the column names as interpretable
names(Tumor) <- c('Output','Age','Gender','Bone','Marrow','Lung','Pleura',
'Liver','Brain','Skin','Neck','Supra','Axil','Media')
# Changing the data types of variables
Tumor$Output <- Tumor$Output-1
Tumor$Age <- Tumor$Age-2
Tumor$Gender <- Tumor$Gender-1
Tumor$Bone <- Tumor$Bone-1
Tumor$Marrow <- Tumor$Marrow-1
Tumor$Lung <- Tumor$Lung-1
Tumor$Pleura <- Tumor$Pleura-1
Tumor$Liver <- Tumor$Liver-1
Tumor$Brain <- Tumor$Brain-1
Tumor$Skin <- Tumor$Skin-1
Tumor$Neck <- Tumor$Neck-1
Tumor$Supra <- Tumor$Supra-1
Tumor$Axil <- Tumor$Axil-1
Tumor$Media <- Tumor$Media-1
# 2.1
# Correlation matrix
cor(Tumor, method = "spearman")
#2.2
# Knowing the best predictors using contingency analysis
chisq.test(Tumor$Output,Tumor$Age)
chisq.test(Tumor$Output,Tumor$Gender)
chisq.test(Tumor$Output,Tumor$Bone)
chisq.test(Tumor$Output,Tumor$Marrow)
chisq.test(Tumor$Output,Tumor$Lung)
chisq.test(Tumor$Output,Tumor$Pleura)
chisq.test(Tumor$Output,Tumor$Liver)
chisq.test(Tumor$Output,Tumor$Brain)
chisq.test(Tumor$Output,Tumor$Skin)
chisq.test(Tumor$Output,Tumor$Neck)
chisq.test(Tumor$Output,Tumor$Supra)
chisq.test(Tumor$Output,Tumor$Axil)
chisq.test(Tumor$Output,Tumor$Media)
#3.1
# Forward regression model
Logit_model <- glm(formula=Output~.,data=Tumor,family = 'binomial',na.action = na.omit)
step(Logit_model,direction = 'forward')
#3.2
# Model1
Model1 <- glm(formula = Output~Gender+Bone+Skin,data=Tumor,family = 'binomial')
summary(Model1)
# Model2
Model2 <- glm(formula = Output~Neck+Media+Axil, data=Tumor)
summary(Model2)
# 4.1
# Making prediction on model1 and confusion matrix
# Predicting for the model1
pred1 <- predict(Model1, type="response")
# Converting probabilities as values
Class_pre <- ifelse(pred1 >...