Skip to content

Commit fd7aa2d

Browse files
20251119 - effect sizes; specify packages of functions
1 parent c00d3e1 commit fd7aa2d

File tree

1 file changed

+41
-21
lines changed

1 file changed

+41
-21
lines changed

regression.Rmd

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ multipleRegressionModel <- lm(
8787
8888
summary(multipleRegressionModel)
8989
confint(multipleRegressionModel)
90+
print(effectsize::standardize_parameters(multipleRegressionModel), digits = 2)
9091
```
9192

9293
### Remove missing data
@@ -105,7 +106,7 @@ multipleRegressionModelNoMissing <- lm(
105106
## Linear regression model on correlation/covariance matrix (for pairwise deletion)
106107

107108
```{r, warning = FALSE}
108-
multipleRegressionModelPairwise <- setCor(
109+
multipleRegressionModelPairwise <- psych::setCor(
109110
y = "bpi_antisocialT2Sum",
110111
x = c("bpi_antisocialT1Sum","bpi_anxiousDepressedSum"),
111112
data = cov(mydata[,c("bpi_antisocialT2Sum","bpi_antisocialT1Sum","bpi_anxiousDepressedSum")], use = "pairwise.complete.obs"),
@@ -126,6 +127,7 @@ rmsMultipleRegressionModel <- robcov(ols(
126127
127128
rmsMultipleRegressionModel
128129
confint(rmsMultipleRegressionModel)
130+
print(effectsize::standardize_parameters(rmsMultipleRegressionModel), digits = 2)
129131
```
130132

131133
## Robust linear regression (MM-type iteratively reweighted least squares regression)
@@ -138,23 +140,25 @@ robustLinearRegression <- lmrob(
138140
139141
summary(robustLinearRegression)
140142
confint(robustLinearRegression)
143+
print(effectsize::standardize_parameters(robustLinearRegression), digits = 2)
141144
```
142145

143146
## Least trimmed squares regression (for removing outliers)
144147

145148
```{r}
146-
ltsRegression <- ltsReg(
149+
ltsRegression <- robustbase::ltsReg(
147150
bpi_antisocialT2Sum ~ bpi_antisocialT1Sum + bpi_anxiousDepressedSum,
148151
data = mydata,
149152
na.action = na.exclude)
150153
151154
summary(ltsRegression)
155+
confint(robustLinearRegression)
152156
```
153157

154158
## Bayesian linear regression
155159

156160
```{r, message = FALSE, warning = FALSE, results = FALSE}
157-
bayesianRegularizedRegression <- brm(
161+
bayesianRegularizedRegression <- brms::brm(
158162
bpi_antisocialT2Sum ~ bpi_antisocialT1Sum + bpi_anxiousDepressedSum,
159163
data = mydata,
160164
chains = 4,
@@ -164,6 +168,7 @@ bayesianRegularizedRegression <- brm(
164168

165169
```{r}
166170
summary(bayesianRegularizedRegression)
171+
print(effectsize::standardize_parameters(bayesianRegularizedRegression, method = "basic"), digits = 2)
167172
```
168173

169174
# Generalized Linear Regression
@@ -182,6 +187,7 @@ generalizedRegressionModel <- glm(
182187
183188
summary(generalizedRegressionModel)
184189
confint(generalizedRegressionModel)
190+
print(effectsize::standardize_parameters(generalizedRegressionModel), digits = 2)
185191
```
186192

187193
## Generalized regression model (rms)
@@ -190,7 +196,7 @@ In this example, we predict a count variable that has a poisson distribution.
190196
We could change the distribution.
191197

192198
```{r}
193-
rmsGeneralizedRegressionModel <- Glm(
199+
rmsGeneralizedRegressionModel <- rms::Glm(
194200
countVariable ~ bpi_antisocialT1Sum + bpi_anxiousDepressedSum,
195201
data = mydata,
196202
x = TRUE,
@@ -199,6 +205,7 @@ rmsGeneralizedRegressionModel <- Glm(
199205
200206
rmsGeneralizedRegressionModel
201207
confint(rmsGeneralizedRegressionModel)
208+
print(effectsize::standardize_parameters(rmsGeneralizedRegressionModel), digits = 2)
202209
```
203210

204211
## Bayesian generalized linear model
@@ -219,35 +226,37 @@ bayesianGeneralizedLinearRegression <- brm(
219226

220227
```{r}
221228
summary(bayesianGeneralizedLinearRegression)
229+
print(effectsize::standardize_parameters(bayesianGeneralizedLinearRegression, method = "basic"), digits = 2)
222230
```
223231

224232
## Robust generalized regression
225233

226234
```{r}
227-
robustGeneralizedRegression <- glmrob(
235+
robustGeneralizedRegression <- robustbase::glmrob(
228236
countVariable ~ bpi_antisocialT1Sum + bpi_anxiousDepressedSum,
229237
data = mydata,
230238
family = "poisson",
231239
na.action = na.exclude)
232240
233241
summary(robustGeneralizedRegression)
234242
confint(robustGeneralizedRegression)
243+
print(effectsize::standardize_parameters(robustGeneralizedRegression), digits = 2)
235244
```
236245

237246
## Ordinal regression model
238247

239248
```{r}
240-
ordinalRegressionModel1 <- polr(
249+
ordinalRegressionModel1 <- MASS::polr(
241250
orderedVariable ~ bpi_antisocialT1Sum + bpi_anxiousDepressedSum,
242251
data = mydata)
243252
244-
ordinalRegressionModel2 <- lrm(
253+
ordinalRegressionModel2 <- rms::lrm(
245254
orderedVariable ~ bpi_antisocialT1Sum + bpi_anxiousDepressedSum,
246255
data = mydata,
247256
x = TRUE,
248257
y = TRUE)
249258
250-
ordinalRegressionModel3 <- orm(
259+
ordinalRegressionModel3 <- rms::orm(
251260
orderedVariable ~ bpi_antisocialT1Sum + bpi_anxiousDepressedSum,
252261
data = mydata,
253262
x = TRUE,
@@ -257,9 +266,11 @@ summary(ordinalRegressionModel1)
257266
confint(ordinalRegressionModel1)
258267
259268
ordinalRegressionModel2
269+
print(effectsize::standardize_parameters(ordinalRegressionModel2), digits = 2)
260270
261271
ordinalRegressionModel3
262272
confint(ordinalRegressionModel3)
273+
print(effectsize::standardize_parameters(ordinalRegressionModel3), digits = 2)
263274
```
264275

265276
## Bayesian ordinal regression model
@@ -276,6 +287,7 @@ bayesianOrdinalRegression <- brm(
276287

277288
```{r}
278289
summary(bayesianOrdinalRegression)
290+
print(effectsize::standardize_parameters(bayesianOrdinalRegression, method = "basic"), digits = 2)
279291
```
280292

281293
## Bayesian count regression model
@@ -292,19 +304,21 @@ bayesianCountRegression <- brm(
292304

293305
```{r}
294306
summary(bayesianCountRegression)
307+
print(effectsize::standardize_parameters(bayesianCountRegression, method = "basic"), digits = 2)
295308
```
296309

297310
## Logistic regression model (rms)
298311

299312
```{r}
300-
logisticRegressionModel <- robcov(lrm(
313+
logisticRegressionModel <- rms::robcov(rms::lrm(
301314
female ~ bpi_antisocialT1Sum + bpi_anxiousDepressedSum,
302315
data = mydata,
303316
x = TRUE,
304317
y = TRUE))
305318
306319
logisticRegressionModel
307320
confint(logisticRegressionModel)
321+
print(effectsize::standardize_parameters(logisticRegressionModel), digits = 2)
308322
```
309323

310324
## Bayesian logistic regression model
@@ -321,6 +335,7 @@ bayesianLogisticRegression <- brm(
321335

322336
```{r}
323337
summary(bayesianLogisticRegression)
338+
print(effectsize::standardize_parameters(bayesianLogisticRegression, method = "basic"), digits = 2)
324339
```
325340

326341
# Hierarchical Linear Regression
@@ -356,6 +371,7 @@ https://cran.r-project.org/web/packages/interactions/vignettes/interactions.html
356371

357372
```{r}
358373
states <- as.data.frame(state.x77)
374+
states$HS.Grad <- states$`HS Grad`
359375
```
360376

361377
## Mean Center Predictors
@@ -371,31 +387,34 @@ states$Murder_centered <- scale(states$Murder, scale = FALSE)
371387

372388
```{r}
373389
interactionModel <- lm(
374-
Income ~ Illiteracy_centered + Murder_centered + Illiteracy_centered:Murder_centered + `HS Grad`,
390+
Income ~ Illiteracy_centered + Murder_centered + Illiteracy_centered:Murder_centered + HS.Grad,
375391
data = states)
392+
393+
summary(interactionModel)
394+
print(effectsize::standardize_parameters(interactionModel), digits = 2)
376395
```
377396

378397
## Plots
379398

380399
```{r}
381-
interact_plot(
400+
interactions::interact_plot(
382401
interactionModel,
383402
pred = Illiteracy_centered,
384403
modx = Murder_centered)
385404
386-
interact_plot(
405+
interactions::interact_plot(
387406
interactionModel,
388407
pred = Illiteracy_centered,
389408
modx = Murder_centered,
390409
plot.points = TRUE)
391410
392-
interact_plot(
411+
interactions::interact_plot(
393412
interactionModel,
394413
pred = Illiteracy_centered,
395414
modx = Murder_centered,
396415
interval = TRUE)
397416
398-
johnson_neyman(
417+
interactions::johnson_neyman(
399418
interactionModel,
400419
pred = Illiteracy_centered,
401420
modx = Murder_centered,
@@ -405,13 +424,13 @@ johnson_neyman(
405424
## Simple Slopes Analysis
406425

407426
```{r}
408-
sim_slopes(
427+
interactions::sim_slopes(
409428
interactionModel,
410429
pred = Illiteracy_centered,
411430
modx = Murder_centered,
412431
johnson_neyman = FALSE)
413432
414-
sim_slopes(
433+
interactions::sim_slopes(
415434
interactionModel,
416435
pred = Illiteracy_centered,
417436
modx = Murder_centered,
@@ -424,13 +443,13 @@ sim_slopes(
424443
Indicates all the values of the moderator for which the slope of the predictor is statistically significant.
425444

426445
```{r}
427-
sim_slopes(
446+
interactions::sim_slopes(
428447
interactionModel,
429448
pred = Illiteracy_centered,
430449
modx = Murder_centered,
431450
johnson_neyman = TRUE)
432451
433-
probe_interaction(
452+
interactions::probe_interaction(
434453
interactionModel,
435454
pred = Illiteracy_centered,
436455
modx = Murder_centered,
@@ -496,6 +515,7 @@ listwiseDeletionModel <- lm(
496515
497516
summary(listwiseDeletionModel)
498517
confint(listwiseDeletionModel)
518+
print(effectsize::standardize_parameters(listwiseDeletionModel), digits = 2)
499519
```
500520

501521
## Pairwise deletion {#pairwiseDeletion}
@@ -521,7 +541,7 @@ pairwiseRegression_syntax <- '
521541
bpi_antisocialT2Sum ~ 1
522542
'
523543
524-
pairwiseRegression_fit <- lavaan(
544+
pairwiseRegression_fit <- lavaan::lavaan(
525545
pairwiseRegression_syntax,
526546
sample.mean = varMeans,
527547
sample.cov = varCovariances,
@@ -543,7 +563,7 @@ fimlRegression_syntax <- '
543563
bpi_antisocialT2Sum ~ 1
544564
'
545565
546-
fimlRegression_fit <- lavaan(
566+
fimlRegression_fit <- lavaan::lavaan(
547567
fimlRegression_syntax,
548568
data = mydata,
549569
missing = "ML",
@@ -558,7 +578,7 @@ summary(
558578
## Multiple imputation {#imputation}
559579

560580
```{r}
561-
modelData_imputed <- mice(
581+
modelData_imputed <- mice::mice(
562582
modelData,
563583
m = 5,
564584
method = "pmm") # predictive mean matching; can choose among many methods

0 commit comments

Comments
 (0)