Einlesen und Erstellen der Datensätze

MIDUS 3 Daten einlesen

agg = Data Set 1: Aggregate Data

dis = Data Set 2: Disposition Codes

cod = Data Set 3: Coded Text Data

load("~/Downloads/MIDUS 3/DS0001/36346-0001-Data.rda")
MIDUS3_agg <- da36346.0001 

load("~/Downloads/MIDUS 3/DS0002/36346-0002-Data.rda")
MIDUS3_dis <- da36346.0002

load("~/Downloads/MIDUS 3/DS0003/36346-0003-Data.rda")
MIDUS3_cod <- da36346.0003

rm(da36346.0001)
rm(da36346.0002)
rm(da36346.0003)

Dimensionen der Datensätze anschauen

dim(MIDUS3_agg)
## [1] 3294 2613
dim(MIDUS3_cod)
## [1] 3137  183
dim(MIDUS3_dis)
## [1] 7108    6

Zusammenführen der drei einzelnen Datensätze

MIDUS3_gesamt <- merge(MIDUS3_agg, MIDUS3_cod, by = "M2ID")
MIDUS3_gesamt <- merge(MIDUS3_gesamt, MIDUS3_dis, by = "M2ID")

MIDUS 3 Biomarker Project Daten einlesen

bio_agg = Dataset 1: Biomarker Aggregate Dataset

bio_med = Dataset 2: Biomarker Medication Stacked Dataset

=>Eigentlich benötigen wir für die Fragestellung nur MIDUS3_bio_agg

load("~/Downloads/MIDUS 3 Biomarker Project/DS0001/38837-0001-Data.rda")
MIDUS3_bio <- da38837.0001

load("~/Downloads/MIDUS 3 Biomarker Project/DS0002/38837-0002-Data.rda")
MIDUS3_bio_med<- da38837.0002
MIDUS3_bio_med <- MIDUS3_bio_med[!duplicated(MIDUS3_bio_med), ]

rm(da38837.0001)
rm(da38837.0002)

Datesätze mit den relevanten Variablen für die Fragestellung erstellen

MIDUS3 <- MIDUS3_gesamt[,c('M2ID','C1PRAGE.x','B1PGENDER','C1SOPTIM','C1SPESSI','C1SORIEN','C1PDEPRE','C1PDEPAF','C1PB1')]

MIDUS3_bio <- MIDUS3_bio[,c('M2ID','C1PRAGE','C1PRSEX','C4QCESD','C4QCESDDA','C4QCESDPA','C4QCESDSC','C4QCESDI')]

Beide Datensätze zusammenführen

MIDUS <- merge(MIDUS3,MIDUS3_bio,by = 'M2ID')

any(is.na(MIDUS))
## [1] TRUE
sum(is.na(MIDUS))
## [1] 47

Bildung in eine numerische Zahl umwandeln

str(MIDUS$C1PB1)
##  Factor w/ 12 levels "(01) NO SCHOOL/SOME GRADE SCHOOL (1-6)",..: 9 12 8 5 9 11 9 11 9 9 ...
MIDUS$C1PB1_num <- as.numeric(as.character(MIDUS$C1PB1))
## Warning: NAs introduced by coercion
unique(MIDUS$C1PB1)
##  [1] (09) GRADUATED FROM A 4- OR 5-YEAR COLLEGE, OR BACHELOR'S DEG.    
##  [2] (12) PH.D., ED.D., MD, DDS, LLB, LLD, JD, OR OTHER PROFESS'NL DEG.
##  [3] (08) GRAD. FROM 2-YEAR COLLEGE, VOCATIONAL SCHOOL, OR ASSOC. DEG. 
##  [4] (05) GRADUATED FROM HIGH SCHOOL                                   
##  [5] (11) MASTER'S DEGREE                                              
##  [6] (06) 1 TO 2 YEARS OF COLLEGE, NO DEGREE YET                       
##  [7] (03) SOME HIGH SCHOOL (9-12 NO DIPLOMA/NO GED)                    
##  [8] (07) 3 OR MORE YEARS OF COLLEGE, NO DEGREE YET                    
##  [9] (04) GED                                                          
## [10] (10) SOME GRADUATE SCHOOL                                         
## [11] (02) EIGHTH GRADE/JUNIOR HIGH SCHOOL (7-8)                        
## 12 Levels: (01) NO SCHOOL/SOME GRADE SCHOOL (1-6) ...
MIDUS$C1PB1_num <- NULL

Extrahieren der Zahl in den Klammern

MIDUS$edu <- as.numeric(sub("^\\((\\d+)\\).*", "\\1", MIDUS$C1PB1))
table(MIDUS$edu, useNA = "ifany")
## 
##   2   3   4   5   6   7   8   9  10  11  12 
##   2  12   7 103  99  21  70 147  19 108  34

##Spaltennamen ändern

names(MIDUS) <- c("id", "age", "gender", "optimism", 'pessimism','lotr','depression+anhedonia','depressedaffect','education_level','age_bio','sex','cesd','cesdda','cesdpa','cesdsc','cesdi','education')

cols <- names(MIDUS)
cols <- cols[cols != "education"]         
cols <- append(cols, "education", after = 9)
MIDUS <- MIDUS[, cols]
rm(cols)

Deskreptive Statistik des Datensatzes

