/
example-mc-mi.Rmd
146 lines (119 loc) · 2.74 KB
/
example-mc-mi.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
title: "betaMC: Monte Carlo Method Combined with Multiple Imputation"
author: "Ivan Jacob Agaloos Pesigan"
output: rmarkdown::html_vignette
bibliography: "vignettes.bib"
csl: https://raw.githubusercontent.com/citation-style-language/styles/master/apa.csl
nocite: |
@Pesigan-Cheung-2023
@Dudgeon-2017
vignette: >
%\VignetteIndexEntry{betaMC: Monte Carlo Method Combined with Multiple Imputation}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
The Monte Carlo Method combined with multiple imputation
described in @Pesigan-Cheung-2023
is implemented using the `MCMI()` function
in the context of linear regression.
Multiple imputation is used to deal with missing values in a data set.
The vector of parameter estimates
and the corresponding sampling covariance matrix
are estimated for each of the imputed data sets.
Results are combined to arrive at the pooled vector of parameter estimates
and the corresponding sampling covariance matrix.
The pooled estimates are then used to generate the sampling distribution
of regression parameters.
The output of the `MCMI()` function
can be passed to the
`BetaMC()`,
`RSqMC()`,
`DeltaRSqMC()`,
`SCorMC()`,
`PCorMC()`,
and
`DiffBetaMC()` functions
to generate confidence intervals for various
regression effect sizes.
In this example,
we use the data set and the model used in
[betaMC: Example Using the BetaMC Function](example-beta-mc.html).
We use the `mice::ampute()` function to generate a data set with missing values.
```{r}
#| message = FALSE
library(betaMC)
```
```{r}
#| echo = FALSE
if (!exists("nas1982")) {
try(
data(
"nas1982",
package = "betaMC"
),
silent = TRUE
)
}
df <- nas1982
```
```{r}
#| eval = FALSE
df <- betaMC::nas1982
```
```{r}
set.seed(42)
df <- mice::ampute(df)$amp
df
```
### Multiple Imputation
```{r}
mi <- mice::mice(
df,
m = 100,
seed = 42,
print = FALSE
)
```
### Regression
Fit the regression model using the `lm()` function.
Note that this does not deal with missing values.
The fitted model (`object`) is updated with each imputed data
within the `MCMI()` function.
```{r}
object <- lm(QUALITY ~ NARTIC + PCTGRT + PCTSUPP, data = df)
```
### Monte Carlo Sampling Distribution of Parameters
```{r}
hc3 <- MCMI(object, mi = mi, type = "hc3")
```
### Standardized Regression Slopes
```{r}
BetaMC(hc3)
```
### Multiple Correlation Coefficients
```{r}
RSqMC(hc3)
```
### Improvement in R-squared
```{r}
DeltaRSqMC(hc3)
```
### Semipartial Correlation Coefficients
```{r}
SCorMC(hc3)
```
### Squared Partial Correlation Coefficients
```{r}
PCorMC(hc3)
```
### Differences of Standardized Regression Slopes
```{r}
DiffBetaMC(hc3)
```
## References