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(readxl)
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
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
loaded_objects <- load("NSDUH_2023.Rdata")
print(loaded_objects)
## [1] ".Random.seed" "data"
nsduh_2023 <- get(loaded_objects[1])
nsduh_2023<-data
nsduh_clean <- nsduh_2023 %>%
select(IRAMDEYR, BNGDRMDAYS, AGE3) %>%
drop_na(IRAMDEYR, BNGDRMDAYS, AGE3)
head(nsduh_clean)
## # A tibble: 6 × 3
## IRAMDEYR BNGDRMDAYS AGE3
## <dbl> <dbl> <dbl>
## 1 0 3 10
## 2 0 2 9
## 3 1 5 9
## 4 0 5 10
## 5 0 5 4
## 6 0 1 8
cordata<-data%>%select(IRAMDEYR,BNGDRMDAYS,AGE3) %>% drop_na(IRAMDEYR,BNGDRMDAYS,AGE3)
cor(cordata)
## IRAMDEYR BNGDRMDAYS AGE3
## IRAMDEYR 1.00000000 -0.02039946 -0.14357527
## BNGDRMDAYS -0.02039946 1.00000000 0.07372612
## AGE3 -0.14357527 0.07372612 1.00000000
H1:
H0:
nsduh_2023<- lm(BNGDRMDAYS ~AGE3+IRAMDEYR, data = data)
summary(nsduh_2023)
##
## Call:
## lm(formula = BNGDRMDAYS ~ AGE3 + IRAMDEYR, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.3006 -0.2503 0.7999 0.9004 1.0990
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.747937 0.027227 137.655 <2e-16 ***
## AGE3 0.050239 0.003297 15.240 <2e-16 ***
## IRAMDEYR -0.047917 0.022682 -2.113 0.0346 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.521 on 45130 degrees of freedom
## (11572 observations deleted due to missingness)
## Multiple R-squared: 0.005534, Adjusted R-squared: 0.00549
## F-statistic: 125.6 on 2 and 45130 DF, p-value: < 2.2e-16
plot(nsduh_2023)
durbinWatsonTest(nsduh_2023)
## lag Autocorrelation D-W Statistic p-value
## 1 -0.001579406 2.003139 0.716
## Alternative hypothesis: rho != 0
plot(nsduh_2023, which = 3)
plot(nsduh_2023, which = 2)
vif(nsduh_2023)
## AGE3 IRAMDEYR
## 1.021048 1.021048