You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users may want to get the output of cond_indirect_effects() as a data frame such that it can be used by other functions.
# Adapted from https://sfcheung.github.io/manymome/articles/mome_lm.html
library(manymome)
dat<-data_med_mod_alm_m<- lm(m~x*w+c1+c2, dat)
lm_y<- lm(y~m+x+c1+c2, dat)
fit_lm<- lm2list(lm_m, lm_y)
boot_out_lm<- do_boot(fit_lm,
R=5000,
seed=54532,
ncores=4)
#> 4 processes started to run bootstrapping.out_xmy_on_w<- cond_indirect_effects(wlevels="w",
x="x",
y="y",
m="m",
fit=fit_lm,
boot_ci=TRUE,
boot_out=boot_out_lm)
out_xmy_on_w#> #> == Conditional indirect effects ==#> #> Path: x -> m -> y#> Conditional on moderator(s): w#> Moderator(s) represented by: w#> #> [w] (w) ind CI.lo CI.hi Sig m~x y~m#> 1 M+1.0SD 3.164 3.060 1.914 3.979 Sig 3.192 0.959#> 2 Mean 2.179 2.136 1.282 2.966 Sig 2.228 0.959#> 3 M-1.0SD 1.194 1.212 -0.102 2.476 1.265 0.959#> #> - [CI.lo to CI.hi] are 95.0% percentile confidence intervals by#> nonparametric bootstrapping with 5000 samples.#> - The 'ind' column shows the indirect effects.#> - 'm~x','y~m' is/are the path coefficient(s) along the path conditional#> on the moderators.
For now, the output of cond_indirect_effects() has methods such as coef() and confint(), such that other packages that make use of these methods can be used. E.g.,
However, there are cases in which users would like to have a data frame. If only the default results are needed (no standard errors, no p-values), then as.data.frame() will work. E.g.,
However, if SEs and/or p-values are needed, more need to be done. I do not yet have an idea on how to implement this appropriately. These columns could have been added in the table. However, I would avoid changing the structure (columns) of the output unless really necessary, to avoid breaking other functions that manipulate the output. Therefore, for now, SEs and p-values are stored internally but they are printed only if requested. This is done by the print methods.
Until the team has a decision, if SEs and/or p-values are needed, the following function can be used as a tentative solution:
cond_indirect_effects_to_data_frame<-function(x,
pvalue=FALSE,
se=FALSE) {
out<- as.data.frame(x)
full_output<- attr(x, "full_output")
if (se) {
se<- sapply(full_output, function(x) {
if (!is.null(x$boot_se)) return(x$boot_se)
if (!is.null(x$mc_se)) return(x$mc_se)
return(NA)
})
out$SE<-se
}
if (pvalue) {
pv<- sapply(full_output, function(x) {
if (!is.null(x$boot_p)) return(x$boot_p)
if (!is.null(x$mc_p)) return(x$mc_p)
return(NA)
})
out$pvalue<-pv
}
return(out)
}
This is not good solution, I admit. Nevertheless, this works for now.
Users who want the results as data frames can just use as.data.frame() or the function cond_indirect_effects_to_data_frame(). Because the output is just a usual data frame, they can be manipulated as data frames (e..g, columns reordered or some rows deleted). E.g.,
Users may want to get the output of
cond_indirect_effects()
as a data frame such that it can be used by other functions.For now, the output of
cond_indirect_effects()
has methods such ascoef()
andconfint()
, such that other packages that make use of these methods can be used. E.g.,However, there are cases in which users would like to have a data frame. If only the default results are needed (no standard errors, no p-values), then
as.data.frame()
will work. E.g.,The results can be used and manipulated as a usual data frame. E.g.,
However, if SEs and/or p-values are needed, more need to be done. I do not yet have an idea on how to implement this appropriately. These columns could have been added in the table. However, I would avoid changing the structure (columns) of the output unless really necessary, to avoid breaking other functions that manipulate the output. Therefore, for now, SEs and p-values are stored internally but they are printed only if requested. This is done by the print methods.
Until the team has a decision, if SEs and/or p-values are needed, the following function can be used as a tentative solution:
This is how it works:
This is not good solution, I admit. Nevertheless, this works for now.
Users who want the results as data frames can just use
as.data.frame()
or the functioncond_indirect_effects_to_data_frame()
. Because the output is just a usual data frame, they can be manipulated as data frames (e..g, columns reordered or some rows deleted). E.g.,I opened this issue to remind me to work on it.
Comments and suggests are welcomed.
The text was updated successfully, but these errors were encountered: