-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.R
222 lines (216 loc) · 5 KB
/
data.R
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#' @title Sample Data: A Path Model
#'
#' @description A four-variable dataset with 100 cases.
#'
#' @format A data frame with 100 rows
#' and 5 variables:
#' \describe{
#' \item{m1}{Mediator. Numeric.}
#' \item{dv}{Outcome variable. Numeric.}
#' \item{iv1}{Predictor. Numeric.}
#' \item{iv2}{Predictor. Numeric.}
#' }
#'
#' @examples
#' library(lavaan)
#' data(pa_dat)
#' mod <-
#' "
#' m1 ~ a1 * iv1 + a2 * iv2
#' dv ~ b * m1
#' a1b := a1 * b
#' a2b := a2 * b
#' "
#' fit <- sem(mod, pa_dat)
#' summary(fit)
"pa_dat"
#' @title Sample Data: A CFA Model
#'
#' @description A six-variable dataset with 100 cases.
#'
#' @format A data frame with 100 rows
#' and 6 variables:
#' \describe{
#' \item{x1}{Indicator. Numeric.}
#' \item{x2}{Indicator. Numeric.}
#' \item{x3}{Indicator. Numeric.}
#' \item{x4}{Indicator. Numeric.}
#' \item{x5}{Indicator. Numeric.}
#' \item{x6}{Indicator. Numeric.}
#' }
#'
#' @examples
#' library(lavaan)
#' data(cfa_dat)
#' mod <-
#' "
#' f1 =~ x1 + x2 + x3
#' f2 =~ x4 + x5 + x6
#' "
#' fit <- cfa(mod, cfa_dat)
#' summary(fit)
"cfa_dat"
#' @title Sample Data: A Latent Variable Structural Model
#'
#' @description A nine-variable dataset with 200 cases.
#'
#' @format A data frame with 200 rows
#' and 9 variables:
#' \describe{
#' \item{x1}{Indicator. Numeric.}
#' \item{x2}{Indicator. Numeric.}
#' \item{x3}{Indicator. Numeric.}
#' \item{x4}{Indicator. Numeric.}
#' \item{x5}{Indicator. Numeric.}
#' \item{x6}{Indicator. Numeric.}
#' \item{x7}{Indicator. Numeric.}
#' \item{x8}{Indicator. Numeric.}
#' \item{x9}{Indicator. Numeric.}
#' }
#'
#' @examples
#' library(lavaan)
#' data(sem_dat)
#' mod <-
#' "
#' f1 =~ x1 + x2 + x3
#' f2 =~ x4 + x5 + x6
#' f3 =~ x7 + x8 + x9
#' f2 ~ a * f1
#' f3 ~ b * f2
#' ab := a * b
#' "
#' fit <- sem(mod, sem_dat)
#' summary(fit)
"sem_dat"
#' @title Sample Data: A Path Model with an Influential Case
#'
#' @description A four-variable dataset with 100 cases, with
#' one influential case.
#'
#' @format A data frame with 100 rows
#' and 5 variables:
#' \describe{
#' \item{case_id}{Case ID. Character.}
#' \item{iv1}{Predictor. Numeric.}
#' \item{iv2}{Predictor. Numeric.}
#' \item{m1}{Mediator. Numeric.}
#' \item{dv}{Outcome variable. Numeric.}
#' }
#'
#' @examples
#' library(lavaan)
#' data(pa_dat2)
#' mod <-
#' "
#' m1 ~ a1 * iv1 + a2 * iv2
#' dv ~ b * m1
#' a1b := a1 * b
#' a2b := a2 * b
#' "
#' fit <- sem(mod, pa_dat2)
#' summary(fit)
#' inf_out <- influence_stat(fit)
#' gcd_plot(inf_out)
"pa_dat2"
#' @title Sample Data: A CFA Model with an Influential Case
#'
#' @description A six-variable dataset with 100 cases, with
#' one influential case.
#'
#' @format A data frame with 100 rows
#' and 7 variables:
#' \describe{
#' \item{case_id}{Case ID. Character.}
#' \item{x1}{Indicator. Numeric.}
#' \item{x2}{Indicator. Numeric.}
#' \item{x3}{Indicator. Numeric.}
#' \item{x4}{Indicator. Numeric.}
#' \item{x5}{Indicator. Numeric.}
#' \item{x6}{Indicator. Numeric.}
#' }
#'
#' @examples
#' library(lavaan)
#' data(cfa_dat2)
#' mod <-
#' "
#' f1 =~ x1 + x2 + x3
#' f2 =~ x4 + x5 + x6
#' "
#' fit <- cfa(mod, cfa_dat2)
#' summary(fit)
#' inf_out <- influence_stat(fit)
#' gcd_plot(inf_out)
"cfa_dat2"
#' @title Sample Data: A Latent Variable Structural Model
#' With an Influential Case
#'
#' @description A ten-variable dataset with 200 cases, with
#' one influential case.
#'
#' @format A data frame with 200 rows
#' and 10 variables:
#' \describe{
#' \item{case_id}{Case ID. Character.}
#' \item{x1}{Indicator. Numeric.}
#' \item{x2}{Indicator. Numeric.}
#' \item{x3}{Indicator. Numeric.}
#' \item{x4}{Indicator. Numeric.}
#' \item{x5}{Indicator. Numeric.}
#' \item{x6}{Indicator. Numeric.}
#' \item{x7}{Indicator. Numeric.}
#' \item{x8}{Indicator. Numeric.}
#' \item{x9}{Indicator. Numeric.}
#' }
#'
#' @examples
#' library(lavaan)
#' data(sem_dat2)
#' mod <-
#' "
#' f1 =~ x1 + x2 + x3
#' f2 =~ x4 + x5 + x6
#' f3 =~ x7 + x8 + x9
#' f2 ~ a * f1
#' f3 ~ b * f2
#' ab := a * b
#' "
#' fit <- sem(mod, sem_dat2)
#' summary(fit)
#' inf_out <- influence_stat(fit)
#' gcd_plot(inf_out)
"sem_dat2"
#' @title Sample Data: A CFA Model with a Heywood Case
#'
#' @description A six-variable dataset with 60 cases, with
#' one case resulting in negative variance if not removed.
#'
#' @format A data frame with 60 rows
#' and 6 variables:
#' \describe{
#' \item{x1}{Indicator. Numeric.}
#' \item{x2}{Indicator. Numeric.}
#' \item{x3}{Indicator. Numeric.}
#' \item{x4}{Indicator. Numeric.}
#' \item{x5}{Indicator. Numeric.}
#' \item{x6}{Indicator. Numeric.}
#' }
#'
#' @examples
#' library(lavaan)
#' data(cfa_dat_heywood)
#' mod <-
#' "
#' f1 =~ x1 + x2 + x3
#' f2 =~ x4 + x5 + x6
#' "
#' # The following will result in a warning
#' fit <- cfa(mod, cfa_dat_heywood)
#' # One variance is negative
#' parameterEstimates(fit, output = "text")
#' # Fit the model with the first case removed
#' fit_no_case_1 <- cfa(mod, cfa_dat_heywood[-1, ])
#' # Results admissible
#' parameterEstimates(fit_no_case_1, output = "text")
"cfa_dat_heywood"