library(psych)
library(knitr)
kable(describe(MIDUS), caption = "Deskriptive Statistiken", digits = 2)
Deskriptive Statistiken
vars n mean sd median trimmed mad min max range skew kurtosis se
id 1 622 14619.10 2704.84 14653.5 14627.76 3592.34 10019 19193 9174 -0.02 -1.25 108.45
age 2 622 61.00 9.74 60.0 60.63 10.38 43 90 47 0.35 -0.42 0.39
gender* 3 622 1.56 0.50 2.0 1.57 0.00 1 2 1 -0.24 -1.95 0.02
optimism 4 608 11.98 2.36 12.0 12.21 2.97 3 15 12 -0.87 0.66 0.10
pessimism 5 608 5.86 2.72 5.0 5.51 2.97 3 15 12 0.95 0.41 0.11
lotr 6 608 24.12 4.47 25.0 24.55 4.45 7 30 23 -0.89 0.58 0.18
depression+anhedonia 7 622 0.67 1.81 0.0 0.11 0.00 0 7 7 2.54 4.87 0.07
depressedaffect 8 622 0.53 1.68 0.0 0.00 0.00 0 7 7 3.00 7.48 0.07
education_level* 9 622 8.03 2.40 8.0 8.04 2.97 2 12 10 -0.10 -1.06 0.10
education 10 622 8.03 2.40 8.0 8.04 2.97 2 12 10 -0.10 -1.06 0.10
age_bio 11 622 61.00 9.74 60.0 60.63 10.38 43 90 47 0.35 -0.42 0.39
sex* 12 622 1.56 0.50 2.0 1.57 0.00 1 2 1 -0.24 -1.95 0.02
cesd 13 621 8.40 7.32 6.0 7.33 5.93 0 45 45 1.48 2.54 0.29
cesdda 14 621 1.75 2.74 1.0 1.15 1.48 0 17 17 2.32 6.22 0.11
cesdpa 15 621 9.38 2.69 10.0 9.77 2.97 0 12 12 -1.00 0.28 0.11
cesdsc 16 621 3.66 3.02 3.0 3.33 2.97 0 16 16 0.99 0.64 0.12
cesdi 17 621 0.36 0.77 0.0 0.17 0.00 0 5 5 2.46 6.70 0.03
kable(summary(MIDUS), caption = "Deskriptive Statistiken", digits = 2)
Deskriptive Statistiken
id age gender optimism pessimism lotr depression+anhedonia depressedaffect education_level education age_bio sex cesd cesdda cesdpa cesdsc cesdi
Min. :10019 Min. :43 (1) MALE :274 Min. : 3.00 Min. : 3.000 Min. : 7.00 Min. :0.0000 Min. :0.0000 (09) GRADUATED FROM A 4- OR 5-YEAR COLLEGE, OR BACHELOR’S DEG. :147 Min. : 2.000 Min. :43 (1) MALE :274 Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. :0.0000
1st Qu.:12167 1st Qu.:54 (2) FEMALE:348 1st Qu.:11.00 1st Qu.: 3.000 1st Qu.:21.00 1st Qu.:0.0000 1st Qu.:0.0000 (11) MASTER’S DEGREE :108 1st Qu.: 6.000 1st Qu.:54 (2) FEMALE:348 1st Qu.: 3.000 1st Qu.: 0.000 1st Qu.: 8.000 1st Qu.: 1.000 1st Qu.:0.0000
Median :14654 Median :60 NA Median :12.00 Median : 5.000 Median :25.00 Median :0.0000 Median :0.0000 (05) GRADUATED FROM HIGH SCHOOL :103 Median : 8.000 Median :60 NA Median : 6.000 Median : 1.000 Median :10.000 Median : 3.000 Median :0.0000
Mean :14619 Mean :61 NA Mean :11.98 Mean : 5.863 Mean :24.12 Mean :0.6656 Mean :0.5322 (06) 1 TO 2 YEARS OF COLLEGE, NO DEGREE YET : 99 Mean : 8.027 Mean :61 NA Mean : 8.395 Mean : 1.749 Mean : 9.378 Mean : 3.662 Mean :0.3639
3rd Qu.:17040 3rd Qu.:67 NA 3rd Qu.:14.00 3rd Qu.: 7.000 3rd Qu.:28.00 3rd Qu.:0.0000 3rd Qu.:0.0000 (08) GRAD. FROM 2-YEAR COLLEGE, VOCATIONAL SCHOOL, OR ASSOC. DEG. : 70 3rd Qu.:10.000 3rd Qu.:67 NA 3rd Qu.:12.000 3rd Qu.: 2.000 3rd Qu.:12.000 3rd Qu.: 5.000 3rd Qu.:0.0000
Max. :19193 Max. :90 NA Max. :15.00 Max. :15.000 Max. :30.00 Max. :7.0000 Max. :7.0000 (12) PH.D., ED.D., MD, DDS, LLB, LLD, JD, OR OTHER PROFESS’NL DEG.: 34 Max. :12.000 Max. :90 NA Max. :45.000 Max. :17.000 Max. :12.000 Max. :16.000 Max. :5.0000
NA NA NA NA’s :14 NA’s :14 NA’s :14 NA NA (Other) : 61 NA NA NA NA’s :1 NA’s :1 NA’s :1 NA’s :1 NA’s :1
cor(MIDUS[, c("age", "optimism", "pessimism","depressedaffect","education","cesd")], method = "pearson", use = "pairwise.complete.obs")
##                         age    optimism  pessimism depressedaffect   education
## age              1.00000000  0.15008883 -0.1558680     -0.12729081 -0.04765306
## optimism         0.15008883  1.00000000 -0.5463875     -0.17337870  0.05802677
## pessimism       -0.15586799 -0.54638752  1.0000000      0.25112815 -0.20982539
## depressedaffect -0.12729081 -0.17337870  0.2511282      1.00000000 -0.02201579
## education       -0.04765306  0.05802677 -0.2098254     -0.02201579  1.00000000
## cesd            -0.10080345 -0.35679774  0.3730952      0.34613199 -0.10960558
##                       cesd
## age             -0.1008035
## optimism        -0.3567977
## pessimism        0.3730952
## depressedaffect  0.3461320
## education       -0.1096056
## cesd             1.0000000
corr.test(MIDUS[, c("age", "optimism", "pessimism","depressedaffect","education","cesd")], method = "pearson", use = "pairwise.complete.obs")
## Call:corr.test(x = MIDUS[, c("age", "optimism", "pessimism", "depressedaffect", 
##     "education", "cesd")], use = "pairwise.complete.obs", method = "pearson")
## Correlation matrix 
##                   age optimism pessimism depressedaffect education  cesd
## age              1.00     0.15     -0.16           -0.13     -0.05 -0.10
## optimism         0.15     1.00     -0.55           -0.17      0.06 -0.36
## pessimism       -0.16    -0.55      1.00            0.25     -0.21  0.37
## depressedaffect -0.13    -0.17      0.25            1.00     -0.02  0.35
## education       -0.05     0.06     -0.21           -0.02      1.00 -0.11
## cesd            -0.10    -0.36      0.37            0.35     -0.11  1.00
## Sample Size 
##                 age optimism pessimism depressedaffect education cesd
## age             622      608       608             622       622  621
## optimism        608      608       608             608       608  607
## pessimism       608      608       608             608       608  607
## depressedaffect 622      608       608             622       622  621
## education       622      608       608             622       622  621
## cesd            621      607       607             621       621  621
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##                  age optimism pessimism depressedaffect education cesd
## age             0.00     0.00         0            0.01      0.47 0.05
## optimism        0.00     0.00         0            0.00      0.46 0.00
## pessimism       0.00     0.00         0            0.00      0.00 0.00
## depressedaffect 0.00     0.00         0            0.00      0.58 0.00
## education       0.24     0.15         0            0.58      0.00 0.03
## cesd            0.01     0.00         0            0.00      0.01 0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

Hypothese 1 prüfen

cor_result_opt_dep <- cor.test(MIDUS$optimism, MIDUS$cesd, method = "pearson")
cor_result_opt_dep
## 
##  Pearson's product-moment correlation
## 
## data:  MIDUS$optimism and MIDUS$cesd
## t = -9.3944, df = 605, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.4243303 -0.2853180
## sample estimates:
##        cor 
## -0.3567977

Effektstärke (r) und 95%-Konfidenzintervall ausgeben

r_value_opt_dep <- cor_result_opt_dep$estimate
ci_lower_opt_dep <- cor_result_opt_dep$conf.int[1]
ci_upper_opt_dep <- cor_result_opt_dep$conf.int[2]

cat("Korrelationskoeffizient r =", round(r_value_opt_dep, 2), "\n")
## Korrelationskoeffizient r = -0.36
cat("95%-Konfidenzintervall: [", round(ci_lower_opt_dep, 2), ",", round(ci_upper_opt_dep, 3), "]\n")
## 95%-Konfidenzintervall: [ -0.42 , -0.285 ]

=>Die erste Hypothese ist mit einem p-Wert < 2.2e-16 signifikant

=>Die Korrelation von Optimismus und Depression liegt bei -0,36

Aus Interesse anschauen, wie Optimismus mit Bildung korreliert ist

cor_result_opt_edu <- cor.test(MIDUS$optimism, MIDUS$education, method = "pearson")
cor_result_opt_edu
## 
##  Pearson's product-moment correlation
## 
## data:  MIDUS$optimism and MIDUS$education
## t = 1.4309, df = 606, p-value = 0.153
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.02158848  0.13691070
## sample estimates:
##        cor 
## 0.05802677
cor_result_opt_pes <- cor.test(MIDUS$optimism, MIDUS$pessimism, method = "pearson")
cor_result_opt_pes
## 
##  Pearson's product-moment correlation
## 
## data:  MIDUS$optimism and MIDUS$pessimism
## t = -16.06, df = 606, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.5998422 -0.4880770
## sample estimates:
##        cor 
## -0.5463875

Effektstärke (r) und 95%-Konfidenzintervall für die ausgeben

r_value_opt_edu <- cor_result_opt_edu$estimate
ci_lower_opt_edu <- cor_result_opt_edu$conf.int[1]
ci_upper_opt_edu <- cor_result_opt_edu$conf.int[2]

cat("Korrelationskoeffizient r =", round(r_value_opt_edu, 2), "\n")
## Korrelationskoeffizient r = 0.06
cat("95%-Konfidenzintervall: [", round(ci_lower_opt_edu, 2), ",", round(ci_upper_opt_edu, 3), "]\n")
## 95%-Konfidenzintervall: [ -0.02 , 0.137 ]

=>Korrelation von Optimismus und Bildung nicht signifikant

Aus Interesse anschauen, wie Depression mit Bildung korreliert ist

cor_result_dep_edu <- cor.test(MIDUS$education, MIDUS$cesd, method = "pearson")
cor_result_dep_edu
## 
##  Pearson's product-moment correlation
## 
## data:  MIDUS$education and MIDUS$cesd
## t = -2.7435, df = 619, p-value = 0.006255
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.18667414 -0.03119624
## sample estimates:
##        cor 
## -0.1096056

Effektstärke (r) und 95%-Konfidenzintervall für die ausgeben

r_value_dep_edu <- cor_result_dep_edu$estimate
ci_lower_dep_edu <- cor_result_dep_edu$conf.int[1]
ci_upper_dep_edu <- cor_result_dep_edu$conf.int[2]

cat("Korrelationskoeffizient r =", round(r_value_dep_edu, 2), "\n")
## Korrelationskoeffizient r = -0.11
cat("95%-Konfidenzintervall: [", round(ci_lower_dep_edu, 2), ",", round(ci_upper_dep_edu, 3), "]\n")
## 95%-Konfidenzintervall: [ -0.19 , -0.031 ]

=>Korrelation von Depression und Bildung ist signifikant und liegt bei ca. -0.11

Aus Interesse anschauen, wie Alter mit Optimismus korreliert ist

cor_result_opt_age <- cor.test(MIDUS$optimism, MIDUS$age, method = "pearson")
cor_result_opt_age
## 
##  Pearson's product-moment correlation
## 
## data:  MIDUS$optimism and MIDUS$age
## t = 3.7371, df = 606, p-value = 0.0002038
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.07142561 0.22689659
## sample estimates:
##       cor 
## 0.1500888

Aus Interesse anschauen, wie Alter mit Bildung korreliert ist

cor_result_edu_age <- cor.test(MIDUS$education, MIDUS$age, method = "pearson")
cor_result_edu_age
## 
##  Pearson's product-moment correlation
## 
## data:  MIDUS$education and MIDUS$age
## t = -1.1879, df = 620, p-value = 0.2353
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.12579684  0.03107841
## sample estimates:
##         cor 
## -0.04765306

Neues Package installieren, um später den Johnson-Neyman-Test durchführen zu können und Plots abzubilden

library(interactions)
library(effectsize)
## 
## Attaching package: 'effectsize'
## The following object is masked from 'package:psych':
## 
##     phi
library(apaTables)

Hypothese 2 prüfen

Variable zentrieren, Zentrierung ohne Standardisierung

MIDUS$optimism_z <- scale(MIDUS$optimism, scale = FALSE)
MIDUS$education_z <- scale(MIDUS$education, scale = FALSE)

Hierarchische Regression

Modell 1: Hauptmodell ohne Interaktion

modell1 <- lm(cesd ~ optimism_z + education_z, data = MIDUS)
summary(modell1)
## 
## Call:
## lm(formula = cesd ~ optimism_z + education_z, data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -15.699  -4.614  -1.595   3.077  35.749 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   8.4363     0.2788  30.259   <2e-16 ***
## optimism_z   -1.1031     0.1187  -9.296   <2e-16 ***
## education_z  -0.2765     0.1178  -2.346   0.0193 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.869 on 604 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.1352, Adjusted R-squared:  0.1323 
## F-statistic: 47.21 on 2 and 604 DF,  p-value: < 2.2e-16
standardize_parameters(modell1)
## # Standardization method: refit
## 
## Parameter   | Std. Coef. |         95% CI
## -----------------------------------------
## (Intercept) |  -3.14e-16 | [-0.07,  0.07]
## optimism z  |      -0.35 | [-0.43, -0.28]
## education z |      -0.09 | [-0.16, -0.01]
library(broom)
tidy_mod1 <- broom::tidy(modell1)
kable(tidy_mod1, caption = "Regressionsoutput Modell 1")
Regressionsoutput Modell 1
term estimate std.error statistic p.value
(Intercept) 8.4362595 0.2787976 30.259444 0.0000000
optimism_z -1.1031373 0.1186637 -9.296336 0.0000000
education_z -0.2764515 0.1178313 -2.346164 0.0192901
library(gtsummary)
modell1 %>% tbl_regression()
Characteristic Beta 95% CI p-value
optimism_z -1.1 -1.3, -0.87 <0.001
education_z -0.28 -0.51, -0.05 0.019
Abbreviation: CI = Confidence Interval

95%-Konfidenzintervall berechnen

confint(modell1)
##                  2.5 %      97.5 %
## (Intercept)  7.8887291  8.98378986
## optimism_z  -1.3361808 -0.87009379
## education_z -0.5078602 -0.04504274

Effektsärke berechnen

library(effectsize)
standardize_parameters(modell1) 
## # Standardization method: refit
## 
## Parameter   | Std. Coef. |         95% CI
## -----------------------------------------
## (Intercept) |  -3.14e-16 | [-0.07,  0.07]
## optimism z  |      -0.35 | [-0.43, -0.28]
## education z |      -0.09 | [-0.16, -0.01]
summary(modell1)$r.squared      
## [1] 0.135186
summary(modell1)$adj.r.squared
## [1] 0.1323224

ANOVA berechnen

modell1.1 <- anova(modell1)
kable(modell1.1, caption = "ANOVA-Tabelle Modell 1")
ANOVA-Tabelle Modell 1
Df Sum Sq Mean Sq F value Pr(>F)
optimism_z 1 4194.7955 4194.7955 88.911600 0.0000000
education_z 1 259.6983 259.6983 5.504486 0.0192901
Residuals 604 28496.3548 47.1794 NA NA

Modell 2: Modell mit Interaktion

modell2 <- lm(cesd ~ optimism_z * education_z, data = MIDUS)
summary(modell2)
## 
## Call:
## lm(formula = cesd ~ optimism_z * education_z, data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.213  -4.617  -1.553   3.059  35.801 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             8.42469    0.27922  30.172   <2e-16 ***
## optimism_z             -1.09807    0.11885  -9.239   <2e-16 ***
## education_z            -0.27302    0.11793  -2.315   0.0209 *  
## optimism_z:education_z  0.04014    0.04843   0.829   0.4076    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.871 on 603 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.1362, Adjusted R-squared:  0.1319 
## F-statistic: 31.68 on 3 and 603 DF,  p-value: < 2.2e-16
standardize_parameters(modell2)
## # Standardization method: refit
## 
## Parameter                | Std. Coef. |         95% CI
## ------------------------------------------------------
## (Intercept)              |  -1.56e-03 | [-0.08,  0.07]
## optimism z               |      -0.35 | [-0.43, -0.28]
## education z              |      -0.09 | [-0.16, -0.01]
## optimism z × education z |       0.03 | [-0.04,  0.10]
tidy_mod2 <- broom::tidy(modell2)
kable(tidy_mod2, caption = "Regressionsoutput Modell 2")
Regressionsoutput Modell 2
term estimate std.error statistic p.value
(Intercept) 8.4246905 0.2792190 30.1723372 0.0000000
optimism_z -1.0980709 0.1188518 -9.2389967 0.0000000
education_z -0.2730171 0.1179346 -2.3149864 0.0209485
optimism_z:education_z 0.0401365 0.0484288 0.8287734 0.4075606

95%-Konfidenzintervall berechnen

confint(modell1)
##                  2.5 %      97.5 %
## (Intercept)  7.8887291  8.98378986
## optimism_z  -1.3361808 -0.87009379
## education_z -0.5078602 -0.04504274

Effektsärke berechnen

library(effectsize)
standardize_parameters(modell2) 
## # Standardization method: refit
## 
## Parameter                | Std. Coef. |         95% CI
## ------------------------------------------------------
## (Intercept)              |  -1.56e-03 | [-0.08,  0.07]
## optimism z               |      -0.35 | [-0.43, -0.28]
## education z              |      -0.09 | [-0.16, -0.01]
## optimism z × education z |       0.03 | [-0.04,  0.10]
summary(modell2)$r.squared      
## [1] 0.13617
summary(modell2)$adj.r.squared
## [1] 0.1318723

ANOVA berechnen

modell2.1 <- anova(modell2)
kable(modell2.1, caption = "ANOVA-Tabelle Modell 2")
ANOVA-Tabelle Modell 2
Df Sum Sq Mean Sq F value Pr(>F)
optimism_z 1 4194.7955 4194.79551 88.8655047 0.0000000
education_z 1 259.6983 259.69833 5.5016324 0.0193218
optimism_z:education_z 1 32.4227 32.42270 0.6868653 0.4075606
Residuals 603 28463.9321 47.20387 NA NA

Interaktionsplot für Modell 2

interact_plot(modell2, pred = "optimism_z", modx = "education_z")

Testen, ob das Modell mit Interaktion signifikant besser passt

modell_ges <- anova(modell1,modell2)
kable(modell_ges, caption = "ANOVA-Tabelle")
ANOVA-Tabelle
Res.Df RSS Df Sum of Sq F Pr(>F)
604 28496.35 NA NA NA NA
603 28463.93 1 32.4227 0.6868653 0.4075606
r2_diff <- summary(modell2)$r.squared - summary(modell1)$r.squared
cat("R²-Zuwachs durch Interaktion:", round(r2_diff, 4))
## R²-Zuwachs durch Interaktion: 0.001

=>Hypothese 2 kann nicht bestätigt werden, da das Modell mit Interaktion nicht signifikant besser passt.

Johnson Neyman Test durchführen

johnson_neyman(modell2, pred = "optimism_z", modx = "education_z")
## JOHNSON-NEYMAN INTERVAL
## 
## When education_z is INSIDE the interval [-19.93, 7.77], the slope of
## optimism_z is p < .05.
## 
## Note: The range of observed values of education_z is [-6.03, 3.97]

=>Optimismus wirkt über alle Bildungslevel hinweg signifikant – ohne wesentliche Veränderung je nach Bildung, also ist es nicht sinnvoll die Interaktion in das Regressionmodell aufzunehmen, da sie keine zusätzliche Varianzaufklärung bietet

Für depressive Symptome zum Zeitpunkt der Erhebung des Optimismus kontrollieren

modell1_kon <- lm(cesd ~ optimism_z + education_z + depressedaffect, data = MIDUS)
summary(modell1_kon)
## 
## Call:
## lm(formula = cesd ~ optimism_z + education_z + depressedaffect, 
##     data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.052  -4.393  -1.479   2.831  30.137 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       7.7513     0.2773  27.953  < 2e-16 ***
## optimism_z       -0.9395     0.1143  -8.217 1.28e-15 ***
## education_z      -0.2627     0.1118  -2.349   0.0191 *  
## depressedaffect   1.3387     0.1625   8.238 1.09e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.517 on 603 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.2227, Adjusted R-squared:  0.2188 
## F-statistic: 57.58 on 3 and 603 DF,  p-value: < 2.2e-16
standardize_parameters(modell1_kon)
## # Standardization method: refit
## 
## Parameter       | Std. Coef. |         95% CI
## ---------------------------------------------
## (Intercept)     |  -3.47e-16 | [-0.07,  0.07]
## optimism z      |      -0.30 | [-0.37, -0.23]
## education z     |      -0.08 | [-0.16, -0.01]
## depressedaffect |       0.30 | [ 0.23,  0.37]
tidy_mod1_kon <- broom::tidy(modell1_kon)
kable(tidy_mod1_kon, caption = "Regressionsoutput Modell 1 (kontrolliert für Depressivität T1)")
Regressionsoutput Modell 1 (kontrolliert für Depressivität T1)
term estimate std.error statistic p.value
(Intercept) 7.7513382 0.2772946 27.953438 0.0000000
optimism_z -0.9395024 0.1143330 -8.217249 0.0000000
education_z -0.2626933 0.1118171 -2.349314 0.0191297
depressedaffect 1.3386893 0.1624947 8.238357 0.0000000
modell1.1_kon <- anova(modell1_kon)
kable(modell1.1_kon, caption = "ANOVA-Tabelle Modell 1 (kontrolliert für Depressivität T1)")
ANOVA-Tabelle Modell 1 (kontrolliert für Depressivität T1)
Df Sum Sq Mean Sq F value Pr(>F)
optimism_z 1 4194.7955 4194.79551 98.755250 0.000000
education_z 1 259.6983 259.69833 6.113903 0.013687
depressedaffect 1 2882.9147 2882.91470 67.870523 0.000000
Residuals 603 25613.4401 42.47668 NA NA
modell2_kon <- lm(cesd ~ optimism_z * education_z + depressedaffect, data = MIDUS)
summary(modell2_kon)
## 
## Call:
## lm(formula = cesd ~ optimism_z * education_z + depressedaffect, 
##     data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.052  -4.306  -1.298   2.930  30.142 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             7.73642    0.27768  27.861  < 2e-16 ***
## optimism_z             -0.93326    0.11449  -8.151 2.10e-15 ***
## education_z            -0.25867    0.11188  -2.312   0.0211 *  
## depressedaffect         1.34154    0.16251   8.255 9.64e-16 ***
## optimism_z:education_z  0.04668    0.04595   1.016   0.3100    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.517 on 602 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.224,  Adjusted R-squared:  0.2189 
## F-statistic: 43.45 on 4 and 602 DF,  p-value: < 2.2e-16
standardize_parameters(modell2_kon)
## # Standardization method: refit
## 
## Parameter                | Std. Coef. |         95% CI
## ------------------------------------------------------
## (Intercept)              |  -1.81e-03 | [-0.07,  0.07]
## optimism z               |      -0.30 | [-0.37, -0.23]
## education z              |      -0.08 | [-0.15, -0.01]
## depressedaffect          |       0.30 | [ 0.23,  0.37]
## optimism z × education z |       0.04 | [-0.03,  0.10]
tidy_mod2_kon <- broom::tidy(modell2_kon)
kable(tidy_mod2_kon, caption = "Regressionsoutput Modell 2 (kontrolliert für Depressivität T1)")
Regressionsoutput Modell 2 (kontrolliert für Depressivität T1)
term estimate std.error statistic p.value
(Intercept) 7.7364236 0.2776754 27.861391 0.0000000
optimism_z -0.9332612 0.1144948 -8.151125 0.0000000
education_z -0.2586694 0.1118842 -2.311939 0.0211176
depressedaffect 1.3415398 0.1625146 8.254891 0.0000000
optimism_z:education_z 0.0466838 0.0459455 1.016069 0.3100048
modell2.1_kon <- anova(modell2_kon)
kable(modell2.1_kon, caption = "ANOVA-Tabelle Modell 2 (kontrolliert für Depressivität T1)")
ANOVA-Tabelle Modell 2 (kontrolliert für Depressivität T1)
Df Sum Sq Mean Sq F value Pr(>F)
optimism_z 1 4194.7955 4194.7955 98.760556 0.0000000
education_z 1 259.6983 259.6983 6.114232 0.0136849
depressedaffect 1 2882.9147 2882.9147 67.874169 0.0000000
optimism_z:education_z 1 43.8504 43.8504 1.032396 0.3100048
Residuals 602 25569.5897 42.4744 NA NA

