#Loading packages
library(readxl)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.7 ✔ dplyr 1.0.9
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(janitor)
##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
#Importing data
depression <- read_excel("~/Library/CloudStorage/OneDrive-AlexandriaUniversity/Depression/depression.xlsx") %>% clean_names() %>%
mutate_if(is.character, ~as.factor(as.character(.)))
str(depression)
## tibble [1,301 × 36] (S3: tbl_df/tbl/data.frame)
## $ a : Factor w/ 1293 levels "1/17/2021 1:28:57",..: 1167 1170 1168 1169 1171 1172 1173 1174 1175 1176 ...
## $ year : num [1:1301] 4 4 4 4 2 4 6 2 6 4 ...
## $ university : Factor w/ 6 levels "Ain Shams University Faculty of Medicine",..: 3 3 3 3 3 3 3 3 3 3 ...
## $ sex : Factor w/ 2 levels "Female","Male": 2 2 2 1 1 1 1 2 1 1 ...
## $ academic_performance : Factor w/ 3 levels "Negative effect",..: 3 3 2 1 2 3 1 1 2 3 ...
## $ relationship_with_your_family: Factor w/ 3 levels "Negative effect",..: 3 3 3 3 2 1 1 2 3 1 ...
## $ social_relationships : Factor w/ 5 levels "Negative","Negative effect",..: 1 1 4 1 4 1 1 1 1 1 ...
## $ eating_habits : Factor w/ 2 levels "No","Yes": 1 1 2 2 1 1 1 1 2 1 ...
## $ eating_habits_how : Factor w/ 8 levels "both amount and type",..: 7 7 8 8 NA 7 NA 7 1 NA ...
## $ gained_weight : Factor w/ 2 levels "No","Yes": 2 2 1 2 1 2 NA 1 2 2 ...
## $ smoking_habits : Factor w/ 8 levels "I am a non-smoker",..: 1 1 1 6 1 1 1 1 1 1 ...
## $ sleeping_pattern : Factor w/ 5 levels "disturbed sleeping pattern",..: 1 4 1 1 1 1 5 1 1 4 ...
## $ trouble_sleeping : Factor w/ 3 levels "Maybe","No","Yes": 1 2 3 3 3 1 2 1 1 2 ...
## $ sleep_quality : Factor w/ 4 levels "Fairly bad","Fairly good",..: 1 2 1 1 1 2 4 1 2 4 ...
## $ physical_activity : Factor w/ 6 levels "I have been less physically active.",..: 3 4 3 3 5 3 3 3 3 3 ...
## $ x1 : num [1:1301] 0 2 1 2 2 1 2 2 3 0 ...
## $ x2 : num [1:1301] 1 1 1 0 2 1 1 0 2 0 ...
## $ x3 : num [1:1301] 2 2 1 3 2 1 2 3 1 0 ...
## $ x4 : num [1:1301] 1 0 1 3 1 0 1 2 0 0 ...
## $ x5 : num [1:1301] 2 1 1 2 1 1 3 3 1 2 ...
## $ x6 : num [1:1301] 3 1 1 1 2 1 2 1 2 2 ...
## $ x7 : num [1:1301] 0 1 2 1 1 0 0 1 1 0 ...
## $ x8 : num [1:1301] 2 0 2 1 2 1 1 1 1 1 ...
## $ x9 : num [1:1301] 0 1 1 3 2 0 1 2 1 1 ...
## $ x10 : num [1:1301] 0 1 1 1 2 0 3 3 3 2 ...
## $ x11 : num [1:1301] 1 1 1 1 2 1 2 3 3 1 ...
## $ x12 : num [1:1301] 0 2 1 3 2 1 3 3 2 0 ...
## $ x13 : num [1:1301] 2 0 1 2 2 1 1 3 3 0 ...
## $ x14 : num [1:1301] 0 1 1 0 1 0 2 1 0 1 ...
## $ x15 : num [1:1301] 0 1 1 2 2 0 1 1 1 0 ...
## $ x16 : num [1:1301] 0 1 1 2 2 0 0 2 3 2 ...
## $ x17 : num [1:1301] 0 1 1 1 2 2 1 3 0 0 ...
## $ x18 : num [1:1301] 3 2 1 3 2 1 2 1 3 1 ...
## $ x19 : num [1:1301] 2 1 1 2 3 0 1 2 0 0 ...
## $ x20 : num [1:1301] 0 1 1 1 3 0 1 2 0 0 ...
## $ x21 : num [1:1301] 0 0 1 1 2 0 2 3 0 0 ...
#Preparing data
depression$year <- depression$year %>% as.factor()
levels(depression$physical_activity)
## [1] "I have been less physically active."
## [2] "I have been more physically active."
## [3] "Less physical activity"
## [4] "More physical activity"
## [5] "No change"
## [6] "There has not been any change in my physical activity."
depression$physical_activity <- factor(depression$physical_activity,
levels = c("I have been less physically active.","I have been more physically active.",
"Less physical activity", "More physical activity" , "No change" ,
"There has not been any change in my physical activity." ) ,
labels = c("Less physical activity","More physical activity",
"Less physical activity", "More physical activity" , "No change" ,
"No change" ))
levels(depression$physical_activity)
## [1] "Less physical activity" "More physical activity" "No change"
depression$sleeping_pattern <- factor(depression$sleeping_pattern,
levels = c( "disturbed sleeping pattern" ,"Disturbed sleeping pattern", "Less sleeping hours" ,
"More sleeping hours" , "No change" ) ,
labels = c("Disturbed sleeping pattern" ,"Disturbed sleeping pattern", "Less sleeping hours" ,
"More sleeping hours" , "No change" ))
depression$social_relationships <- factor(depression$social_relationships,
levels = c( "Negative","Negative effect", "No effect" , "Positive", "Positive effect") ,
labels = c("Negative effect","Negative effect", "No effect" , "Positive effect", "Positive effect"))
depression$eating_habits_how <- factor(depression$eating_habits_how,
levels = c("both amount and type" ,"Change in both amount and type of food",
"Change in both the amount and type of food" ,"Change in the amount of food",
"Change in the type of food" , "changed amount of food" ,
"no change" , "type of food" ) ,
labels = c("both amount and type" ,"both amount and type",
"both amount and type" ,"amount of food",
"type of food" , "amount of food" ,
"no change" , "type of food" ))
depression$smoking_habits <- factor(depression$smoking_habits,
levels = c( "I am a non-smoker" ,
"I am a non-smoker." ,
"I am a smoker and my smoking habits did not change since the outreak" ,
"I am a smoker and my smoking habits have not change since the outbreak.",
"I am a smoker and reduced smoking during the pandemic." ,
"I started smoking during the pandemic" ,
"I started smoking during the pandemic." ,
"I stopped smoking during the pandemic." ) ,
labels = c("non-smoker" ,
"non-smoker" ,
"smoker with no change",
"smoker with no change",
"smoker with reduced smoking " ,
"started smoking" ,
"started smoking" ,
"stopped smoking" ))
levels(depression$smoking_habits)
## [1] "non-smoker" "smoker with no change"
## [3] "smoker with reduced smoking " "started smoking"
## [5] "stopped smoking"
##making new columns
######################################
depression$anxiety = c((depression$x2 + depression$x4 + depression$x7 + depression$x9 +
depression$x15+ depression$x19 + depression$x20)*2)
class(depression$anxiety)
## [1] "numeric"
depression$anxiety2 <- depression$anxiety %>% as.numeric()
Normal= c(0, 0:7, 7)
Mild = c(8, 9)
Moderate = c(10, 10:14, 14)
Severe =c(15, 15:19, 19)
Extremely.Severe = c(20, 20:42, 42)
depression$anxiety[depression$anxiety %in% Normal] <- "Normal"
depression$anxiety[depression$anxiety %in% Mild] <- "Mild"
depression$anxiety[depression$anxiety %in% Moderate] <- "Moderate"
depression$anxiety[depression$anxiety %in% Severe] <- "Severe"
depression$anxiety[depression$anxiety %in% Extremely.Severe] <- "Extremely.Severe"
depression$anxiety <- as.factor(depression$anxiety)
plot(depression$anxiety)

