Title: | Mediation Analysis Confidence Intervals |
---|---|
Description: | We provide functions to compute confidence intervals for a well-defined nonlinear function of the model parameters (e.g., product of k coefficients) in single--level and multilevel structural equation models. It also computes a chi-square test statistic for a function of indirect effects. 'Tofighi', D. and 'MacKinnon', D. P. (2011). 'RMediation' An R package for mediation analysis confidence intervals. Behavior Research Methods, 43, 692--700. <doi:10.3758/s13428-011-0076-x>. 'Tofighi', D. (2020). Bootstrap Model-Based Constrained Optimization Tests of Indirect Effects. Frontiers in Psychology, 10, 2989. <doi:10.3389/fpsyg.2019.02989>. |
Authors: | Davood Tofighi [aut, cre] |
Maintainer: | Davood Tofighi <[email protected]> |
License: | GPL (>= 3) |
Version: | 2.0.0 |
Built: | 2024-10-30 03:46:14 UTC |
Source: | https://github.com/quantpsych/rmediation |
This function returns a ()% confidence interval (CI) for a
well–defined nonlinear function of the coefficients in single–level and
multilevel structural equation models. The
ci
function uses the Monte
Carlo (type="MC"
) and the asymptotic normal theory
(type="asymp"
) with the multivariate delta standard error
(Asymptotic–Delta) method (Sobel, 1982) to compute a CI. In addition, for
each of the methods, when a user specifies plot=TRUE
and
plotCI=TRUE
, a plot of the sampling distribution of the quantity of
interest in the quant
argument and an overlaid plot of the CI will be
produced. When type="all"
and plot=TRUE
, two overlaid plots of
the sampling distributions corresponding to each method will be produced;
when plotCI=TRUE
, then the overlaid plots of the CIs for both methods
will be displayed as well.
ci( mu, Sigma, quant, alpha = 0.05, type = "MC", plot = FALSE, plotCI = FALSE, n.mc = 1e+06, H0 = FALSE, mu0 = NULL, Sigma0 = NULL, ... )
ci( mu, Sigma, quant, alpha = 0.05, type = "MC", plot = FALSE, plotCI = FALSE, n.mc = 1e+06, H0 = FALSE, mu0 = NULL, Sigma0 = NULL, ... )
mu |
(1) a vector of means (e.g., coefficient estimates) for the
normal random variables. A user can assign a name to each mean value, e.g.,
|
Sigma |
either a covariance matrix or a vector that stacks all the columns of the lower triangle variance–covariance matrix one underneath the other. |
quant |
quantity of interest, which is a nonlinear/linear function of
the model parameters. Argument |
alpha |
significance level for the CI. The default value is .05. |
type |
method used to compute a CI. It takes on the values |
plot |
when |
plotCI |
when |
n.mc |
Monte Carlo sample size. The default sample size is 1e+6. |
H0 |
False. If |
mu0 |
a vector of means (e.g., coefficient estimates) for the
normal random variables that satisfy the null hypothesis |
Sigma0 |
either a covariance matrix or a vector that stacks all
the columns of the lower triangle variance–covariance matrix one
underneath the other. If it is not provided, then |
... |
additional arguments. |
When type
is "MC"
or "asymp"
, ci
returns
a list that contains:
(\eqn{1-\alpha})% CI |
a vector of lower and upper confidence limits, |
Estimate |
a point estimate of the quantity of interest, |
SE |
standard error of the quantity of interest, |
MC Error |
When |
When type="all"
, ci
returns a list of two
objects, each of which a list that contains the results produced by
each method as described above.
A shiny web application for Monte Carlo method of this function is available at https://amplab.shinyapps.io/MEDMC/
Davood Tofighi [email protected]
Tofighi, D. and MacKinnon, D. P. (2011). RMediation: An R package for mediation analysis confidence intervals. Behavior Research Methods, 43, 692–700. doi:10.3758/s13428-011-0076-x
ci( mu = c(b1 = 1, b2 = .7, b3 = .6, b4 = .45), Sigma = c(.05, 0, 0, 0, .05, 0, 0, .03, 0, .03), quant = ~ b1 * b2 * b3 * b4, type = "all", plot = TRUE, plotCI = TRUE ) # An Example of Conservative Null Sampling Distribution ci(c(b1 = .3, b2 = .4, b3 = .3), c(.01, 0, 0, .01, 0, .02), quant = ~ b1 * b2 * b3, type = "mc", plot = TRUE, plotCI = TRUE, H0 = TRUE, mu0 = c(b1 = .3, b2 = .4, b3 = 0) ) # An Example of Less Conservative Null Sampling Distribution ci(c(b1 = .3, b2 = .4, b3 = .3), c(.01, 0, 0, .01, 0, .02), quant = ~ b1 * b2 * b3, type = "mc", plot = TRUE, plotCI = TRUE, H0 = TRUE, mu0 = c(b1 = 0, b2 = .4, b3 = 0.1) )
ci( mu = c(b1 = 1, b2 = .7, b3 = .6, b4 = .45), Sigma = c(.05, 0, 0, 0, .05, 0, 0, .03, 0, .03), quant = ~ b1 * b2 * b3 * b4, type = "all", plot = TRUE, plotCI = TRUE ) # An Example of Conservative Null Sampling Distribution ci(c(b1 = .3, b2 = .4, b3 = .3), c(.01, 0, 0, .01, 0, .02), quant = ~ b1 * b2 * b3, type = "mc", plot = TRUE, plotCI = TRUE, H0 = TRUE, mu0 = c(b1 = .3, b2 = .4, b3 = 0) ) # An Example of Less Conservative Null Sampling Distribution ci(c(b1 = .3, b2 = .4, b3 = .3), c(.01, 0, 0, .01, 0, .02), quant = ~ b1 * b2 * b3, type = "mc", plot = TRUE, plotCI = TRUE, H0 = TRUE, mu0 = c(b1 = 0, b2 = .4, b3 = 0.1) )
This function checks if the lavaan model syntax is valid. It does so by attempting to parse and fit the model in a safe environment. If the model syntax is invalid, the function will return an error message.
is_valid_lav_syntax(model, data = NULL)
is_valid_lav_syntax(model, data = NULL)
model |
A character string representing the lavaan model to be fitted. |
data |
A data frame containing the observed variables. |
A logical value indicating whether the model syntax is valid.
Davood Tofighi [email protected]
bad_model <- "y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9" data(HolzingerSwineford1939, package = "lavaan") is_valid_lav_syntax(bad_model, HolzingerSwineford1939) good_model <- "visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 visual ~ speed textual ~ speed" is_valid_lav_syntax(good_model, HolzingerSwineford1939)
bad_model <- "y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9" data(HolzingerSwineford1939, package = "lavaan") is_valid_lav_syntax(bad_model, HolzingerSwineford1939) good_model <- "visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 visual ~ speed textual ~ speed" is_valid_lav_syntax(good_model, HolzingerSwineford1939)
Fits a SEM model to each dataset in a mids
object without pooling the results.
This function is an extension for the lavaan::sem()
function to handle mice::mids objects from the mice package.
It allows for both a SEM model syntax as a character string or a pre-fitted lavaan model object.
lav_mice(model, mids, ...)
lav_mice(model, mids, ...)
model |
Either a character string representing the SEM model to be fitted or a pre-fitted lavaan model object. |
mids |
A |
... |
Additional arguments to be passed to |
A list of lavaan model fits, one for each imputed dataset.
Davood Tofighi [email protected]
## Not run: # library(mice) # library(lavaan) # Load Holzinger and Swineford (1939) dataset data("HolzingerSwineford1939", package = "lavaan") # Introduce missing data df_complete <- na.omit(HolzingerSwineford1939) amp <- mice::ampute(df_complete, prop = 0.2, mech = "MAR") data_with_missing <- amp$amp # Perform multiple imputation imputed_data <- mice::mice(data_with_missing, m = 3, maxit = 5, seed = 12345, printFlag = FALSE) # fit the Holzinger and Swineford (1939) example model HS_model <- " visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " # Fit the SEM model without running fit_HS <- lavaan::sem(HS_model, data = data_with_missing, do.fit = FALSE) # Fit the SEM model without pooling to each imputed dataset fit_list1 <- lav_mice(HS_model, imputed_data) # 'fit_list1' now contains a list of lavaan objects, one for each imputed dataset # Fit the SEM model without pooling to each imputed dataset using a pre-fitted model object fit_list2 <- lav_mice(fit_HS, imputed_data) # 'fit_list2' now contains a list of lavaan objects, one for each imputed dataset ## End(Not run)
## Not run: # library(mice) # library(lavaan) # Load Holzinger and Swineford (1939) dataset data("HolzingerSwineford1939", package = "lavaan") # Introduce missing data df_complete <- na.omit(HolzingerSwineford1939) amp <- mice::ampute(df_complete, prop = 0.2, mech = "MAR") data_with_missing <- amp$amp # Perform multiple imputation imputed_data <- mice::mice(data_with_missing, m = 3, maxit = 5, seed = 12345, printFlag = FALSE) # fit the Holzinger and Swineford (1939) example model HS_model <- " visual =~ x1 + x2 + x3 textual =~ x4 + x5 + x6 speed =~ x7 + x8 + x9 " # Fit the SEM model without running fit_HS <- lavaan::sem(HS_model, data = data_with_missing, do.fit = FALSE) # Fit the SEM model without pooling to each imputed dataset fit_list1 <- lav_mice(HS_model, imputed_data) # 'fit_list1' now contains a list of lavaan objects, one for each imputed dataset # Fit the SEM model without pooling to each imputed dataset using a pre-fitted model object fit_list2 <- lav_mice(fit_HS, imputed_data) # 'fit_list2' now contains a list of lavaan objects, one for each imputed dataset ## End(Not run)
This function computes asymptotic MBCO chi-squared test for a smooth function of model parameters including a function of indirect effects.
mbco( h0 = NULL, h1 = NULL, R = 10L, type = "asymp", alpha = 0.05, checkHess = "No", checkSE = "No", optim = "SLSQP", precision = 1e-09 )
mbco( h0 = NULL, h1 = NULL, R = 10L, type = "asymp", alpha = 0.05, checkHess = "No", checkSE = "No", optim = "SLSQP", precision = 1e-09 )
h0 |
An |
h1 |
An |
R |
The number of bootstrap draws. |
type |
If 'asymp' (default), the asymptotic MBCO chi-squares test comparing fit of h0 and h1. If 'parametric', the parametric bootstrap MBCO chi-squared test is computed. If 'semi', the semi-parametric MBCO chi-squared is computed. |
alpha |
Significance level with the default value of .05 |
checkHess |
If 'No' (default), the Hessian matrix would not be calculated. |
checkSE |
if 'No' (default), the standard errors would not be calculated. |
optim |
Choose optimizer available in OpenMx. The default optimizer is "SLSQP". Other optimizer choices are available. See mxOption for more details. |
precision |
Functional precision. The default value is set to 1e-9. See mxOption for more details. |
A list that contains
chisq |
asymptotic chi-squared test statistic value |
df |
chi-squared df |
p |
chi-squared p-value computed based on the method specified by the argument |
Davood Tofighi [email protected]
Tofighi, D., & Kelley, K. (2020). Indirect effects in sequential mediation models: Evaluating methods for hypothesis testing and confidence interval formation. Multivariate Behavioral Research, 55, 188–210. doi:10.1080/00273171.2019.1618545
Tofighi, D. (2020). Bootstrap Model-Based Constrained Optimization Tests of Indirect Effects. Frontiers in Psychology, 10, 2989. doi:10.3389/fpsyg.2019.02989
library(OpenMx) data(memory_exp) memory_exp$x <- as.numeric(memory_exp$x) - 1 # manually creating dummy codes endVar <- c("x", "repetition", "imagery", "recall") manifests <- c("x", "repetition", "imagery", "recall") full_model <- mxModel( "memory_example", type = "RAM", manifestVars = manifests, mxPath( from = "x", to = endVar, arrows = 1, free = TRUE, values = .2, labels = c("a1", "a2", "cp") ), mxPath( from = "repetition", to = "recall", arrows = 1, free = TRUE, values = .2, labels = "b1" ), mxPath( from = "imagery", to = "recall", arrows = 1, free = TRUE, values = .2, labels = "b2" ), mxPath( from = manifests, arrows = 2, free = TRUE, values = .8 ), mxPath( from = "one", to = endVar, arrows = 1, free = TRUE, values = .1 ), mxAlgebra(a1 * b1, name = "ind1"), mxAlgebra(a2 * b2, name = "ind2"), mxCI("ind1", type = "both"), mxCI("ind2", type = "both"), mxData(observed = memory_exp, type = "raw") ) ## Reduced Model for indirect effect: a1*b1 null_model1 <- mxModel( model = full_model, name = "Null Model 1", mxConstraint(ind1 == 0, name = "ind1_eq0_constr") ) full_model <- mxTryHard(full_model, checkHess = FALSE, silent = TRUE) null_model1 <- mxTryHard(null_model1, checkHess = FALSE, silent = TRUE) mbco(null_model1, full_model)
library(OpenMx) data(memory_exp) memory_exp$x <- as.numeric(memory_exp$x) - 1 # manually creating dummy codes endVar <- c("x", "repetition", "imagery", "recall") manifests <- c("x", "repetition", "imagery", "recall") full_model <- mxModel( "memory_example", type = "RAM", manifestVars = manifests, mxPath( from = "x", to = endVar, arrows = 1, free = TRUE, values = .2, labels = c("a1", "a2", "cp") ), mxPath( from = "repetition", to = "recall", arrows = 1, free = TRUE, values = .2, labels = "b1" ), mxPath( from = "imagery", to = "recall", arrows = 1, free = TRUE, values = .2, labels = "b2" ), mxPath( from = manifests, arrows = 2, free = TRUE, values = .8 ), mxPath( from = "one", to = endVar, arrows = 1, free = TRUE, values = .1 ), mxAlgebra(a1 * b1, name = "ind1"), mxAlgebra(a2 * b2, name = "ind2"), mxCI("ind1", type = "both"), mxCI("ind2", type = "both"), mxData(observed = memory_exp, type = "raw") ) ## Reduced Model for indirect effect: a1*b1 null_model1 <- mxModel( model = full_model, name = "Null Model 1", mxConstraint(ind1 == 0, name = "ind1_eq0_constr") ) full_model <- mxTryHard(full_model, checkHess = FALSE, silent = TRUE) null_model1 <- mxTryHard(null_model1, checkHess = FALSE, silent = TRUE) mbco(null_model1, full_model)
Produces confidence intervals for the mediated effect and the product of two normal random variables
medci( mu.x, mu.y, se.x, se.y, rho = 0, alpha = 0.05, type = "dop", plot = FALSE, plotCI = FALSE, n.mc = 1e+05, ... )
medci( mu.x, mu.y, se.x, se.y, rho = 0, alpha = 0.05, type = "dop", plot = FALSE, plotCI = FALSE, n.mc = 1e+05, ... )
mu.x |
mean of |
mu.y |
mean of |
se.x |
standard error (deviation) of |
se.y |
standard error (deviation) of |
rho |
correlation between |
alpha |
significance level for the confidence interval. The default value is .05. |
type |
method used to compute confidence interval. It takes on the
values |
plot |
when |
plotCI |
when |
n.mc |
when |
... |
additional arguments to be passed on to the function. |
This function returns a ()% confidence interval for
the mediated effect (product of two normal random variables). To obtain a
confidence interval using a specific method, the argument
type
should be specified. The default is type="dop"
, which uses the code
we wrote in R to implement the distribution of product of the coefficients
method described by Meeker and Escobar (1994) to evaluate the CDF of the
distribution of product. type="MC"
uses the Monte Carlo approach to
compute the confidence interval (Tofighi & MacKinnon, 2011).
type="asymp"
produces the asymptotic normal confidence interval.
Note that except for the Monte Carlo method, the standard error for the
indirect effect is based on the analytical results by Craig (1936):
. In addition, the estimate of
indirect effect is ;
type="all"
prints
confidence intervals using all four options.
A vector of lower confidence limit and upper confidence limit. When
type
is "prodclin"
(default), "DOP"
, "MC"
or
"asymp"
, medci
returns a list that contains:
(\eqn{1-\alpha})% CI |
a vector of lower and upper confidence limits, |
Estimate |
a point estimate of the quantity of interest, |
SE |
standard error of the quantity of interest, |
MC Error |
When
|
Note that when
type="all"
, medci
returns a list of four
objects, each of which a list that contains the results produced by
each method as described above.
Davood Tofighi [email protected]
Craig, C. C. (1936). On the frequency function of .
The Annals of Mathematical Statistics, 7, 1–15.
MacKinnon, D. P., Fritz, M. S., Williams, J., and Lockwood, C. M. (2007). Distribution of the product confidence limits for the indirect effect: Program PRODCLIN. Behavior Research Methods, 39, 384–389.
Meeker, W. and Escobar, L. (1994). An algorithm to compute the CDF of the product of two normal random variables. Communications in Statistics: Simulation and Computation, 23, 271–280.
Tofighi, D. and MacKinnon, D. P. (2011). RMediation: An R package for mediation analysis confidence intervals. Behavior Research Methods, 43, 692–700. doi:10.3758/s13428-011-0076-x
qprodnormal
pprodnormal
ci
RMediation-package
## Example 1 res <- medci( mu.x = .2, mu.y = .4, se.x = 1, se.y = 1, rho = 0, alpha = .05, type = "dop", plot = TRUE, plotCI = TRUE ) ## Example 2 res <- medci(mu.x = .2, mu.y = .4, se.x = 1, se.y = 1, rho = 0, alpha = .05, type = "all", plot = TRUE, plotCI = TRUE)
## Example 1 res <- medci( mu.x = .2, mu.y = .4, se.x = 1, se.y = 1, rho = 0, alpha = .05, type = "dop", plot = TRUE, plotCI = TRUE ) ## Example 2 res <- medci(mu.x = .2, mu.y = .4, se.x = 1, se.y = 1, rho = 0, alpha = .05, type = "all", plot = TRUE, plotCI = TRUE)
Data were obtained from eight replicated experiments. The data were collected on the first day of class as part of the first Dr. MacKinnon's (2018) classroom teaching. The pedagogical value of the experiment was that students would have first-hand knowledge of the experiment thereby increasing their understanding of course concepts. Permission to use the data was obtained from the university Institutional Review Board.
data(memory_exp)
data(memory_exp)
A data frame with 369 rows and 5 variables:
Replication ID, ranges from 1 to 8
Use of repetition rehearsal technique on a 1 to 9 scale
Total words recalled out of 20 words
Use of imagery rehearsal technique on a 1 to 9 scale
A factor with two levels: repetition or primary rehearsal = 0, imagery or secondary rehearsal = 1
If you use the data set, please cite the original article by MacKinnon et al. (2018) cited below.
MacKinnon, D. P., Valente, M. J., & Wurpts, I. C. (2018). Benchmark validation of statistical models: Application to mediation analysis of imagery and memory. Psychological Methods, 23, 654–671. doi:10.1037/met0000174
This function fits an OpenMx model to each imputed dataset in a 'mids' object from the 'mice' package. The function returns a list of OpenMx model fits.
mx_mice(model, mids, ...)
mx_mice(model, mids, ...)
model |
An OpenMx model object. |
mids |
A 'mids' object from the 'mice' package. |
... |
Additional arguments to be passed to 'mxRun'. |
A list of OpenMx model fits.
Davood Tofighi [email protected]
## Not run: # library(OpenMx) # library(mice) # Fit a model to multiply imputed datasets data("HolzingerSwineford1939", package = "lavaan") # Introduce missing data df_complete <- na.omit(HolzingerSwineford1939) amp <- mice::ampute(df_complete, prop = 0.2, mech = "MAR") df_incomplete <- amp$amp # Perform multiple imputation imputed_data <- mice(df_incomplete, m = 3, method = "pmm", maxit = 5, seed = 12345) # Simple SEM model specification with OpenMx manifestVars <- paste0("x", 1:9) latVar <- c("visual", "textual", "speed") model <- mxModel("Simple SEM", type = "RAM", manifestVars = manifestVars, latentVars = latVar, mxPath(from = "visual", to = c("x1", "x2", "x3")), mxPath(from = "textual", to = c("x4", "x5", "x6")), mxPath(from = "speed", to = c("x7", "x8", "x9")), mxPath(from = manifestVars, arrows = 2), mxPath(from = latVar, arrows = 2, free = FALSE, values = 1.0), mxPath(from = "one", to = manifestVars, arrows = 1, free = TRUE, values = 1.0), mxPath(from = "one", to = latVar, arrows = 1, free = FALSE, values = 0), mxData(df_complete, type = "raw") ) # Assuming mx_mice is correctly defined in your environment fits <- mx_mice(model, imputed_data) summary(fits[[1]]) ## End(Not run)
## Not run: # library(OpenMx) # library(mice) # Fit a model to multiply imputed datasets data("HolzingerSwineford1939", package = "lavaan") # Introduce missing data df_complete <- na.omit(HolzingerSwineford1939) amp <- mice::ampute(df_complete, prop = 0.2, mech = "MAR") df_incomplete <- amp$amp # Perform multiple imputation imputed_data <- mice(df_incomplete, m = 3, method = "pmm", maxit = 5, seed = 12345) # Simple SEM model specification with OpenMx manifestVars <- paste0("x", 1:9) latVar <- c("visual", "textual", "speed") model <- mxModel("Simple SEM", type = "RAM", manifestVars = manifestVars, latentVars = latVar, mxPath(from = "visual", to = c("x1", "x2", "x3")), mxPath(from = "textual", to = c("x4", "x5", "x6")), mxPath(from = "speed", to = c("x7", "x8", "x9")), mxPath(from = manifestVars, arrows = 2), mxPath(from = latVar, arrows = 2, free = FALSE, values = 1.0), mxPath(from = "one", to = manifestVars, arrows = 1, free = TRUE, values = 1.0), mxPath(from = "one", to = latVar, arrows = 1, free = FALSE, values = 0), mxData(df_complete, type = "raw") ) # Assuming mx_mice is correctly defined in your environment fits <- mx_mice(model, imputed_data) summary(fits[[1]]) ## End(Not run)
This function returns a probability corresponding to the quantile q
.
pMC(q, mu, Sigma, quant, lower.tail = TRUE, n.mc = 1e+06, ...)
pMC(q, mu, Sigma, quant, lower.tail = TRUE, n.mc = 1e+06, ...)
q |
quantile |
mu |
a vector of means (e.g., coefficient estimates) for the normal random variables. A user can assign a name to each mean value, e.g., |
Sigma |
either a covariance matrix or a vector that stacks all the columns of the lower triangle variance–covariance matrix one underneath the other. |
quant |
quantity of interest, which is a nonlinear/linear function of the model parameters. Argument |
lower.tail |
logical; if |
n.mc |
Monte Carlo sample size. The default sample size is 1e+6. |
... |
additional arguments. |
scalar probability value.
Davood Tofighi [email protected]
Tofighi, D. and MacKinnon, D. P. (2011). RMediation: An R package for mediation analysis confidence intervals. Behavior Research Methods, 43, 692–700. doi:10.3758/s13428-011-0076-x
pMC(.2, mu = c(b1 = 1, b2 = .7, b3 = .6, b4 = .45), Sigma = c(.05, 0, 0, 0, .05, 0, 0, .03, 0, .03), quant = ~ b1 * b2 * b3 * b4 )
pMC(.2, mu = c(b1 = 1, b2 = .7, b3 = .6, b4 = .45), Sigma = c(.05, 0, 0, 0, .05, 0, 0, .03, 0, .03), quant = ~ b1 * b2 * b3 * b4 )
Generates percentiles (100 based quantiles) for the distribution of product of two normal random variables and the mediated effect
pprodnormal( q, mu.x, mu.y, se.x = 1, se.y = 1, rho = 0, lower.tail = TRUE, type = "dop", n.mc = 1e+05 )
pprodnormal( q, mu.x, mu.y, se.x = 1, se.y = 1, rho = 0, lower.tail = TRUE, type = "dop", n.mc = 1e+05 )
q |
quantile or value of the product |
mu.x |
mean of |
mu.y |
mean of |
se.x |
standard error (deviation) of |
se.y |
standard error (deviation) of |
rho |
correlation between |
lower.tail |
logical; if |
type |
method used to compute confidence interval. It takes on the
values |
n.mc |
when |
This function returns the percentile (probability) and the
associated error for the distribution of product of mediated effect (two
normal random variables). To obtain a percentile using a specific method,
the argument type
should be specified. The default method is
type="dop"
, which is based on the method described by Meeker and
Escobar (1994) to evaluate the CDF of the distribution of product of two
normal random variables. type="MC"
uses the Monte Carlo approach
(Tofighi & MacKinnon, 2011). type="all"
prints percentiles using all
three options. For the method type="dop"
, the error is the modulus
of absolute error for the numerical integration (for more information see
Meeker and Escobar, 1994). For type="MC"
, the error refers to the
Monte Carlo error.
An object of the type list
that contains the
following values:
p |
probability (percentile) corresponding to
quantile |
error |
estimate of the absolute error |
Davood Tofighi [email protected]
Tofighi, D. and MacKinnon, D. P. (2011). RMediation: An R package for mediation analysis confidence intervals. Behavior Research Methods, 43, 692–700. doi:10.3758/s13428-011-0076-x
pprodnormal(q = 0, mu.x = .5, mu.y = .3, se.x = 1, se.y = 1, rho = 0, type = "all")
pprodnormal(q = 0, mu.x = .5, mu.y = .3, se.x = 1, se.y = 1, rho = 0, type = "all")
This function returns a quantile corresponding to the probability p
.
qMC(p, mu, Sigma, quant, n.mc = 1e+06, ...)
qMC(p, mu, Sigma, quant, n.mc = 1e+06, ...)
p |
probability. |
mu |
a vector of means (e.g., coefficient estimates) for the normal random variables. A user can assign a name to each mean value, e.g., |
Sigma |
either a covariance matrix or a vector that stacks all the columns of the lower triangle variance–covariance matrix one underneath the other. |
quant |
quantity of interest, which is a nonlinear/linear function of the model parameters. Argument |
n.mc |
Monte Carlo sample size. The default sample size is 1e+6. |
... |
additional arguments. |
scalar quantile value.
Davood Tofighi [email protected]
Tofighi, D. and MacKinnon, D. P. (2011). RMediation: An R package for mediation analysis confidence intervals. Behavior Research Methods, 43, 692–700. doi:10.3758/s13428-011-0076-x
qMC(.05, mu = c(b1 = 1, b2 = .7, b3 = .6, b4 = .45), Sigma = c(.05, 0, 0, 0, .05, 0, 0, .03, 0, .03), quant = ~ b1 * b2 * b3 * b4 )
qMC(.05, mu = c(b1 = 1, b2 = .7, b3 = .6, b4 = .45), Sigma = c(.05, 0, 0, 0, .05, 0, 0, .03, 0, .03), quant = ~ b1 * b2 * b3 * b4 )
Generates quantiles for the distribution of product of two normal random variables
qprodnormal( p, mu.x, mu.y, se.x, se.y, rho = 0, lower.tail = TRUE, type = "dop", n.mc = 1e+05 )
qprodnormal( p, mu.x, mu.y, se.x, se.y, rho = 0, lower.tail = TRUE, type = "dop", n.mc = 1e+05 )
p |
probability |
mu.x |
mean of |
mu.y |
mean of |
se.x |
standard error (deviation) of |
se.y |
standard error (deviation) of |
rho |
correlation between |
lower.tail |
logical; if |
type |
method used to compute confidence interval. It takes on the
values |
n.mc |
when |
This function returns a quantile and the associated error
(accuracy) corresponding the requested percentile (probability) p
of
the distribution of product of mediated effect (product of two normal
random variables). To obtain a quantile using a specific method, the
argument type
should be specified. The default method is
type="dop"
, which uses the method described by Meeker and Escobar
(1994) to evaluate the CDF of the distribution of product of two normal
variables. type="MC"
uses the Monte Carlo approach (Tofighi &
MacKinnon, 2011). type="all"
prints quantiles using all three
options. For the method type="dop"
, the error is the modulus of
absolute error for the numerical integration (for more information see
Meeker and Escobar, 1994). For type="MC"
, the error refers to the
Monte Carlo error.
An object of the type list
that contains the
following values:
q |
quantile corresponding to probability |
error |
estimate of the absolute error |
Davood Tofighi [email protected]
Tofighi, D. and MacKinnon, D. P. (2011). RMediation: An R package for mediation analysis confidence intervals. Behavior Research Methods, 43, 692–700. doi:10.3758/s13428-011-0076-x
## lower tail qprodnormal( p = .1, mu.x = .5, mu.y = .3, se.x = 1, se.y = 1, rho = 0, lower.tail = TRUE, type = "all" ) ## upper tail qprodnormal( p = .1, mu.x = .5, mu.y = .3, se.x = 1, se.y = 1, rho = 0, lower.tail = FALSE, type = "all" )
## lower tail qprodnormal( p = .1, mu.x = .5, mu.y = .3, se.x = 1, se.y = 1, rho = 0, lower.tail = TRUE, type = "all" ) ## upper tail qprodnormal( p = .1, mu.x = .5, mu.y = .3, se.x = 1, se.y = 1, rho = 0, lower.tail = FALSE, type = "all" )
Creates a data.frame for a log-likelihood object
## S3 method for class 'logLik' tidy(x, ...)
## S3 method for class 'logLik' tidy(x, ...)
x |
x A log-likelihood object, typically returned by logLik. |
... |
Additional arguments (not used) |
A data.frame with columns:
The term name
The log-likelihood value
The degrees of freedom
Davood Tofighi [email protected]
fit <- lm(mpg ~ wt, data = mtcars) logLik_fit <- logLik(fit) tidy(logLik_fit)
fit <- lm(mpg ~ wt, data = mtcars) logLik_fit <- logLik(fit) tidy(logLik_fit)