subgroupsem | R Documentation |
This function is the main function of the package and can be flexibly used to interface the python module pysubgroup for efficiently finding subgroups in structural equation models estimated by the R package lavaan.
subgroupsem(
f_fit,
dat,
columns = names(dat),
ignore = NULL,
algorithm = "SimpleDFS",
max_n_subgroups = 10L,
search_depth = 3L,
min_quality = 0,
min_subgroup_size = NULL,
weighting_attr = NULL,
generalization_aware = FALSE,
na_rm = FALSE,
bw = NULL,
verbose = FALSE,
...
)
f_fit |
Function to be fitted. Must take at least two arguments.
|
dat |
A data frame. |
columns |
Column names of the provided data frame which are to be analysed. Columns must have ordinal or nominal scale. |
ignore |
Optional argument. If |
algorithm |
A character specifying the subgroup discovery algorithm to use. An exhaustive depth-first search is provided with 'SimpleDFS' (default) . A heuristic (non-exhaustive) Beam search is provided with 'Beam', but not yet implemented. |
max_n_subgroups |
Maximum number of subgroups. Default is 10. |
search_depth |
Maximum number of attribute combinations. Default is 3. |
min_quality |
Minimum value of interestingness measure. Values below will not be considered. Default is 0. |
min_subgroup_size |
Minimum size of a subgroup. Subgroups with sizes below will not be considered. The absolute minimum is set to 50 units, which can not be lowered. If NULL (default) the absolute minimum is applied. |
weighting_attr |
This option is deprecated. |
generalization_aware |
This option is deprecated. |
na_rm |
Boolean. Default is FALSE. If set to TRUE, cases with NA values
on any column will be set to FALSE in the |
bw |
Integer for beam width. Only used if algorithm is Beam search.
Defaults to |
verbose |
Logical. Get some information, what is going on. Defaults
to |
... |
Additional arguments to be passed to |
List containing the time consumed and the groups.
if (FALSE) {
model <- "
eta1 =~ NA*x1 + x2 + x3
eta2 =~ NA*x4 + x5 + x6
eta3 =~ NA*x7 + x8 + x9
eta1 ~~ 1*eta1
eta2 ~~ 1*eta2
eta3 ~~ 1*eta3
eta1 + eta2 + eta3 ~ 0*1
"
f_fit <- function(sg, dat) {
# Add subgroup to dataset (from logical to numeric)
sg <- as.numeric(sg)
dat$subgroup <- sg
# if all participants in subgroup return -1
if (all(sg == 1)) {
rval <- 0
return(rval)
}
rval <- tryCatch(
{
# Fit Model
fit <- sem(model, data = dat, group = "subgroup")
stopifnot(lavInspect(fit, "post.check"))
# Compute interestingness measure
tmp <- partable(fit)
lam1 <- tmp$est[
tmp$lhs == "eta1" &
tmp$op == "=~" & tmp$group == 1
]
lam2 <- tmp$est[
tmp$lhs == "eta1" &
tmp$op == "=~" &
tmp$group == 2
]
difflam <- abs(lam2 - lam1)
rval <- sum(sg, na.rm = T)^0.5 * sum(difflam)
},
error = function(e) -1
)
if (!is.numeric(rval) | length(rval) > 1) {
rval <- -1
}
return(rval)
}
m1 <- subgroupsem(
f_fit = f_fit,
dat = HolzingerSwineford1939,
columns = c("sex", "school", "grade")
)
summary(m1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.