library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(MASS)
##
## Attaching package: 'MASS'
##
## The following object is masked from 'package:dplyr':
##
## select
library(readxl)
load("NSDUH_2023.Rdata")
#data<-read_excel("NSDUH_2023.Rdata")
model1<-lm(CABINGFLG~IRMARIT,data=data)
model2<-lm(CABINGFLG~IRMARIT+SEXIDENT22+CATAGE,data=data)
model3<-lm(CABINGFLG~IRMARIT+SEXIDENT22+CATAGE+SEXATRACT2+IMPSOC+SUICTHNK,data=data)
summary(model1)
##
## Call:
## lm(formula = CABINGFLG ~ IRMARIT, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.602 -0.597 -0.585 -0.044 84.956
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.6079489 0.0236906 25.662 < 2e-16 ***
## IRMARIT -0.0056991 0.0007594 -7.505 6.22e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.188 on 56703 degrees of freedom
## Multiple R-squared: 0.0009924, Adjusted R-squared: 0.0009748
## F-statistic: 56.33 on 1 and 56703 DF, p-value: 6.225e-14
model1<-lm(CABINGFLG~IRMARIT+SEXIDENT22+CATAGE,data=data)
model3<-lm(CABINGFLG~IRMARIT+SEXATRACT2+SEXIDENT22+CATAGE+IMPSOC+SUICTHNK,data=data)
plot(model1,which=1)
plot(model2,which=1)
plot(model3,which=1)
raintest(model1)
##
## Rainbow test
##
## data: model1
## Rain = 1.1736, df1 = 28353, df2 = 28348, p-value < 2.2e-16
raintest(model2)
##
## Rainbow test
##
## data: model2
## Rain = 1.1736, df1 = 28353, df2 = 28348, p-value < 2.2e-16
raintest(model3)
##
## Rainbow test
##
## data: model3
## Rain = 1.1735, df1 = 28353, df2 = 28345, p-value < 2.2e-16
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
## The following object is masked from 'package:purrr':
##
## some
durbinWatsonTest(model1)
## lag Autocorrelation D-W Statistic p-value
## 1 0.005743427 1.988513 0.226
## Alternative hypothesis: rho != 0
durbinWatsonTest(model2)
## lag Autocorrelation D-W Statistic p-value
## 1 0.005743427 1.988513 0.216
## Alternative hypothesis: rho != 0
durbinWatsonTest(model3)
## lag Autocorrelation D-W Statistic p-value
## 1 0.005878017 1.988244 0.208
## Alternative hypothesis: rho != 0
plot(model1,which=3)
plot(model2,which=3)
plot(model3,which=3)
bptest(model1)
##
## studentized Breusch-Pagan test
##
## data: model1
## BP = 24.282, df = 3, p-value = 2.181e-05
bptest(model2)
##
## studentized Breusch-Pagan test
##
## data: model2
## BP = 24.282, df = 3, p-value = 2.181e-05
bptest(model3)
##
## studentized Breusch-Pagan test
##
## data: model3
## BP = 28.267, df = 6, p-value = 8.367e-05
plot(model1,which=2)
plot(model2,which=2)
plot(model3,which=2)
model2<-lm(CABINGFLG~IRMARIT,data=data)
model3<-lm(CABINGFLG~IRMARIT+SEXATRACT2+SEXIDENT22+CATAGE+IMPSOC+SUICTHNK,data=data)
vif(model1)
## IRMARIT SEXIDENT22 CATAGE
## 1.358172 1.000097 1.358092
vif(model3)
## IRMARIT SEXATRACT2 SEXIDENT22 CATAGE IMPSOC SUICTHNK
## 1.702838 3.874218 3.859798 2.162600 1.793826 3.758425
model3<-data %>% dplyr::select(CABINGFLG, SEXATRACT2, SEXIDENT22, CATAGE, IMPSOC,SUICTHNK)
cor(model3)
## CABINGFLG SEXATRACT2 SEXIDENT22 CATAGE IMPSOC
## CABINGFLG 1.000000000 0.004871243 0.005210004 0.026001324 -0.02389414
## SEXATRACT2 0.004871243 1.000000000 0.859520749 0.001845605 0.15756520
## SEXIDENT22 0.005210004 0.859520749 1.000000000 0.001168330 0.16181291
## CATAGE 0.026001324 0.001845605 0.001168330 1.000000000 -0.40858320
## IMPSOC -0.023894140 0.157565201 0.161812905 -0.408583200 1.00000000
## SUICTHNK -0.034707310 0.218901394 0.215881056 -0.707459663 0.65982424
## SUICTHNK
## CABINGFLG -0.03470731
## SEXATRACT2 0.21890139
## SEXIDENT22 0.21588106
## CATAGE -0.70745966
## IMPSOC 0.65982424
## SUICTHNK 1.00000000
```