###################################
depression$deprss = c((depression$x3 + depression$x5 + depression$x10 + depression$x13 +
depression$x16 + depression$x17 + depression$x21)*2)
depression$deprss2 <- depression$deprss %>% as.numeric()
Normal= c(0, 0:9, 9)
Mild = c(10, 10:13, 13)
Moderate = c(14, 14:20, 20)
Severe =c(21, 21:27, 27)
Extremely.Severe = c(28, 28:42, 42)
depression$deprss[depression$deprss %in% Normal] <- "Normal"
depression$deprss[depression$deprss %in% Mild] <- "Mild"
depression$deprss[depression$deprss %in% Moderate] <- "Moderate"
depression$deprss[depression$deprss %in% Severe] <- "Severe"
depression$deprss[depression$deprss %in% Extremely.Severe] <- "Extremely.Severe"
depression$deprss <- as.factor(depression$deprss)
#############################
depression$stress = c((depression$x1 + depression$x6 + depression$x8 + depression$x11 + depression$x12 +
depression$x14 + depression$x18 )*2)
depression$stress2 <- depression$stress %>% as.numeric()
Normal= c(0, 0:14, 14)
Mild = c(15, 15:18, 18)
Moderate = c(19, 19:25, 25)
Severe =c(26, 26:33, 33)
Extremely.Severe = c(34, 34:42, 42)
depression$stress[depression$stress %in% Normal] <- "Normal"
depression$stress[depression$stress %in% Mild] <- "Mild"
depression$stress[depression$stress %in% Moderate] <- "Moderate"
depression$stress[depression$stress %in% Severe] <- "Severe"
depression$stress[depression$stress %in% Extremely.Severe] <- "Extremely.Severe"
depression$stress <- as.factor(depression$stress)
################################################################################
#testing for normality (The data is not normally distributed)
hist(depression$stress2)

library("ggpubr")
ggdensity(depression$anxiety2,
main = "Density plot of tooth length",
xlab = "Tooth length")

ggqqplot(depression$anxiety2)

shapiro.test(depression$anxiety2)
##
## Shapiro-Wilk normality test
##
## data: depression$anxiety2
## W = 0.95752, p-value < 2.2e-16
my_data = depression %>% select (stress2, deprss2, anxiety2, year, sex ,academic_performance,
relationship_with_your_family, social_relationships,
eating_habits, eating_habits_how ,gained_weight, smoking_habits,
sleeping_pattern, trouble_sleeping, sleep_quality,physical_activity) %>% as.data.frame()
as.numeric(my_data$sex)
## [1] 2 2 2 1 1 1 1 2 1 1 1 1 1 2 1 2 1 2 1 1 2 1 2 1 1 1 1 2 1 1 2 2 2 1 1 1 2
## [38] 1 2 2 1 1 2 1 2 2 1 2 2 1 2 2 1 1 1 1 1 1 1 2 1 2 2 1 1 1 1 1 1 2 2 1 1 1
## [75] 1 2 1 2 1 1 1 2 1 1 2 2 1 2 2 1 1 1 1 1 1 1 2 2 2 1 2 2 1 1 1 1 1 2 1 1 1
## [112] 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 2 1 1 1 1 2 1 1 1 1 1 1 1 2 2
## [149] 1 1 1 2 1 1 2 1 2 1 1 2 2 1 1 1 1 2 1 2 1 1 1 1 2 1 1 1 2 2 1 1 2 1 2 1 1
## [186] 1 2 1 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 1 1 2 1 1 2 2 2 2 1 1 1 1 1 1 1 1 1 1
## [223] 2 2 2 2 2 1 1 1 1 2 2 2 2 2 1 1 1 1 2 2 1 2 2 1 1 2 1 1 2 1 1 1 1 2 1 2 2
## [260] 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 1 1 1 1 2 1 2 2 2 1 1 1 1 1 1 2 1 1 2 1 1 1
## [297] 1 2 1 1 2 1 2 2 1 1 1 1 2 2 1 2 2 2 2 2 1 2 1 2 1 1 1 1 1 1 2 2 1 1 2 2 1
## [334] 2 2 2 1 1 2 2 1 2 1 2 2 2 2 1 2 1 2 1 2 2 1 2 2 1 2 1 1 2 1 2 1 1 1 1 1 1
## [371] 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1
## [408] 1 2 1 2 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1
## [445] 1 2 1 1 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 1 1 2 2
## [482] 1 1 1 1 1 1 1 2 2 2 2 1 1 1 2 1 1 2 2 1 1 1 1 1 1 1 1 2 1 2 2 1 1 1 2 2 1
## [519] 1 1 1 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 2 1 1 2 1 1 2 1 2 1 2 1 1 1 1 1 1 1 1
## [556] 2 1 2 1 2 1 1 2 2 1 1 2 1 2 1 2 2 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1
## [593] 1 1 1 2 1 1 1 1 2 2 1 2 1 1 1 1 1 1 1 1 1 2 2 2 1 2 1 1 1 1 1 1 1 1 2 1 2
## [630] 1 2 1 1 1 2 1 1 1 1 1 1 2 1 1 2 2 1 1 2 1 1 2 2 1 2 1 2 2 1 1 1 1 2 1 1 1
## [667] 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 2 1 1 1 2 2 2 1 2 2 2 1
## [704] 2 1 1 2 1 1 1 1 1 1 2 1 2 2 2 1 2 1 1 1 1 1 2 2 2 2 1 1 2 2 1 1 2 1 2 1 1
## [741] 2 1 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 2 1 2
## [778] 1 1 2 2 1 2 1 1 1 2 1 2 1 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 2 1 1
## [815] 2 2 2 2 1 2 1 1 2 1 1 1 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 2 2 1 1 1 2 1 1 1 1
## [852] 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 1
## [889] 1 1 2 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 2 2 2 1 2 1 1 2 2 1 1 2
## [926] 2 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 2 1 1 1 1
## [963] 1 1 2 1 2 2 1 2 1 2 1 2 2 2 1 2 2 2 1 2 1 1 2 1 1 1 1 1 1 2 1 1 2 1 2 1 1
## [1000] 1 1 2 2 1 2 2 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 2 2
## [1037] 1 1 1 1 1 1 2 1 2 2 1 2 1 1 1 1 2 1 2 1 1 1 1 2 2 1 1 1 2 2 2 1 1 2 1 1 2
## [1074] 2 1 2 1 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 1 1 2 2 1 1 1 1 2 1 1 1 1 1 1
## [1111] 1 1 1 1 1 1 1 2 1 2 1 2 1 1 2 1 2 2 2 1 1 1 1 1 2 2 1 2 1 2 2 2 1 1 1 1 2
## [1148] 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 1 2 1 1 1 2 1 2 1 1 2 1 1 2 1 2 1 1 1 1 1 1
## [1185] 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1
## [1222] 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 1 2 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 2 1 1 1
## [1259] 1 1 1 1 2 1 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1 2 1 2
## [1296] 2 2 2 2 1 1
library(dplyr)
my_data = my_data %>%
mutate_all(as.numeric)
matrix <- cor(my_data, use = "complete.obs", method = "spearman") %>% as.data.frame()
write.csv(matrix, file = "matrix.csv")
###############################
#Linear regression( using step wise selection )
library(caret)
## Loading required package: lattice
##
## Attaching package: 'caret'
## The following object is masked from 'package:purrr':
##
## lift
library(leaps)
# Set seed for reproducibility
set.seed(123)
#Making new data frame for regression (we used only depression as the other subscales was found to be highly correlated)
dataReg <- depression %>% na.omit(depression) %>%
select(deprss2, year, sex ,academic_performance,
relationship_with_your_family, social_relationships,
eating_habits, eating_habits_how ,gained_weight, smoking_habits,
sleeping_pattern, trouble_sleeping, sleep_quality,physical_activity)
names(dataReg)
## [1] "deprss2" "year"
## [3] "sex" "academic_performance"
## [5] "relationship_with_your_family" "social_relationships"
## [7] "eating_habits" "eating_habits_how"
## [9] "gained_weight" "smoking_habits"
## [11] "sleeping_pattern" "trouble_sleeping"
## [13] "sleep_quality" "physical_activity"
# Set up repeated k-fold cross-validation
train.control <- trainControl(method = "cv", number = 10)
# Train the model
step.model <- train(deprss2 ~., data = dataReg,
method = "leapSeq",
tuneGrid = data.frame(nvmax = 1:13),
trControl = train.control)
step.model$results
## nvmax RMSE Rsquared MAE RMSESD RsquaredSD MAESD
## 1 1 11.11586 0.08071998 9.346980 0.3675167 0.05509099 0.3095806
## 2 2 11.11192 0.08183516 9.314816 0.3511517 0.03366671 0.2439178
## 3 3 10.74643 0.13826691 8.929999 0.3636245 0.04670804 0.3134308
## 4 4 10.59686 0.15984938 8.816163 0.3359991 0.04863565 0.2495277
## 5 5 10.67933 0.15099644 8.889180 0.4172432 0.05988859 0.3088920
## 6 6 10.64225 0.15861983 8.844071 0.4964621 0.07170734 0.4164087
## 7 7 10.77087 0.13777414 8.970654 0.4598540 0.05940865 0.3666392
## 8 8 10.60564 0.16507215 8.786637 0.5965378 0.08407653 0.5284714
## 9 9 10.61939 0.16530356 8.841268 0.5703081 0.08415638 0.5653824
## 10 10 10.48243 0.18260018 8.713195 0.7043133 0.09536341 0.5943071
## 11 11 10.41911 0.19366777 8.615009 0.5727064 0.08820535 0.4869791
## 12 12 10.48051 0.18737152 8.682246 0.5092244 0.08133059 0.4255507
## 13 13 10.46231 0.18545243 8.697184 0.5749636 0.07955392 0.5224946
step.model$bestTune
## nvmax
## 11 11
summary(step.model$finalModel)
## Subset selection object
## 31 Variables (and intercept)
## Forced in Forced out
## year2 FALSE FALSE
## year3 FALSE FALSE
## year4 FALSE FALSE
## year5 FALSE FALSE
## year6 FALSE FALSE
## sexMale FALSE FALSE
## academic_performanceNo change FALSE FALSE
## academic_performancePositive effect FALSE FALSE
## relationship_with_your_familyNo change FALSE FALSE
## relationship_with_your_familyPositive effect FALSE FALSE
## social_relationshipsNo effect FALSE FALSE
## social_relationshipsPositive effect FALSE FALSE
## eating_habitsYes FALSE FALSE
## eating_habits_howamount of food FALSE FALSE
## eating_habits_howtype of food FALSE FALSE
## eating_habits_howno change FALSE FALSE
## gained_weightYes FALSE FALSE
## smoking_habitssmoker with no change FALSE FALSE
## smoking_habitssmoker with reduced smoking FALSE FALSE
## smoking_habitsstarted smoking FALSE FALSE
## smoking_habitsstopped smoking FALSE FALSE
## sleeping_patternLess sleeping hours FALSE FALSE
## sleeping_patternMore sleeping hours FALSE FALSE
## sleeping_patternNo change FALSE FALSE
## trouble_sleepingNo FALSE FALSE
## trouble_sleepingYes FALSE FALSE
## sleep_qualityFairly good FALSE FALSE
## sleep_qualityVery bad FALSE FALSE
## sleep_qualityVery good FALSE FALSE
## physical_activityMore physical activity FALSE FALSE
## physical_activityNo change FALSE FALSE
## 1 subsets of each size up to 11
## Selection Algorithm: 'sequential replacement'
## year2 year3 year4 year5 year6 sexMale academic_performanceNo change
## 1 ( 1 ) " " " " " " " " " " " " " "
## 2 ( 1 ) " " " " " " " " " " " " " "
## 3 ( 1 ) " " " " " " " " " " " " " "
## 4 ( 1 ) " " " " " " " " " " " " " "
## 5 ( 1 ) " " "*" " " " " " " " " " "
## 6 ( 1 ) " " "*" " " " " " " " " "*"
## 7 ( 1 ) " " "*" " " " " " " " " " "
## 8 ( 1 ) " " "*" " " " " " " " " " "
## 9 ( 1 ) " " "*" " " " " " " " " " "
## 10 ( 1 ) " " "*" " " " " " " " " " "
## 11 ( 1 ) " " "*" " " " " " " "*" "*"
## academic_performancePositive effect
## 1 ( 1 ) " "
## 2 ( 1 ) " "
## 3 ( 1 ) " "
## 4 ( 1 ) "*"
## 5 ( 1 ) "*"
## 6 ( 1 ) "*"
## 7 ( 1 ) "*"
## 8 ( 1 ) "*"
## 9 ( 1 ) "*"
## 10 ( 1 ) "*"
## 11 ( 1 ) "*"
## relationship_with_your_familyNo change
## 1 ( 1 ) " "
## 2 ( 1 ) " "
## 3 ( 1 ) " "
## 4 ( 1 ) " "
## 5 ( 1 ) " "
## 6 ( 1 ) " "
## 7 ( 1 ) " "
## 8 ( 1 ) " "
## 9 ( 1 ) " "
## 10 ( 1 ) " "
## 11 ( 1 ) " "
## relationship_with_your_familyPositive effect
## 1 ( 1 ) " "
## 2 ( 1 ) " "
## 3 ( 1 ) " "
## 4 ( 1 ) " "
## 5 ( 1 ) " "
## 6 ( 1 ) " "
## 7 ( 1 ) " "
## 8 ( 1 ) " "
## 9 ( 1 ) " "
## 10 ( 1 ) " "
## 11 ( 1 ) " "
## social_relationshipsNo effect social_relationshipsPositive effect
## 1 ( 1 ) " " " "
## 2 ( 1 ) " " " "
## 3 ( 1 ) "*" " "
## 4 ( 1 ) "*" " "
## 5 ( 1 ) "*" " "
## 6 ( 1 ) "*" " "
## 7 ( 1 ) "*" "*"
## 8 ( 1 ) "*" "*"
## 9 ( 1 ) "*" "*"
## 10 ( 1 ) "*" "*"
## 11 ( 1 ) "*" " "
## eating_habitsYes eating_habits_howamount of food
## 1 ( 1 ) " " " "
## 2 ( 1 ) " " " "
## 3 ( 1 ) " " " "
## 4 ( 1 ) " " " "
## 5 ( 1 ) " " " "
## 6 ( 1 ) " " " "
## 7 ( 1 ) " " " "
## 8 ( 1 ) " " " "
## 9 ( 1 ) " " " "
## 10 ( 1 ) " " " "
## 11 ( 1 ) " " " "
## eating_habits_howtype of food eating_habits_howno change
## 1 ( 1 ) " " " "
## 2 ( 1 ) " " " "
## 3 ( 1 ) " " " "
## 4 ( 1 ) " " " "
## 5 ( 1 ) " " " "
## 6 ( 1 ) " " " "
## 7 ( 1 ) " " " "
## 8 ( 1 ) " " " "
## 9 ( 1 ) " " " "
## 10 ( 1 ) " " " "
## 11 ( 1 ) " " " "
## gained_weightYes smoking_habitssmoker with no change
## 1 ( 1 ) " " " "
## 2 ( 1 ) " " " "
## 3 ( 1 ) " " " "
## 4 ( 1 ) " " " "
## 5 ( 1 ) " " " "
## 6 ( 1 ) " " " "
## 7 ( 1 ) " " " "
## 8 ( 1 ) " " " "
## 9 ( 1 ) " " " "
## 10 ( 1 ) " " " "
## 11 ( 1 ) " " " "
## smoking_habitssmoker with reduced smoking
## 1 ( 1 ) " "
## 2 ( 1 ) " "
## 3 ( 1 ) " "
## 4 ( 1 ) " "
## 5 ( 1 ) " "
## 6 ( 1 ) " "
## 7 ( 1 ) " "
## 8 ( 1 ) " "
## 9 ( 1 ) " "
## 10 ( 1 ) " "
## 11 ( 1 ) " "
## smoking_habitsstarted smoking smoking_habitsstopped smoking
## 1 ( 1 ) " " " "
## 2 ( 1 ) " " " "
## 3 ( 1 ) " " " "
## 4 ( 1 ) " " " "
## 5 ( 1 ) " " " "
## 6 ( 1 ) " " " "
## 7 ( 1 ) " " " "
## 8 ( 1 ) " " " "
## 9 ( 1 ) " " " "
## 10 ( 1 ) " " " "
## 11 ( 1 ) " " " "
## sleeping_patternLess sleeping hours
## 1 ( 1 ) " "
## 2 ( 1 ) " "
## 3 ( 1 ) " "
## 4 ( 1 ) " "
## 5 ( 1 ) " "
## 6 ( 1 ) " "
## 7 ( 1 ) " "
## 8 ( 1 ) " "
## 9 ( 1 ) " "
## 10 ( 1 ) " "
## 11 ( 1 ) " "
## sleeping_patternMore sleeping hours sleeping_patternNo change
## 1 ( 1 ) " " " "
## 2 ( 1 ) " " " "
## 3 ( 1 ) " " " "
## 4 ( 1 ) " " " "
## 5 ( 1 ) " " " "
## 6 ( 1 ) " " " "
## 7 ( 1 ) " " "*"
## 8 ( 1 ) " " " "
## 9 ( 1 ) " " "*"
## 10 ( 1 ) "*" " "
## 11 ( 1 ) "*" " "
## trouble_sleepingNo trouble_sleepingYes sleep_qualityFairly good
## 1 ( 1 ) "*" " " " "
## 2 ( 1 ) "*" " " "*"
## 3 ( 1 ) "*" " " "*"
## 4 ( 1 ) "*" " " "*"
## 5 ( 1 ) "*" " " "*"
## 6 ( 1 ) "*" " " "*"
## 7 ( 1 ) "*" " " "*"
## 8 ( 1 ) "*" " " "*"
## 9 ( 1 ) "*" " " "*"
## 10 ( 1 ) "*" " " "*"
## 11 ( 1 ) "*" " " "*"
## sleep_qualityVery bad sleep_qualityVery good
## 1 ( 1 ) " " " "
## 2 ( 1 ) " " " "
## 3 ( 1 ) " " " "
## 4 ( 1 ) " " " "
## 5 ( 1 ) " " " "
## 6 ( 1 ) " " " "
## 7 ( 1 ) " " " "
## 8 ( 1 ) " " " "
## 9 ( 1 ) " " " "
## 10 ( 1 ) " " "*"
## 11 ( 1 ) " " "*"
## physical_activityMore physical activity physical_activityNo change
## 1 ( 1 ) " " " "
## 2 ( 1 ) " " " "
## 3 ( 1 ) " " " "
## 4 ( 1 ) " " " "
## 5 ( 1 ) " " " "
## 6 ( 1 ) " " " "
## 7 ( 1 ) " " " "
## 8 ( 1 ) "*" "*"
## 9 ( 1 ) "*" "*"
## 10 ( 1 ) "*" "*"
## 11 ( 1 ) "*" "*"
##The regression coefficients of the final model (best model) / fitting the model
##testing for coliniarity
model <- lm(deprss2 ~ year + academic_performance +trouble_sleeping+
social_relationships+ eating_habits_how+ smoking_habits+sleep_quality+physical_activity
, data = dataReg)
summary(model)
##
## Call:
## lm(formula = deprss2 ~ year + academic_performance + trouble_sleeping +
## social_relationships + eating_habits_how + smoking_habits +
## sleep_quality + physical_activity, data = dataReg)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.603 -7.229 0.579 7.286 27.523
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 28.7852 1.1475 25.085 < 2e-16
## year2 2.8783 1.1432 2.518 0.011994
## year3 4.4855 1.1672 3.843 0.000130
## year4 0.6145 1.1067 0.555 0.578896
## year5 1.3993 1.0650 1.314 0.189242
## year6 1.4529 1.3585 1.069 0.285147
## academic_performanceNo change -2.9269 1.0688 -2.738 0.006299
## academic_performancePositive effect -4.6531 0.9802 -4.747 2.41e-06
## trouble_sleepingNo -3.1221 0.9626 -3.243 0.001227
## trouble_sleepingYes 1.5502 0.8383 1.849 0.064782
## social_relationshipsNo effect -5.1766 0.9092 -5.694 1.70e-08
## social_relationshipsPositive effect -3.2657 1.0438 -3.129 0.001814
## eating_habits_howamount of food 1.2431 0.7600 1.636 0.102286
## eating_habits_howtype of food -1.4425 1.0338 -1.395 0.163263
## eating_habits_howno change -3.2181 2.4221 -1.329 0.184316
## smoking_habitssmoker with no change -3.1700 2.0165 -1.572 0.116316
## smoking_habitssmoker with reduced smoking 4.9002 3.3896 1.446 0.148636
## smoking_habitsstarted smoking 1.2005 2.3729 0.506 0.613045
## smoking_habitsstopped smoking 5.4368 3.5867 1.516 0.129927
## sleep_qualityFairly good -3.4839 0.8848 -3.937 8.90e-05
## sleep_qualityVery bad 2.0159 1.1400 1.768 0.077359
## sleep_qualityVery good -2.5383 1.2918 -1.965 0.049743
## physical_activityMore physical activity -3.3677 1.0750 -3.133 0.001791
## physical_activityNo change -3.5123 1.0445 -3.363 0.000806
##
## (Intercept) ***
## year2 *
## year3 ***
## year4
## year5
## year6
## academic_performanceNo change **
## academic_performancePositive effect ***
## trouble_sleepingNo **
## trouble_sleepingYes .
## social_relationshipsNo effect ***
## social_relationshipsPositive effect **
## eating_habits_howamount of food
## eating_habits_howtype of food
## eating_habits_howno change
## smoking_habitssmoker with no change
## smoking_habitssmoker with reduced smoking
## smoking_habitsstarted smoking
## smoking_habitsstopped smoking
## sleep_qualityFairly good ***
## sleep_qualityVery bad .
## sleep_qualityVery good *
## physical_activityMore physical activity **
## physical_activityNo change ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.998 on 868 degrees of freedom
## Multiple R-squared: 0.2691, Adjusted R-squared: 0.2497
## F-statistic: 13.89 on 23 and 868 DF, p-value: < 2.2e-16
library("olsrr")
##
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
##
## rivers
ols_coll_diag(model)
## Tolerance and Variance Inflation Factor
## ---------------------------------------
## Variables Tolerance VIF
## 1 year2 0.6480432 1.543107
## 2 year3 0.6649945 1.503772
## 3 year4 0.5878686 1.701060
## 4 year5 0.6010484 1.663760
## 5 year6 0.7119178 1.404657
## 6 academic_performanceNo change 0.9146091 1.093363
## 7 academic_performancePositive effect 0.8919012 1.121200
## 8 trouble_sleepingNo 0.6431181 1.554924
## 9 trouble_sleepingYes 0.6613277 1.512110
## 10 social_relationshipsNo effect 0.9121800 1.096275
## 11 social_relationshipsPositive effect 0.9092967 1.099751
## 12 eating_habits_howamount of food 0.8292588 1.205896
## 13 eating_habits_howtype of food 0.8532301 1.172017
## 14 eating_habits_howno change 0.9163918 1.091236
## 15 smoking_habitssmoker with no change 0.9739150 1.026784
## 16 smoking_habitssmoker with reduced smoking 0.9766278 1.023932
## 17 smoking_habitsstarted smoking 0.9547556 1.047389
## 18 smoking_habitsstopped smoking 0.9801521 1.020250
## 19 sleep_qualityFairly good 0.5761145 1.735766
## 20 sleep_qualityVery bad 0.7567006 1.321527
## 21 sleep_qualityVery good 0.5893018 1.696923
## 22 physical_activityMore physical activity 0.9040783 1.106099
## 23 physical_activityNo change 0.9147180 1.093233
##
##
## Eigenvalue and Condition Index
## ------------------------------
## Eigenvalue Condition Index intercept year2 year3
## 1 5.06752310 1.000000 2.990992e-03 3.329528e-03 3.023310e-03
## 2 1.56452314 1.799728 5.922493e-04 1.406562e-02 6.643238e-03
## 3 1.22459451 2.034238 3.736642e-06 3.090151e-02 4.051054e-02
## 4 1.18803475 2.065301 1.350978e-05 6.177534e-06 1.890385e-02
## 5 1.14976092 2.099395 5.418882e-05 2.201471e-02 3.752771e-03
## 6 1.10936845 2.137273 8.149119e-07 2.421675e-02 2.763185e-03
## 7 1.08760964 2.158546 4.597139e-10 4.264797e-02 4.172702e-03
## 8 1.03944452 2.207991 2.326312e-07 1.323986e-02 5.752014e-02
## 9 1.01161315 2.238157 1.404540e-04 1.221379e-02 8.521415e-04
## 10 0.98221483 2.271405 5.754156e-06 9.346977e-03 1.241641e-01
## 11 0.94846386 2.311466 1.029853e-05 3.072806e-02 1.529189e-01
## 12 0.94081196 2.320847 2.559525e-05 8.027080e-02 1.097548e-03
## 13 0.90885303 2.361299 1.853134e-04 3.593839e-02 7.149888e-03
## 14 0.85657252 2.432293 2.037097e-04 6.571469e-02 7.296858e-05
## 15 0.84843411 2.443930 1.613629e-04 1.381338e-03 7.902913e-03
## 16 0.73496457 2.625818 2.806888e-04 1.259633e-02 3.572568e-02
## 17 0.69847313 2.693537 1.698260e-03 6.690902e-02 2.171993e-03
## 18 0.59324676 2.922673 1.886442e-04 1.993726e-04 5.986488e-03
## 19 0.58842588 2.934621 4.289798e-04 6.229596e-04 6.241381e-04
## 20 0.54718111 3.043213 1.478640e-04 5.217637e-04 2.452999e-03
## 21 0.38245276 3.640064 2.147764e-03 3.462805e-02 4.489636e-02
## 22 0.27425182 4.298561 5.453006e-03 2.577935e-02 5.174885e-03
## 23 0.18826158 5.188204 1.348914e-03 2.691010e-01 2.833135e-01
## 24 0.06491992 8.835048 9.839177e-01 2.036260e-01 1.882058e-01
## year4 year5 year6 academic_performanceNo change
## 1 0.0038797143 0.0036438925 2.414661e-03 5.856110e-03
## 2 0.0119909368 0.0031334676 6.241775e-04 6.006932e-03
## 3 0.0582995960 0.0256171385 8.360529e-03 3.341251e-03
## 4 0.0322932654 0.0274425336 3.956874e-02 2.026795e-03
## 5 0.0101740806 0.0005409512 2.838619e-03 1.620659e-02
## 6 0.0108927342 0.0091165745 7.968902e-03 5.900711e-02
## 7 0.0187314566 0.0466672498 5.808608e-02 7.334276e-02
## 8 0.0003108544 0.0560243928 5.404046e-02 1.603914e-02
## 9 0.0030308237 0.0061183147 5.694596e-02 4.517779e-04
## 10 0.0104145868 0.0005163574 2.528840e-01 3.017739e-02
## 11 0.0073072511 0.0568746802 7.502911e-05 7.443053e-04
## 12 0.0070836779 0.0217529075 7.361465e-08 9.999137e-03
## 13 0.0071196868 0.0091564341 3.631680e-03 2.541067e-01
## 14 0.0035151267 0.0338072804 9.415311e-04 5.250858e-05
## 15 0.0184848914 0.0058541026 6.121609e-02 1.668300e-02
## 16 0.1444531510 0.0525959921 3.072208e-03 5.041809e-02
## 17 0.0267397322 0.0159987732 9.373790e-03 2.773083e-02
## 18 0.0041732516 0.0002575645 6.557890e-03 1.213405e-02
## 19 0.0034091107 0.0055566082 2.984352e-03 6.070109e-02
## 20 0.0016294791 0.0023690414 4.689363e-03 3.488225e-01
## 21 0.0499885415 0.0288700429 2.500347e-04 8.946582e-06
## 22 0.0244388717 0.0135296854 1.393609e-02 2.779988e-04
## 23 0.3129378456 0.3191977778 2.702432e-01 5.768737e-03
## 24 0.2287013337 0.2553582370 1.392965e-01 9.627369e-05
## academic_performancePositive effect trouble_sleepingNo trouble_sleepingYes
## 1 0.0068226935 7.003004e-03 5.070979e-03
## 2 0.0053425514 5.145800e-02 5.794929e-02
## 3 0.0100859040 3.435334e-03 1.344437e-03
## 4 0.0345050570 2.922928e-03 1.481737e-04
## 5 0.0035519600 8.177466e-03 1.128670e-03
## 6 0.0379512826 7.771981e-05 4.514439e-04
## 7 0.0952841562 2.196758e-03 1.393959e-05
## 8 0.0092790641 1.709174e-04 4.583184e-07
## 9 0.0010353878 6.385251e-03 6.847508e-03
## 10 0.0335279117 6.940392e-05 9.276075e-03
## 11 0.0007082547 9.445520e-04 3.228973e-04
## 12 0.0001660926 1.806034e-03 1.305165e-04
## 13 0.0478201763 2.236825e-05 1.012493e-02
## 14 0.0040209895 1.801850e-03 3.089748e-05
## 15 0.0581649669 3.230255e-03 1.307269e-03
## 16 0.0000521554 3.526950e-05 3.024352e-04
## 17 0.0702890149 2.346769e-02 2.772199e-03
## 18 0.0047442654 1.998951e-01 1.368559e-01
## 19 0.0665821738 3.869511e-03 6.901038e-04
## 20 0.4955143150 2.283057e-03 6.126143e-04
## 21 0.0110073510 7.963125e-02 5.135973e-02
## 22 0.0014579182 5.895510e-01 3.301218e-01
## 23 0.0008668735 8.421018e-03 2.188879e-01
## 24 0.0012194845 3.144278e-03 1.642498e-01
## social_relationshipsNo effect social_relationshipsPositive effect
## 1 7.478128e-03 5.621168e-03
## 2 5.531087e-03 5.335226e-04
## 3 1.655857e-02 1.889272e-02
## 4 4.689423e-03 2.797160e-02
## 5 2.615155e-02 6.919220e-02
## 6 4.399884e-02 8.581777e-02
## 7 4.061492e-03 2.090830e-03
## 8 8.919647e-03 3.074665e-03
## 9 1.611788e-02 5.360377e-03
## 10 2.896051e-04 2.151499e-07
## 11 2.123180e-02 4.835839e-05
## 12 5.353775e-02 4.654693e-02
## 13 1.767588e-02 8.898326e-02
## 14 1.033398e-01 1.013748e-01
## 15 6.498501e-03 3.485652e-04
## 16 2.778201e-06 7.870469e-03
## 17 8.977014e-02 8.647390e-02
## 18 1.502679e-02 6.151668e-03
## 19 3.498783e-01 1.405639e-01
## 20 1.914554e-01 2.682486e-01
## 21 1.120262e-03 6.931393e-05
## 22 1.641951e-03 2.816541e-02
## 23 1.994349e-03 2.944392e-03
## 24 1.303008e-02 3.655323e-03
## eating_habits_howamount of food eating_habits_howtype of food
## 1 7.874078e-03 0.0045840683
## 2 1.845761e-03 0.0005611841
## 3 2.926280e-02 0.0230918527
## 4 2.658791e-02 0.0386936370
## 5 4.707910e-04 0.0110364407
## 6 1.531265e-03 0.0442878687
## 7 1.763168e-02 0.0704364281
## 8 4.367366e-04 0.0199723817
## 9 1.035850e-02 0.0037209387
## 10 3.213394e-03 0.0014368983
## 11 1.788289e-02 0.0803008954
## 12 7.098912e-03 0.0210097735
## 13 1.368443e-02 0.1492354409
## 14 2.247086e-02 0.0028509398
## 15 1.488730e-02 0.0420872955
## 16 6.065708e-02 0.0067941214
## 17 1.429955e-02 0.0645739172
## 18 1.017725e-04 0.0009269747
## 19 4.672519e-04 0.0535543900
## 20 7.192464e-05 0.0002578943
## 21 6.232053e-01 0.2866441130
## 22 1.873835e-02 0.0004573322
## 23 5.009599e-03 0.0124677514
## 24 1.022119e-01 0.0610174624
## eating_habits_howno change smoking_habitssmoker with no change
## 1 9.745470e-04 1.599520e-03
## 2 2.553402e-03 6.256610e-04
## 3 2.347200e-01 8.545333e-04
## 4 2.067048e-02 8.292323e-02
## 5 7.896928e-02 4.413688e-04
## 6 2.508309e-03 6.579601e-02
## 7 5.621174e-03 1.298816e-01
## 8 4.973927e-02 4.634662e-02
## 9 6.535043e-03 3.159920e-03
## 10 6.496426e-05 1.861794e-05
## 11 6.757664e-03 9.987269e-02
## 12 5.394383e-02 9.459639e-02
## 13 2.619439e-02 2.393100e-02
## 14 5.171943e-04 2.899229e-02
## 15 4.306939e-02 3.698299e-01
## 16 2.687568e-01 6.517537e-05
## 17 7.617389e-02 2.195044e-02
## 18 8.151572e-04 3.727932e-06
## 19 1.129254e-03 1.136009e-03
## 20 2.035221e-02 1.416517e-03
## 21 9.087110e-02 2.400958e-02
## 22 6.980336e-03 2.245890e-03
## 23 8.505909e-04 3.658388e-05
## 24 1.231769e-03 2.668036e-04
## smoking_habitssmoker with reduced smoking smoking_habitsstarted smoking
## 1 0.0005100793 0.0007475038
## 2 0.0052424920 0.0293457096
## 3 0.0223022758 0.0094245626
## 4 0.0723368012 0.0105979041
## 5 0.0911851022 0.0046075068
## 6 0.0012167127 0.0229749913
## 7 0.0333162304 0.0073338438
## 8 0.0800422456 0.0534591115
## 9 0.0091697051 0.2946739093
## 10 0.0188971435 0.0926482590
## 11 0.0136382368 0.1842036788
## 12 0.3800095604 0.0046420816
## 13 0.0566453325 0.0520507184
## 14 0.1308918614 0.0036257432
## 15 0.0178733628 0.0652848957
## 16 0.0262163278 0.0848538412
## 17 0.0003290210 0.0076596296
## 18 0.0002971035 0.0142856738
## 19 0.0254609911 0.0016015140
## 20 0.0028892872 0.0001623604
## 21 0.0071721586 0.0263659186
## 22 0.0033316097 0.0075106332
## 23 0.0007806983 0.0120996043
## 24 0.0002456610 0.0098404051
## smoking_habitsstopped smoking sleep_qualityFairly good sleep_qualityVery bad
## 1 3.120712e-04 5.918799e-03 2.839059e-03
## 2 5.488065e-03 1.508168e-03 9.452259e-02
## 3 1.495998e-02 5.638524e-05 3.439929e-03
## 4 2.788883e-04 1.457771e-02 4.453460e-02
## 5 1.850818e-02 2.641423e-02 5.294415e-03
## 6 7.876506e-03 4.261169e-03 1.213287e-03
## 7 4.535626e-02 6.701196e-04 2.111914e-03
## 8 2.678648e-01 1.327058e-03 1.189189e-02
## 9 3.585871e-01 2.575136e-03 3.234869e-03
## 10 8.587049e-04 1.885999e-02 1.477391e-02
## 11 6.591674e-02 1.295317e-03 3.448835e-03
## 12 1.108908e-02 1.602971e-03 5.574754e-03
## 13 7.514015e-05 1.000767e-03 2.158211e-02
## 14 6.425288e-02 1.026491e-02 6.474533e-03
## 15 3.898632e-02 4.767133e-03 3.085320e-02
## 16 7.458299e-03 1.972190e-02 5.505303e-02
## 17 2.242642e-02 9.419379e-03 7.244679e-02
## 18 6.245112e-02 2.052199e-02 3.101622e-01
## 19 3.013538e-05 2.418262e-03 1.269734e-03
## 20 1.744492e-03 6.868295e-03 9.566557e-03
## 21 8.031820e-04 2.601142e-02 3.637776e-05
## 22 1.245724e-04 1.503640e-01 1.414454e-01
## 23 1.866952e-03 4.298524e-01 6.649303e-02
## 24 2.684134e-03 2.397225e-01 9.173696e-02
## sleep_qualityVery good physical_activityMore physical activity
## 1 3.542603e-03 5.739526e-03
## 2 3.631922e-02 1.119679e-02
## 3 7.124169e-03 1.566825e-03
## 4 2.429867e-02 4.460723e-02
## 5 1.012410e-01 4.959331e-02
## 6 1.044800e-02 5.978911e-02
## 7 3.178225e-03 7.152736e-04
## 8 5.741009e-03 1.113316e-07
## 9 5.491923e-05 1.900795e-03
## 10 2.391516e-02 7.753956e-05
## 11 7.653529e-03 3.272245e-05
## 12 4.221403e-03 5.689473e-02
## 13 5.928095e-05 8.440440e-04
## 14 5.343669e-03 2.022465e-01
## 15 8.058907e-03 4.487609e-02
## 16 2.397670e-02 2.232042e-02
## 17 2.061988e-02 1.000387e-01
## 18 9.562731e-02 1.026107e-02
## 19 1.448879e-03 2.826047e-01
## 20 1.486048e-03 1.825796e-02
## 21 2.627389e-03 7.896067e-02
## 22 2.742692e-01 4.718560e-03
## 23 2.216694e-01 8.833739e-06
## 24 1.170755e-01 2.748534e-03
## physical_activityNo change
## 1 0.0055206029
## 2 0.0008169683
## 3 0.0036938374
## 4 0.0042109750
## 5 0.0413183938
## 6 0.1784850490
## 7 0.0005557934
## 8 0.0033278614
## 9 0.0391455894
## 10 0.0027605778
## 11 0.0001002708
## 12 0.0001727546
## 13 0.0010584985
## 14 0.0773151946
## 15 0.0865282169
## 16 0.0037180714
## 17 0.1636336853
## 18 0.0164059398
## 19 0.2989829737
## 20 0.0151789756
## 21 0.0203525321
## 22 0.0166279458
## 23 0.0050271656
## 24 0.0150621271
#odds ratios
##deprss
depression$deprss <- ordered(depression$deprss, levels = c("Normal", "Mild", "Moderate", "Severe","Extremely.Severe"))
depression$stress <- ordered(depression$stress, levels = c("Normal", "Mild", "Moderate", "Severe","Extremely.Severe"))
depression$anxiety <- ordered(depression$anxiety, levels = c("Normal", "Mild", "Moderate", "Severe","Extremely.Severe"))
fit.log = glm(deprss ~ year + academic_performance +trouble_sleeping+
social_relationships+ eating_habits_how+ smoking_habits+sleep_quality+physical_activity
, data = depression, family = binomial)
summary(fit.log)
##
## Call:
## glm(formula = deprss ~ year + academic_performance + trouble_sleeping +
## social_relationships + eating_habits_how + smoking_habits +
## sleep_quality + physical_activity, family = binomial, data = depression)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -3.2231 0.1160 0.2341 0.4083 1.4530
##
## Coefficients:
## Estimate Std. Error z value
## (Intercept) 4.577e+00 6.568e-01 6.969
## year2 5.854e-01 4.623e-01 1.266
## year3 9.126e-01 5.301e-01 1.722
## year4 8.400e-02 3.993e-01 0.210
## year5 6.966e-02 3.966e-01 0.176
## year6 -3.302e-03 4.821e-01 -0.007
## academic_performanceNo change -1.889e-01 3.634e-01 -0.520
## academic_performancePositive effect -9.754e-01 3.035e-01 -3.214
## trouble_sleepingNo -6.905e-01 3.149e-01 -2.193
## trouble_sleepingYes 4.215e-01 4.099e-01 1.028
## social_relationshipsNo effect -1.190e+00 2.940e-01 -4.047
## social_relationshipsPositive effect -7.888e-01 3.518e-01 -2.242
## eating_habits_howamount of food 5.188e-01 3.019e-01 1.718
## eating_habits_howtype of food -2.195e-01 3.518e-01 -0.624
## eating_habits_howno change 1.180e+00 1.128e+00 1.046
## smoking_habitssmoker with no change -8.681e-01 5.957e-01 -1.457
## smoking_habitssmoker with reduced smoking 1.531e+01 1.205e+03 0.013
## smoking_habitsstarted smoking -1.692e-01 1.171e+00 -0.144
## smoking_habitsstopped smoking 1.383e+01 1.341e+03 0.010
## sleep_qualityFairly good -1.757e+00 5.685e-01 -3.091
## sleep_qualityVery bad -6.306e-01 8.145e-01 -0.774
## sleep_qualityVery good -1.795e+00 6.280e-01 -2.858
## physical_activityMore physical activity -5.990e-01 3.382e-01 -1.771
## physical_activityNo change -1.347e+00 3.107e-01 -4.334
## Pr(>|z|)
## (Intercept) 3.20e-12 ***
## year2 0.20539
## year3 0.08516 .
## year4 0.83338
## year5 0.86059
## year6 0.99454
## academic_performanceNo change 0.60327
## academic_performancePositive effect 0.00131 **
## trouble_sleepingNo 0.02834 *
## trouble_sleepingYes 0.30377
## social_relationshipsNo effect 5.18e-05 ***
## social_relationshipsPositive effect 0.02493 *
## eating_habits_howamount of food 0.08573 .
## eating_habits_howtype of food 0.53272
## eating_habits_howno change 0.29537
## smoking_habitssmoker with no change 0.14503
## smoking_habitssmoker with reduced smoking 0.98986
## smoking_habitsstarted smoking 0.88517
## smoking_habitsstopped smoking 0.99177
## sleep_qualityFairly good 0.00200 **
## sleep_qualityVery bad 0.43878
## sleep_qualityVery good 0.00427 **
## physical_activityMore physical activity 0.07658 .
## physical_activityNo change 1.46e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 567.17 on 898 degrees of freedom
## Residual deviance: 423.60 on 875 degrees of freedom
## (402 observations deleted due to missingness)
## AIC: 471.6
##
## Number of Fisher Scoring iterations: 16
library(epiDisplay)
## Loading required package: foreign
## Loading required package: survival
##
## Attaching package: 'survival'
## The following object is masked from 'package:caret':
##
## cluster
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:olsrr':
##
## cement
## The following object is masked from 'package:dplyr':
##
## select
## Loading required package: nnet
##
## Attaching package: 'epiDisplay'
## The following object is masked from 'package:lattice':
##
## dotplot
## The following object is masked from 'package:ggplot2':
##
## alpha
logistic.display(fit.log)
##
## Logistic regression predicting deprss
##
## crude OR(95%CI)
## year: ref.=1
## 2 1.51 (0.68,3.35)
## 3 2.04 (0.83,4.99)
## 4 0.86 (0.44,1.65)
## 5 1.07 (0.54,2.12)
## 6 0.7794 (0.3531,1.7202)
##
## academic_performance: ref.=Negative effect
## No change 0.39 (0.21,0.72)
## Positive effect 0.25 (0.15,0.43)
##
## trouble_sleeping: ref.=Maybe
## No 0.33 (0.2,0.56)
## Yes 2.68 (1.33,5.4)
##
## social_relationships: ref.=Negative effect
## No effect 0.21 (0.13,0.35)
## Positive effect 0.35 (0.19,0.66)
##
## eating_habits_how: ref.=both amount and type
## amount of food 1.6 (0.95,2.72)
## type of food 0.73 (0.41,1.31)
## no change 2.13 (0.28,16.34)
##
## smoking_habits: ref.=non-smoker
## smoker with no change 0.44 (0.16,1.21)
## smoker with reduced smoking 1656228.65 (0,Inf)
## started smoking 2.01 (0.27,15.22)
## stopped smoking 1656228.66 (0,Inf)
##
## sleep_quality: ref.=Fairly bad
## Fairly good 0.1 (0.04,0.29)
## Very bad 0.62 (0.14,2.82)
## Very good 0.07 (0.02,0.2)
##
## physical_activity: ref.=Less physical activity
## More physical activity 0.27 (0.15,0.48)
## No change 0.19 (0.11,0.32)
##
## adj. OR(95%CI)
## year: ref.=1
## 2 1.8 (0.73,4.44)
## 3 2.49 (0.88,7.04)
## 4 1.09 (0.5,2.38)
## 5 1.07 (0.49,2.33)
## 6 0.9967 (0.3875,2.5639)
##
## academic_performance: ref.=Negative effect
## No change 0.83 (0.41,1.69)
## Positive effect 0.38 (0.21,0.68)
##
## trouble_sleeping: ref.=Maybe
## No 0.5 (0.27,0.93)
## Yes 1.52 (0.68,3.4)
##
## social_relationships: ref.=Negative effect
## No effect 0.3 (0.17,0.54)
## Positive effect 0.45 (0.23,0.91)
##
## eating_habits_how: ref.=both amount and type
## amount of food 1.68 (0.93,3.04)
## type of food 0.8 (0.4,1.6)
## no change 3.26 (0.36,29.7)
##
## smoking_habits: ref.=non-smoker
## smoker with no change 0.42 (0.13,1.35)
## smoker with reduced smoking 4465945.32 (0,Inf)
## started smoking 0.84 (0.09,8.39)
## stopped smoking 1018933.78 (0,Inf)
##
## sleep_quality: ref.=Fairly bad
## Fairly good 0.17 (0.06,0.53)
## Very bad 0.53 (0.11,2.63)
## Very good 0.17 (0.05,0.57)
##
## physical_activity: ref.=Less physical activity
## More physical activity 0.55 (0.28,1.07)
## No change 0.26 (0.14,0.48)
##
## P(Wald's test) P(LR-test)
## year: ref.=1 0.363
## 2 0.205
## 3 0.085
## 4 0.833
## 5 0.861
## 6 0.995
##
## academic_performance: ref.=Negative effect 0.006
## No change 0.603
## Positive effect 0.001
##
## trouble_sleeping: ref.=Maybe 0.009
## No 0.028
## Yes 0.304
##
## social_relationships: ref.=Negative effect < 0.001
## No effect < 0.001
## Positive effect 0.025
##
## eating_habits_how: ref.=both amount and type 0.12
## amount of food 0.086
## type of food 0.533
## no change 0.295
##
## smoking_habits: ref.=non-smoker 0.359
## smoker with no change 0.145
## smoker with reduced smoking 0.99
## started smoking 0.885
## stopped smoking 0.992
##
## sleep_quality: ref.=Fairly bad 0.002
## Fairly good 0.002
## Very bad 0.439
## Very good 0.004
##
## physical_activity: ref.=Less physical activity < 0.001
## More physical activity 0.077
## No change < 0.001
##
## Log-likelihood = -211.7993
## No. of observations = 899
## AIC value = 471.5986
##Likert Graphs$$
library(tidyverse)
#preparing DASS data
Data = depression %>% dplyr::select(x1:x21) %>% mutate_all(as.character)
Data[Data == 0 ] <- "Did not apply to me at all"
Data[Data == 1 ] <- "Applied to me to some degree,or some of the time"
Data[Data == 2 ] <- "Applied to me to a considerable degree or a good part of time"
Data[Data == 3 ] <- "Applied to me very much or most of the time"
Data <- Data %>% mutate_all(as.factor)
mutate_order <- function(x) {
x <- factor(x , levels = c(
"Did not apply to me at all",
"Applied to me to some degree,or some of the time",
"Applied to me to a considerable degree or a good part of time",
"Applied to me very much or most of the time"),
ordered = TRUE)
return(x)
}
Data$x1 = mutate_order(Data$x1)
Data$x2 = mutate_order(Data$x2)
Data$x3 = mutate_order(Data$x3)
Data = as.data.frame(Data)
library(likert)
## Loading required package: xtable
##
## Attaching package: 'likert'
## The following object is masked from 'package:dplyr':
##
## recode
Result = likert(Data)
summary(Result)
## Item low neutral high mean sd
## 7 x7 33.20523 0 66.79477 3.114527 1.0982277
## 4 x4 36.20292 0 63.79708 3.068409 1.1275950
## 21 x21 36.27978 0 63.72022 2.741737 1.0659859
## 15 x15 40.35357 0 59.64643 2.819370 1.1329172
## 10 x10 40.66103 0 59.33897 2.610300 1.0602692
## 17 x17 41.27594 0 58.72406 2.628747 1.0740595
## 20 x20 41.96772 0 58.03228 2.757879 1.1424440
## 9 x9 42.58263 0 57.41737 2.703305 1.0966648
## 19 x19 42.58263 0 57.41737 2.695619 1.1473934
## 16 x16 47.42506 0 52.57494 2.400461 1.0206935
## 8 x8 47.65565 0 52.34435 2.451960 1.0422784
## 11 x11 47.80938 0 52.19062 2.362798 1.0071893
## 5 x5 48.34743 0 51.65257 2.347425 1.0239305
## 18 x18 48.42429 0 51.57571 2.526518 1.1053489
## 13 x13 48.96234 0 51.03766 2.331284 1.0069821
## 3 x3 52.03689 0 47.96311 2.510377 1.0958347
## 6 x6 52.11376 0 47.88624 2.456572 1.0929129
## 12 x12 55.18832 0 44.81168 2.398155 1.0545708
## 1 x1 58.41660 0 41.58340 2.345888 1.0169148
## 14 x14 59.26211 0 40.73789 2.323597 1.0665421
## 2 x2 76.63336 0 23.36664 1.826287 0.9886825
plot(Result,
type="bar")