Testen ob das Modell mit Interaktion signifikant besser passt

modell_ges_kon <- anova(modell1_kon,modell2_kon)
kable(modell_ges_kon, caption = "ANOVA-Tabelle (kontrolliert für Depressivität T1)")
ANOVA-Tabelle (kontrolliert für Depressivität T1)
Res.Df RSS Df Sum of Sq F Pr(>F)
603 25613.44 NA NA NA NA
602 25569.59 1 43.8504 1.032396 0.3100048
r2_diff_kon <- summary(modell2_kon)$r.squared - summary(modell1_kon)$r.squared
cat("R²-Zuwachs durch Interaktion:", round(r2_diff_kon, 4))
## R²-Zuwachs durch Interaktion: 0.0013

=>Auch wenn für depressive Symptome zum Zeitpunkt T1 kontrolliert wird, ist der Effekt der Interaktion von SES und Optimismus nicht signifikant

Hypothese 2a überprüfen

library(interactions)
slopes <- sim_slopes(modell2, pred = "optimism_z", modx = "education_z")
slopes.table <- slopes$slopes
print(slopes.table)
##   Value of education_z      Est.      S.E.      2.5%      97.5%    t val.
## 1          -2.35890961 -1.192749 0.1605603 -1.508074 -0.8774240 -7.428670
## 2           0.01220753 -1.097581 0.1188836 -1.331057 -0.8641047 -9.232398
## 3           2.38332466 -1.002413 0.1698794 -1.336040 -0.6687856 -5.900732
##              p
## 1 3.767659e-13
## 2 4.444688e-19
## 3 6.037482e-09
slopes_df <- as.data.frame(slopes$slopes)
slopes_df
##   Value of education_z      Est.      S.E.      2.5%      97.5%    t val.
## 1          -2.35890961 -1.192749 0.1605603 -1.508074 -0.8774240 -7.428670
## 2           0.01220753 -1.097581 0.1188836 -1.331057 -0.8641047 -9.232398
## 3           2.38332466 -1.002413 0.1698794 -1.336040 -0.6687856 -5.900732
##              p
## 1 3.767659e-13
## 2 4.444688e-19
## 3 6.037482e-09

Alle Effekte sind signifikant negativ → mehr Optimismus = weniger depressive Symptome – für alle SES-Niveaus.

->Aber: Der Effekt wird schwächer, je höher der SES (von -1.19 → -1.10 → -1.00).

->Der Effekt von Optimismus auf Depression ist bei niedriger Bildung stärker, nicht bei hoher.

=>Somit ist auch Hypothese 2a nicht signifikant, allerdings zeigt sich ein gegenteiliger Effekt, nämlich, dass Optimismus bei niedrigem SES stärker wirkt.

Hypothese 3 prüfen

Variable zentrieren, Zentrierung ohne Standardisierung

MIDUS$age_z <- scale(MIDUS$age, scale = FALSE)

Hierarchische Regression

Modell 1: Hauptmodell ohne Interaktion

modell1_age <- lm(cesd ~ optimism_z + age_z, data = MIDUS)
summary(modell1_age)
## 
## Call:
## lm(formula = cesd ~ optimism_z + age_z, data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -15.608  -4.647  -1.482   3.288  34.944 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  8.43546    0.27965  30.164   <2e-16 ***
## optimism_z  -1.09199    0.12037  -9.072   <2e-16 ***
## age_z       -0.03918    0.02916  -1.343     0.18    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.89 on 604 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.1299, Adjusted R-squared:  0.127 
## F-statistic: 45.09 on 2 and 604 DF,  p-value: < 2.2e-16
standardize_parameters(modell1_age)
## # Standardization method: refit
## 
## Parameter   | Std. Coef. |         95% CI
## -----------------------------------------
## (Intercept) |  -3.25e-16 | [-0.07,  0.07]
## optimism z  |      -0.35 | [-0.42, -0.27]
## age z       |      -0.05 | [-0.13,  0.02]
tidy_mod1_age <- broom::tidy(modell1_age)
kable(tidy_mod1_age, caption = "Regressionsoutput Modell 1")
Regressionsoutput Modell 1
term estimate std.error statistic p.value
(Intercept) 8.4354580 0.2796502 30.164323 0.0000000
optimism_z -1.0919895 0.1203682 -9.072077 0.0000000
age_z -0.0391805 0.0291645 -1.343435 0.1796358

95%-Konfidenzintervall berechnen

confint(modell1_age)
##                   2.5 %      97.5 %
## (Intercept)  7.88625326  8.98466280
## optimism_z  -1.32838054 -0.85559851
## age_z       -0.09645659  0.01809552

Effektsärke berechnen

library(effectsize)
standardize_parameters(modell1_age) 
## # Standardization method: refit
## 
## Parameter   | Std. Coef. |         95% CI
## -----------------------------------------
## (Intercept) |  -3.25e-16 | [-0.07,  0.07]
## optimism z  |      -0.35 | [-0.42, -0.27]
## age z       |      -0.05 | [-0.13,  0.02]
summary(modell1_age)$r.squared      
## [1] 0.1299046
summary(modell1_age)$adj.r.squared
## [1] 0.1270235

ANOVA berechnen

modell1.1_age <- anova(modell1_age)
kable(modell1.1_age, caption = "ANOVA-Tabelle Modell 1")
ANOVA-Tabelle Modell 1
Df Sum Sq Mean Sq F value Pr(>F)
optimism_z 1 4194.79551 4194.79551 88.371909 0.0000000
age_z 1 85.67015 85.67015 1.804816 0.1796358
Residuals 604 28670.38301 47.46752 NA NA

Modell 2: Modell mit Interaktion

modell2_age <- lm(cesd ~ optimism_z * age_z, data = MIDUS)
summary(modell2_age)
## 
## Call:
## lm(formula = cesd ~ optimism_z * age_z, data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.149  -4.796  -1.414   3.219  34.878 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       8.413759   0.283481  29.680   <2e-16 ***
## optimism_z       -1.086662   0.120959  -8.984   <2e-16 ***
## age_z            -0.039845   0.029216  -1.364    0.173    
## optimism_z:age_z  0.006038   0.012623   0.478    0.633    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.894 on 603 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.1302, Adjusted R-squared:  0.1259 
## F-statistic:  30.1 on 3 and 603 DF,  p-value: < 2.2e-16
standardize_parameters(modell2_age)
## # Standardization method: refit
## 
## Parameter          | Std. Coef. |         95% CI
## ------------------------------------------------
## (Intercept)        |  -2.94e-03 | [-0.08,  0.07]
## optimism z         |      -0.35 | [-0.42, -0.27]
## age z              |      -0.05 | [-0.13,  0.02]
## optimism z × age z |       0.02 | [-0.06,  0.10]
tidy_mod2_age <- broom::tidy(modell2_age)
kable(tidy_mod2_age, caption = "Regressionsoutput Modell 2")
Regressionsoutput Modell 2
term estimate std.error statistic p.value
(Intercept) 8.4137595 0.2834813 29.6801217 0.0000000
optimism_z -1.0866623 0.1209588 -8.9837365 0.0000000
age_z -0.0398453 0.0292162 -1.3638091 0.1731365
optimism_z:age_z 0.0060383 0.0126226 0.4783721 0.6325588

95%-Konfidenzintervall berechnen

confint(modell2_age)
##                        2.5 %      97.5 %
## (Intercept)       7.85702887  8.97049004
## optimism_z       -1.32421403 -0.84911051
## age_z            -0.09722303  0.01753252
## optimism_z:age_z -0.01875136  0.03082801

Effektsärke berechnen

library(effectsize)
standardize_parameters(modell2_age) 
## # Standardization method: refit
## 
## Parameter          | Std. Coef. |         95% CI
## ------------------------------------------------
## (Intercept)        |  -2.94e-03 | [-0.08,  0.07]
## optimism z         |      -0.35 | [-0.42, -0.27]
## age z              |      -0.05 | [-0.13,  0.02]
## optimism z × age z |       0.02 | [-0.06,  0.10]
summary(modell2_age)$r.squared      
## [1] 0.1302346
summary(modell2_age)$adj.r.squared
## [1] 0.1259075

ANOVA berechnen

modell2.1_age <- anova(modell2_age)
kable(modell2.1_age, caption = "ANOVA-Tabelle Modell 2")
ANOVA-Tabelle Modell 2
Df Sum Sq Mean Sq F value Pr(>F)
optimism_z 1 4194.79551 4194.79551 88.2590801 0.0000000
age_z 1 85.67015 85.67015 1.8025119 0.1799143
optimism_z:age_z 1 10.87635 10.87635 0.2288399 0.6325588
Residuals 603 28659.50667 47.52820 NA NA

Interaktionsplot für Modell 2

interact_plot(modell2_age, pred = "optimism_z", modx = "age_z")

### Testen, ob das Modell mit Interaktion signifikant besser passt

modell_ges_age <- anova(modell1_age,modell2_age)
kable(modell_ges_age, caption = "ANOVA-Tabelle")
ANOVA-Tabelle
Res.Df RSS Df Sum of Sq F Pr(>F)
604 28670.38 NA NA NA NA
603 28659.51 1 10.87635 0.2288399 0.6325588
r2_diff_age <- summary(modell2_age)$r.squared - summary(modell1_age)$r.squared
cat("R²-Zuwachs durch Interaktion:", round(r2_diff_age, 4))
## R²-Zuwachs durch Interaktion: 3e-04

Hypothese 3 nicht bestätigt, da die Interaktion mit Alter nicht signifikant zusätzliche Varianz aufklärt

Für depressive Symptome zum Zeitpunkt der Erhebung des Optimismus kontrollieren

modell1_age_kon <- lm(cesd ~ optimism_z + age_z + depressedaffect, data = MIDUS)
summary(modell1_age_kon)
## 
## Call:
## lm(formula = cesd ~ optimism_z + age_z + depressedaffect, data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.133  -4.602  -1.313   3.025  29.928 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      7.75125    0.27866  27.816  < 2e-16 ***
## optimism_z      -0.94317    0.11581  -8.144 2.20e-15 ***
## age_z           -0.01603    0.02785  -0.575    0.565    
## depressedaffect  1.33475    0.16403   8.137 2.32e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.545 on 603 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.216,  Adjusted R-squared:  0.2121 
## F-statistic: 55.38 on 3 and 603 DF,  p-value: < 2.2e-16
standardize_parameters(modell1_age_kon)
## # Standardization method: refit
## 
## Parameter       | Std. Coef. |         95% CI
## ---------------------------------------------
## (Intercept)     |  -3.55e-16 | [-0.07,  0.07]
## optimism z      |      -0.30 | [-0.37, -0.23]
## age z           |      -0.02 | [-0.09,  0.05]
## depressedaffect |       0.30 | [ 0.23,  0.37]
tidy_mod1_age_kon <- broom::tidy(modell1_age_kon)
kable(tidy_mod1_age_kon, caption = "Regressionsoutput Modell 1 (kontrolliert für Depressivität T1)")
Regressionsoutput Modell 1 (kontrolliert für Depressivität T1)
term estimate std.error statistic p.value
(Intercept) 7.7512507 0.2786641 27.8157520 0.0000000
optimism_z -0.9431651 0.1158065 -8.1443192 0.0000000
age_z -0.0160271 0.0278528 -0.5754226 0.5652202
depressedaffect 1.3347483 0.1640319 8.1371284 0.0000000
modell1.1_age_kon <- anova(modell1_age_kon)
kable(modell1.1_age_kon, caption = "ANOVA-Tabelle Modell 1 (kontrolliert für Depressivität T1)")
ANOVA-Tabelle Modell 1 (kontrolliert für Depressivität T1)
Df Sum Sq Mean Sq F value Pr(>F)
optimism_z 1 4194.79551 4194.79551 97.913275 0.0000000
age_z 1 85.67015 85.67015 1.999679 0.1578486
depressedaffect 1 2836.68788 2836.68788 66.212858 0.0000000
Residuals 603 25833.69513 42.84195 NA NA
modell2_age_kon <- lm(cesd ~ optimism_z * age_z + depressedaffect, data = MIDUS)
summary(modell2_age_kon)
## 
## Call:
## lm(formula = cesd ~ optimism_z * age_z + depressedaffect, data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.180  -4.618  -1.210   2.994  30.177 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       7.718447   0.282441  27.328  < 2e-16 ***
## optimism_z       -0.935157   0.116380  -8.035 4.94e-15 ***
## age_z            -0.016926   0.027892  -0.607    0.544    
## depressedaffect   1.337947   0.164156   8.150 2.11e-15 ***
## optimism_z:age_z  0.008672   0.011993   0.723    0.470    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.548 on 602 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.2167, Adjusted R-squared:  0.2115 
## F-statistic: 41.63 on 4 and 602 DF,  p-value: < 2.2e-16
standardize_parameters(modell2_age_kon)
## # Standardization method: refit
## 
## Parameter          | Std. Coef. |         95% CI
## ------------------------------------------------
## (Intercept)        |  -4.23e-03 | [-0.08,  0.07]
## optimism z         |      -0.30 | [-0.37, -0.23]
## age z              |      -0.02 | [-0.09,  0.05]
## depressedaffect    |       0.30 | [ 0.23,  0.37]
## optimism z × age z |       0.03 | [-0.05,  0.10]
tidy_mod2_age_kon <- broom::tidy(modell2_age_kon)
kable(tidy_mod2_age_kon, caption = "Regressionsoutput Modell 2 (kontrolliert für Depressivität T1)")
Regressionsoutput Modell 2 (kontrolliert für Depressivität T1)
term estimate std.error statistic p.value
(Intercept) 7.7184469 0.2824414 27.3276023 0.0000000
optimism_z -0.9351574 0.1163804 -8.0353489 0.0000000
age_z -0.0169263 0.0278915 -0.6068624 0.5441711
depressedaffect 1.3379470 0.1641564 8.1504401 0.0000000
optimism_z:age_z 0.0086724 0.0119933 0.7231027 0.4698976
modell2.1_age_kon <- anova(modell2_age_kon)
kable(modell2.1_age_kon, caption = "ANOVA-Tabelle Modell 2 (kontrolliert für Depressivität T1)")
ANOVA-Tabelle Modell 2 (kontrolliert für Depressivität T1)
Df Sum Sq Mean Sq F value Pr(>F)
optimism_z 1 4194.79551 4194.79551 97.8358013 0.0000000
age_z 1 85.67015 85.67015 1.9980969 0.1580137
depressedaffect 1 2836.68788 2836.68788 66.1604675 0.0000000
optimism_z:age_z 1 22.41883 22.41883 0.5228776 0.4698976
Residuals 602 25811.27629 42.87587 NA NA

Testen ob das Modell mit Interaktion signifikant besser passt

modell_age_ges_kon <- anova(modell1_age_kon,modell2_age_kon)
kable(modell_age_ges_kon, caption = "ANOVA-Tabelle (kontrolliert für Depressivität T1)")
ANOVA-Tabelle (kontrolliert für Depressivität T1)
Res.Df RSS Df Sum of Sq F Pr(>F)
603 25833.70 NA NA NA NA
602 25811.28 1 22.41883 0.5228776 0.4698976
r2_age_diff_kon <- summary(modell2_age_kon)$r.squared - summary(modell1_age_kon)$r.squared
cat("R²-Zuwachs durch Interaktion:", round(r2_age_diff_kon, 4))
## R²-Zuwachs durch Interaktion: 7e-04

Johnson Neyman Test durchführen

johnson_neyman(modell2_age, pred = "optimism_z", modx = "age_z")
## JOHNSON-NEYMAN INTERVAL
## 
## When age_z is INSIDE the interval [-58.07, 33.49], the slope of optimism_z
## is p < .05.
## 
## Note: The range of observed values of age_z is [-18.00, 29.00]

#### =>Der Zusammenhang zwischen Optimismus und depressiven Symptomen ist in allen Altersgruppen signifikant – unabhängig vom Alter #### Der Zusammenhang wird nicht durch das Alter abgeschwächt oder verstärkt. #### Es liegt keine bedeutsame Interaktion zwischen Optimismus und Alter vor.

Anschauen, ob diesselben Dinge für Pessimismus gelten

cor.test(MIDUS$pessimism, MIDUS$cesd, method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  MIDUS$pessimism and MIDUS$cesd
## t = 9.8911, df = 605, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.3024955 0.4396233
## sample estimates:
##       cor 
## 0.3730952
cor.test(MIDUS$pessimism, MIDUS$education, method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  MIDUS$pessimism and MIDUS$education
## t = -5.2829, df = 606, p-value = 1.776e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2845928 -0.1325208
## sample estimates:
##        cor 
## -0.2098254

Auch bei Pessimismus besteht eine Korrelation zu Depression, die signfikant ist und bei 0.37 liegt

Interessanterweise ist, im Gegensatz zu Optimismus, Pessimismus signifikant mit Bildung korreliert und zwar zu -0.21

Anschauen der Interaktion mit Bildung

Variable zentrieren, Zentrierung ohne Standardisierung

MIDUS$pessimism_z <- scale(MIDUS$pessimism, scale = FALSE)

Hierarchische Regression

Dabei für depressive Symptome zum Zeitpunkt der Erhebung des Optimismus kontrollieren

Modell 1: Hauptmodell ohne Interaktion

modell1_pes <- lm(cesd ~ pessimism_z + education_z +depressedaffect, data = MIDUS)
summary(modell1_pes)
## 
## Call:
## lm(formula = cesd ~ pessimism_z + education_z + depressedaffect, 
##     data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.584  -4.378  -1.375   3.221  30.488 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       7.8029     0.2795  27.915  < 2e-16 ***
## pessimism_z       0.8017     0.1041   7.703 5.47e-14 ***
## education_z      -0.1296     0.1147  -1.130    0.259    
## depressedaffect   1.2435     0.1665   7.468 2.87e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.558 on 603 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.2131, Adjusted R-squared:  0.2092 
## F-statistic: 54.42 on 3 and 603 DF,  p-value: < 2.2e-16
standardize_parameters(modell1_pes)
## # Standardization method: refit
## 
## Parameter       | Std. Coef. |        95% CI
## --------------------------------------------
## (Intercept)     |  -2.91e-16 | [-0.07, 0.07]
## pessimism z     |       0.29 | [ 0.22, 0.37]
## education z     |      -0.04 | [-0.11, 0.03]
## depressedaffect |       0.28 | [ 0.21, 0.35]
tidy_mod1_pes <- broom::tidy(modell1_pes)
kable(tidy_mod1_pes, caption = "Regressionsoutput Modell 1")
Regressionsoutput Modell 1
term estimate std.error statistic p.value
(Intercept) 7.8029068 0.2795201 27.915369 0.0000000
pessimism_z 0.8016603 0.1040682 7.703222 0.0000000
education_z -0.1296235 0.1147053 -1.130057 0.2589015
depressedaffect 1.2435092 0.1665162 7.467797 0.0000000
modell1.1_pes <- anova(modell1_pes)
kable(modell1.1_pes, caption = "ANOVA-Tabelle Modell 1")
ANOVA-Tabelle Modell 1
Df Sum Sq Mean Sq F value Pr(>F)
pessimism_z 1 4586.75851 4586.75851 106.6650690 0.0000000
education_z 1 36.07474 36.07474 0.8389182 0.3600725
depressedaffect 1 2398.10785 2398.10785 55.7679981 0.0000000
Residuals 603 25929.90757 43.00151 NA NA

Modell 2: Modell mit Interaktion

modell2_pes <- lm(cesd ~ pessimism_z * education_z +depressedaffect, data = MIDUS)
summary(modell2_pes)
## 
## Call:
## lm(formula = cesd ~ pessimism_z * education_z + depressedaffect, 
##     data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.638  -4.338  -1.338   3.184  30.490 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              7.82157    0.28418  27.524  < 2e-16 ***
## pessimism_z              0.80907    0.10603   7.631 9.18e-14 ***
## education_z             -0.12907    0.11480  -1.124    0.261    
## depressedaffect          1.24460    0.16666   7.468 2.88e-13 ***
## pessimism_z:education_z  0.01496    0.04018   0.372    0.710    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.562 on 602 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.2133, Adjusted R-squared:  0.208 
## F-statistic: 40.79 on 4 and 602 DF,  p-value: < 2.2e-16
standardize_parameters(modell2_pes)
## # Standardization method: refit
## 
## Parameter                 | Std. Coef. |        95% CI
## ------------------------------------------------------
## (Intercept)               |   2.59e-03 | [-0.07, 0.07]
## pessimism z               |       0.30 | [ 0.22, 0.37]
## education z               |      -0.04 | [-0.11, 0.03]
## depressedaffect           |       0.28 | [ 0.21, 0.35]
## pessimism z × education z |       0.01 | [-0.06, 0.08]
tidy_mod2_pes <- broom::tidy(modell2_pes)
kable(tidy_mod2_pes, caption = "Regressionsoutput Modell 2")
Regressionsoutput Modell 2
term estimate std.error statistic p.value
(Intercept) 7.8215731 0.2841752 27.523767 0.0000000
pessimism_z 0.8090729 0.1060277 7.630771 0.0000000
education_z -0.1290701 0.1147969 -1.124334 0.2613193
depressedaffect 1.2445993 0.1666610 7.467852 0.0000000
pessimism_z:education_z 0.0149645 0.0401829 0.372409 0.7097194
modell2.1_pes <- anova(modell2_pes)
kable(modell2.1_pes, caption = "ANOVA-Tabelle Modell 2")
ANOVA-Tabelle Modell 2
Df Sum Sq Mean Sq F value Pr(>F)
pessimism_z 1 4586.758509 4586.758509 106.5127111 0.0000000
education_z 1 36.074745 36.074745 0.8377199 0.3604162
depressedaffect 1 2398.107853 2398.107853 55.6883403 0.0000000
pessimism_z:education_z 1 5.972344 5.972344 0.1386885 0.7097194
Residuals 602 25923.935227 43.063015 NA NA

Testen, ob das Modell mit Interaktion signifikant besser passt

modell_ges_pes <- anova(modell1_pes,modell2_pes)
kable(modell_ges_pes, caption = "ANOVA-Tabelle")
ANOVA-Tabelle
Res.Df RSS Df Sum of Sq F Pr(>F)
603 25929.91 NA NA NA NA
602 25923.94 1 5.972344 0.1386885 0.7097194
r2_diff_pes <- summary(modell2_pes)$r.squared - summary(modell1_pes)$r.squared
cat("R²-Zuwachs durch Interaktion:", round(r2_diff_pes, 4))
## R²-Zuwachs durch Interaktion: 2e-04

=>Auch für Pessimismus ist die Interaktion mit Bildung nicht signifikant

Hypothese 2a überprüfen

library(interactions)
slopes <- sim_slopes(modell2_pes, pred = "pessimism_z", modx = "education_z", johnson_neyman = FALSE)
slopes.table <- slopes$slopes
print(slopes.table)
##   Value of education_z      Est.      S.E.      2.5%    97.5%   t val.
## 1          -2.35890961 0.7737731 0.1282699 0.5218622 1.025684 6.032382
## 2           0.01220753 0.8092556 0.1061209 0.6008435 1.017668 7.625792
## 3           2.38332466 0.8447381 0.1556470 0.5390609 1.150415 5.427267
##              p
## 1 2.821963e-09
## 2 9.504425e-14
## 3 8.305387e-08

Anschauen der Interaktion mit Alter

Hierarchische Regression

Dabei für depressive Symptome zum Zeitpunkt der Erhebung des Optimismus kontrollieren

Modell 1: Hauptmodell ohne Interaktion

modell1_age_pes <- lm(cesd ~ pessimism_z + age_z + depressedaffect, data = MIDUS)
summary(modell1_age_pes)
## 
## Call:
## lm(formula = cesd ~ pessimism_z + age_z + depressedaffect, data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.727  -4.407  -1.348   3.236  30.306 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      7.80964    0.27989  27.903  < 2e-16 ***
## pessimism_z      0.81689    0.10309   7.924 1.11e-14 ***
## age_z           -0.01590    0.02794  -0.569     0.57    
## depressedaffect  1.22974    0.16723   7.354 6.32e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.563 on 603 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.2118, Adjusted R-squared:  0.2079 
## F-statistic: 54.02 on 3 and 603 DF,  p-value: < 2.2e-16
standardize_parameters(modell1_age_pes)
## # Standardization method: refit
## 
## Parameter       | Std. Coef. |        95% CI
## --------------------------------------------
## (Intercept)     |  -2.96e-16 | [-0.07, 0.07]
## pessimism z     |       0.30 | [ 0.23, 0.37]
## age z           |      -0.02 | [-0.09, 0.05]
## depressedaffect |       0.28 | [ 0.20, 0.35]
tidy_mod1_age_pes <- broom::tidy(modell1_age_pes)
kable(tidy_mod1_age_pes, caption = "Regressionsoutput Modell 1")
Regressionsoutput Modell 1
term estimate std.error statistic p.value
(Intercept) 7.8096356 0.2798890 27.902614 0.0000000
pessimism_z 0.8168866 0.1030865 7.924285 0.0000000
age_z -0.0158963 0.0279425 -0.568891 0.5696419
depressedaffect 1.2297375 0.1672269 7.353707 0.0000000
modell1.1_age_pes <- anova(modell1_age_pes)
kable(modell1.1_age_pes, caption = "ANOVA-Tabelle Modell 1")
ANOVA-Tabelle Modell 1
Df Sum Sq Mean Sq F value Pr(>F)
pessimism_z 1 4586.75851 4586.75851 106.496779 0.0000000
age_z 1 64.14006 64.14006 1.489224 0.2228139
depressedaffect 1 2329.06725 2329.06725 54.077005 0.0000000
Residuals 603 25970.88286 43.06946 NA NA

Modell 2: Modell mit Interaktion

modell2_age_pes <- lm(cesd ~ pessimism_z * age_z + depressedaffect, data = MIDUS)
summary(modell2_age_pes)
## 
## Call:
## lm(formula = cesd ~ pessimism_z * age_z + depressedaffect, data = MIDUS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -16.806  -4.406  -1.349   3.291  30.398 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        7.797128   0.283794  27.475  < 2e-16 ***
## pessimism_z        0.808395   0.107714   7.505 2.22e-13 ***
## age_z             -0.017148   0.028334  -0.605    0.545    
## depressedaffect    1.227905   0.167489   7.331 7.38e-13 ***
## pessimism_z:age_z -0.003029   0.011048  -0.274    0.784    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.568 on 602 degrees of freedom
##   (15 observations deleted due to missingness)
## Multiple R-squared:  0.2119, Adjusted R-squared:  0.2067 
## F-statistic: 40.47 on 4 and 602 DF,  p-value: < 2.2e-16
standardize_parameters(modell2_age_pes)
## # Standardization method: refit
## 
## Parameter           | Std. Coef. |        95% CI
## ------------------------------------------------
## (Intercept)         |  -1.82e-03 | [-0.07, 0.07]
## pessimism z         |       0.30 | [ 0.22, 0.37]
## age z               |      -0.02 | [-0.10, 0.05]
## depressedaffect     |       0.28 | [ 0.20, 0.35]
## pessimism z × age z |      -0.01 | [-0.09, 0.07]
tidy_mod2_age_pes <- broom::tidy(modell2_age_pes)
kable(tidy_mod2_age_pes, caption = "Regressionsoutput Modell 2")
Regressionsoutput Modell 2
term estimate std.error statistic p.value
(Intercept) 7.7971282 0.2837936 27.4746476 0.0000000
pessimism_z 0.8083946 0.1077138 7.5050261 0.0000000
age_z -0.0171476 0.0283339 -0.6051979 0.5452756
depressedaffect 1.2279046 0.1674887 7.3312676 0.0000000
pessimism_z:age_z -0.0030293 0.0110477 -0.2742043 0.7840217
modell2.1_age_pes <- anova(modell2_age_pes)
kable(modell2.1_age_pes, caption = "ANOVA-Tabelle Modell 2")
ANOVA-Tabelle Modell 2
Df Sum Sq Mean Sq F value Pr(>F)
pessimism_z 1 4586.758509 4586.758509 106.333447 0.0000000
age_z 1 64.140062 64.140062 1.486940 0.2231694
depressedaffect 1 2329.067248 2329.067248 53.994067 0.0000000
pessimism_z:age_z 1 3.243282 3.243282 0.075188 0.7840217
Residuals 602 25967.639576 43.135614 NA NA

Testen, ob das Modell mit Interaktion signifikant besser passt

modell_ges_age_pes <- anova(modell1_age_pes,modell2_age_pes)
kable(modell_ges_age_pes, caption = "ANOVA-Tabelle")
ANOVA-Tabelle
Res.Df RSS Df Sum of Sq F Pr(>F)
603 25970.88 NA NA NA NA
602 25967.64 1 3.243282 0.075188 0.7840217
r2_diff_age_pes <- summary(modell2_age_pes)$r.squared - summary(modell1_age_pes)$r.squared
cat("R²-Zuwachs durch Interaktion:", round(r2_diff_age_pes, 4))
## R²-Zuwachs durch Interaktion: 1e-04

=>Auch für Pessimismus ist die Interaktion nicht signifikant

Details zur verwendeten Software anzeigen lassen

version
##                _                           
## platform       aarch64-apple-darwin20      
## arch           aarch64                     
## os             darwin20                    
## system         aarch64, darwin20           
## status                                     
## major          4                           
## minor          5.0                         
## year           2025                        
## month          04                          
## day            11                          
## svn rev        88135                       
## language       R                           
## version.string R version 4.5.0 (2025-04-11)
## nickname       How About a Twenty-Six