Title: | Quantitative Psychology Tools |
---|---|
Description: | Contains tools useful for data screening, testing moderation (Cohen et. al. 2003)<doi:10.4324/9780203774441>, mediation (MacKinnon et. al. 2002)<doi:10.1037/1082-989x.7.1.83> and estimating power (Murphy & Myors 2014)<ISBN:9781315773155>. |
Authors: | Thomas D. Fletcher |
Maintainer: | Thomas D. Fletcher <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.6 |
Built: | 2025-02-15 04:09:30 UTC |
Source: | https://github.com/cran/QuantPsyc |
Contains tools useful in screening univariate and multivariate data, testing simple moderating relationships (Cohen et. al. 2003)<doi:10.4324/9780203774441>, extimating indirect effects based on simple (proximal) and complex (distal) mediating relationships(MacKinnon et. al. 2002)<doi:10.1037/1082-989x.7.1.83> . A tool for computing power in a given F distribution is also included (Murphy & Myors 2014)<ISBN:9781315773155>. These are basic operations covered in a multivariate course in most Doctoral level Psychology programs. THese functions will also likely be useful in other domains (e.g., sociology, business management, medicine).
Package: | QuantPsyc |
Type: | Package |
Version: | 1.6 |
Date: | 2022-05-27 |
License: | GPL (version 2 or later) |
These functions can be grouped into 4 sets.
Data Screening
Moderation
Mediation
Power Calculation
Data Screening tools include both graphical and statistical methods for assessing the shape of the distributions as well as look for any outliers. Key functions include norm
and mult.norm
. Moderation functions are based on Aiken & West (1991) and Cohen, Cohen, West & Aiken (2003). Currently, only simple models are permissible (Y ~ X + Z + XZ). Key functions include moderate.lm
, sim.slopes
, and graph.mod
. Mediation functions are largely based on MacKinnon et al (2002) and Fletcher (2006). Both simple (one mediator) and complex (chain of two mediators) relationships can be estimated. Key functions include proximal.med
, and distal.med
. Finally, powerF
will calculate power based on an F distribution given percent variance accounted for (e.g. effect size) and degrees of freedom (e.g., model parameters and sample size). Some of the functions are original and others borrowed from numerous sources. I have taken care to reference appropriately.
Thomas D. Fletcher
Maintainer: Thomas D. Fletcher <[email protected]>
Aiken, L. S., & West, S. G. (1991). Multiple regression: Testing and interpreting interactions. Newbury Park: Sage Publications.
Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analysis for the behavioral sciences, 3rd ed. Mahwah, NJ: Lawrence Erlbaum Associates.
Fletcher, T. D. (2006, August). Methods and approaches to assessing distal mediation. Paper presented at the 66th annual meeting of the Academy of Management, Atlanta, GA.
Khattree, R. & Naik, D. N. (1999). Applied multivariate statistics with SAS software (2nd ed.). Cary, NC: SAS Institute Inc.
MacKinnon, D. P., Lockwood, C. M., Hoffman, J. M., West, S. G., & Sheets, V. (2002). A comparison of methods to test mediation and other intervening variable effects. Psychological Methods, 7, 83-104.
Murphy, K. R., & Myors, B. (2004). Statistical power analysis: A simple and general model for traditional and modern hypothesis tests (2nd ed.). Mahwah, NJ: Lawrence Erlbaum Associates.
# Data Screening data(USJudgeRatings) norm(USJudgeRatings$CONT) mult.norm(USJudgeRatings[,1:4]) # Moderation data(tra) lm.mod1 <- moderate.lm(beliefs, values, attitudes, tra) ss.mod1 <- sim.slopes(lm.mod1,meanCenter(tra$values)) summary(lm.mod1) ss.mod1 # use mouse click to place legend in graph.mod # graph.mod(ss.mod1,beliefs,attitudes,tra,"Interaction Example") # Mediation # create object with names x, m, y # data(tra) temp.tra <- tra names(temp.tra) <- c("x", "z", "m", "y") proximal.med(temp.tra)
# Data Screening data(USJudgeRatings) norm(USJudgeRatings$CONT) mult.norm(USJudgeRatings[,1:4]) # Moderation data(tra) lm.mod1 <- moderate.lm(beliefs, values, attitudes, tra) ss.mod1 <- sim.slopes(lm.mod1,meanCenter(tra$values)) summary(lm.mod1) ss.mod1 # use mouse click to place legend in graph.mod # graph.mod(ss.mod1,beliefs,attitudes,tra,"Interaction Example") # Mediation # create object with names x, m, y # data(tra) temp.tra <- tra names(temp.tra) <- c("x", "z", "m", "y") proximal.med(temp.tra)
Provides a Classification analysis for a logistic regression model. Also provides McFadden's Rsq.
ClassLog(MOD, resp, cut=.5)
ClassLog(MOD, resp, cut=.5)
MOD |
Model of class glm where family is bonomial |
resp |
response variable from data |
cut |
Arbitrary cut for the proportion deemed '1' in model |
A list containing: /CR
rawtab two-way table of classifications as frequencies
classtab two-way table of classifications as percentages
overall Overall percent classifications that are correct
mcFadden McFaddens pseudoRsq; 1 - ModelDeviance / NullDeviance
This is a primative function. I have a long to do list. For example, it is not yet written to handle missing observations.
Thomas D. Fletcher [email protected]
# create some data x <- rnorm(100) y <- as.numeric(cut(.5*x + rnorm(100), breaks=2))-1 tdf <- data.frame(x=x, y=y) # run a logistic regression glm1 <- glm(y ~ x, data=tdf, family=binomial) # Get typical summary of results summary(glm1) # Classification Analysis ClassLog(glm1, tdf$y)
# create some data x <- rnorm(100) y <- as.numeric(cut(.5*x + rnorm(100), breaks=2))-1 tdf <- data.frame(x=x, y=y) # run a logistic regression glm1 <- glm(y ~ x, data=tdf, family=binomial) # Get typical summary of results summary(glm1) # Classification Analysis ClassLog(glm1, tdf$y)
Computes the indirect effect (and all paths) in a 4 variable system, assuming all paths estimated.
distal.med(data)
distal.med(data)
data |
data.frame containing the variables labeled 'x', 'm1', 'm2', and 'y' respectively. |
Computes the paths in the model system: /cr
Y = t'X + fM1 + cM2
M2 = eX + bM1
M1 = aX
and the indirect effect a*b*c + a*f + e*c
Returns a table with all the effects and decomposition of effects in the above 4 variable system inclucing the standard errors and t-values.
a |
Effect of X on M1 |
b |
Effect of M1 on M2 controlling for X |
c |
Effect of M2 on Y controlling for X and M1 |
e |
Effect of X on M2 controlling for M1 |
f |
Effect of M1 on Y controlling for X and M2 |
abc |
'Direct' Indirect Effect of X on Y |
af |
Indirect Effect of X on Y through M1 only |
ef |
Indirect Effect of M1 on Y though M2 |
ind.xy |
'Total' Indirect effect of X on Y |
t |
Total Effect of X on Y |
t' |
Direct Effect of X on Y accounting for all mediators |
This function is primative in that it is based on a simplistic model AND forces the user to name the variables in the dataset x, m1, m2, and y.
This function uses the following undocumented functions: se.indirect3
Thomas D. Fletcher [email protected]
Fletcher, T. D. (2006, August). Methods and approaches to assessing distal mediation. Paper presented at the 66th annual meeting of the Academy of Management, Atlanta, GA.
MacKinnon, D. P., Lockwood, C. M., Hoffman, J. M., West, S. G., & Sheets, V. (2002). A comparison of methods to test mediation and other intervening variable effects. Psychological Methods, 7, 83-104.
cormat <- matrix (c(1,.3,.15,.075,.3,1,.3,.15,.15,.3,1,.3,.075,.15,.3,1),ncol=4) require(MASS) d200 <- data.frame(mvrnorm(200, mu=c(0,0,0,0), cormat)) names(d200) <- c("x","m1","m2","y") distal.med(d200)
cormat <- matrix (c(1,.3,.15,.075,.3,1,.3,.15,.15,.3,1,.3,.075,.15,.3,1),ncol=4) require(MASS) d200 <- data.frame(mvrnorm(200, mu=c(0,0,0,0), cormat)) names(d200) <- c("x","m1","m2","y") distal.med(d200)
Computes the 'total indirect effect' from distal.med
for use in boot
distInd.ef(data, i)
distInd.ef(data, i)
data |
data.frame used in |
i |
|
This function is not useful of itself. It is specifically created as an intermediate step in bootstrapping the indirect effect.
indirect effect that is passed to boot for each bootstrap sample
Thomas D. Fletcher [email protected]
Davison, A. C. & Hinkley, D. V. (1997). Bootstrap methods and their application. Cambridge, UK: Cambridge University Press.
Fletcher, T. D. (2006, August). Methods and approaches to assessing distal mediation. Paper presented at the 66th annual meeting of the Academy of Management, Atlanta, GA.
MacKinnon, D. P., Lockwood, C. M., Hoffman, J. M., West, S. G., & Sheets, V. (2002). A comparison of methods to test mediation and other intervening variable effects. Psychological Methods, 7, 83-104.
MacKinnon, D. P., Lockwood, C. M., & Williams, J. (2004). Confidence limit for indirect effect: distribution of the product and resampling methods. Multivariate Behavioral Research, 39, 99-128.
cormat <- matrix (c(1,.3,.15,.075,.3,1,.3,.15,.15,.3,1,.3,.075,.15,.3,1),ncol=4) require(MASS) d200 <- data.frame(mvrnorm(200, mu=c(0,0,0,0), cormat)) names(d200) <- c("x","m1","m2","y") require(boot) distmed.boot <- boot(d200, distInd.ef, R=999) sort(distmed.boot$t)[c(25,975)] #95% CI plot(density(distmed.boot$t)) # Distribution of bootstapped indirect effect summary(distmed.boot$t)
cormat <- matrix (c(1,.3,.15,.075,.3,1,.3,.15,.15,.3,1,.3,.075,.15,.3,1),ncol=4) require(MASS) d200 <- data.frame(mvrnorm(200, mu=c(0,0,0,0), cormat)) names(d200) <- c("x","m1","m2","y") require(boot) distmed.boot <- boot(d200, distInd.ef, R=999) sort(distmed.boot$t)[c(25,975)] #95% CI plot(density(distmed.boot$t)) # Distribution of bootstapped indirect effect summary(distmed.boot$t)
This function is a modified version of eda.shape
found in the S+ Guide to Statistics, v1, p. 124. It is based on work by Tukey (1977) and each plot is described in more detail in Ch. 4 of Cohen et al. Creates 4 plots useful in assesing univariate distributions of data.
eda.uni(x, title = "")
eda.uni(x, title = "")
x |
A univariate data object such as column of variable from a data.frame() |
title |
Title printed above first plot in upper left corner |
Simply provides a histogram, smoothed histogram, qq-plot, and boxplot for x.
A single graph object with 4 basic plots.
Thomas D. Fletcher [email protected]
Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/ correlation analysis for the behavioral sciences, 3rd ed. Mahwah, NJ: Lawrence Erlbaum Associates. Chapter 4, Data Visualization, exploration, and assumption checking: Diagnosing and solving regression problems.
Insightful (2001). S-Plus 6 for Windows Guide to Statistics, Volume 1. Seattle: Insightful.
Tukey (1977). Exploratory Data Analysis. Reading, MA: Addison-Wesley.
hist
, plot.density
, qqnorm
, boxplot
# create negatively skewed dat with 100 observations xc <- -rchisq(100,3) eda.uni(xc)
# create negatively skewed dat with 100 observations xc <- -rchisq(100,3) eda.uni(xc)
x-y plot containing the simple slopes conditioned on z.
graph.mod(ssmod, x, y, data, title = "", xlab = "Centered X", ylab = "Raw Y", ylimit = 1.5, ...)
graph.mod(ssmod, x, y, data, title = "", xlab = "Centered X", ylab = "Raw Y", ylimit = 1.5, ...)
ssmod |
Results of |
x |
Explanatory variable to be used in xyplot |
y |
Outcome variable to be used in xyplot |
data |
data.frame containing x, z, y |
title |
Optional 'main' title for the plot |
xlab |
x-axis label |
ylab |
y-axis label |
ylimit |
used as a multiple of SDy to define the limits of the y-axis |
... |
to be determined ... |
Given moderate.lm
and sim.slopes
, this function plots x,y and adds the simple slopes corresponding to arbitrary values of z defined in sim.slopes
. Users must 'click' on an area to add the legend.
A plot object.
This is based on a simple 3 variable moderation model with continuous variables. Users must modify the functions to accomodate other models (e.g., categorical moderators, covariates)
Thomas D. Fletcher [email protected]
Aiken, L. S., & West, S. G. (1991). Multiple regression: Testing and interpreting interactions. Newbury Park: Sage Publications.
Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analysis for the behavioral sciences, 3rd ed. Mahwah, NJ: Lawrence Erlbaum Associates.
data(tra) lm.mod1 <- moderate.lm(beliefs, values, attitudes, tra) ss.mod1 <- sim.slopes(lm.mod1, tra$values) ## requires user interaction ## graph.mod(ss.mod1,beliefs,attitudes,tra,"Interaction Example")
data(tra) lm.mod1 <- moderate.lm(beliefs, values, attitudes, tra) ss.mod1 <- sim.slopes(lm.mod1, tra$values) ## requires user interaction ## graph.mod(ss.mod1,beliefs,attitudes,tra,"Interaction Example")
Computes the standardized regression coeffients (beta) from an object of class (lm)
lm.beta(MOD)
lm.beta(MOD)
MOD |
MOD is object from |
A "numeric" representing each standardized coefficient from lm() model
This function does not produce 'correct' standardized coefficients when interaction terms are present
Thomas D. Fletcher [email protected]
us <- USJudgeRatings names(us) lm1 <- lm ( CONT ~ INTG + DMNR + DILG, us) lm.beta(lm1) # Standardized data (using Make.Z()) usz <- data.frame (Make.Z (us)) lm1.z <- lm ( CONT ~ INTG + DMNR + DILG, usz) # compare standardized data versus lm.beta summary(lm1.z)
us <- USJudgeRatings names(us) lm1 <- lm ( CONT ~ INTG + DMNR + DILG, us) lm.beta(lm1) # Standardized data (using Make.Z()) usz <- data.frame (Make.Z (us)) lm1.z <- lm ( CONT ~ INTG + DMNR + DILG, usz) # compare standardized data versus lm.beta summary(lm1.z)
Converts data to standard normal (mean = 0; SD = 1) - i.e., z-scores.
Make.Z(x)
Make.Z(x)
x |
Any data object (especially useful for multiple columns of a data.frame). |
Takes the data (by columns if necessary) and subtracts out the mean and then divides by the standard deviation. The result is a standard normal z score.
A numeric or matrix containing standardized data (i.e., z scores)
The result is a matrix. One may wish to convert to data.frame or use as.data.frame(Make.Z(x))
Thomas D. Fletcher [email protected]
zUSJR <- Make.Z(USJudgeRatings) # creates new object containg z scores dim(zUSJR) # shows that there are 43 observed z scores for 12 variables zUSJR[,1] # to look at only the first column of z scores
zUSJR <- Make.Z(USJudgeRatings) # creates new object containg z scores dim(zUSJR) # shows that there are 43 observed z scores for 12 variables zUSJR[,1] # to look at only the first column of z scores
This simple function subtracts the mean from a variable rendering mean-centered variables.
meanCenter(x)
meanCenter(x)
x |
variable or column of data to be centered |
This is particularly useful in lm() with higher order terms as in moderation.
a numeric; mean centered 'x'
Thomas D. Fletcher [email protected]
data(USJudgeRatings) usCONT <- meanCenter(USJudgeRatings$CONT) summary(usCONT)
data(USJudgeRatings) usCONT <- meanCenter(USJudgeRatings$CONT) summary(usCONT)
This function creates an object of class lm() specific to a moderated multiple regression involving 3 variables.
moderate.lm(x, z, y, data, mc = FALSE)
moderate.lm(x, z, y, data, mc = FALSE)
x |
focal explanatory variable |
z |
moderating variable |
y |
outcome variable |
data |
data.frame containing the variables |
mc |
Logical specifying wheter the data are already mean centered |
This model takes x and z and creates the interaction term x*z. If the data are not already mean centered, then x and z are mean centered by subtracting out the means. This is necessary for interpretation and to reduce multicolinearity. The lm() is then computed thusly: Y ~ X + Z + XZ.
An object of class lm(). One can use summary(), coef() or any other function useful to lm(). This model is used by other moderator tools - see below.
This is a very simplistic model. If x or z are categorical, the results will not be accurate. The function can be modified by the user to deal with complications such as covariates, non-continuous variables, etc.
Thomas D. Fletcher [email protected]
Aiken, L. S., & West, S. G. (1991). Multiple regression: Testing and interpreting interactions. Newbury Park: Sage Publications.
Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analysis for the behavioral sciences, 3rd ed. Mahwah, NJ: Lawrence Erlbaum Associates.
data(tra) lm.mod1 <- moderate.lm(beliefs, values, attitudes, tra) summary(lm.mod1)
data(tra) lm.mod1 <- moderate.lm(beliefs, values, attitudes, tra) summary(lm.mod1)
Returns tests for multivariate Skewness and kurtosis as well as Mahalanobis' D-squared.
mult.norm(x, s = var(x), chicrit = 0.005)
mult.norm(x, s = var(x), chicrit = 0.005)
x |
A multivariate data object as in columns from a data.frame |
s |
Covariance matrix of x (not necessary to specify) |
chicrit |
p-value corresponding to critical value of chi-square distribution for detecting multivariate outliers |
Tests for multivariate skewness and kurtosis were adapted from SAS macros in Khatree & Naik (1999). They attribute the formula to Mardia (1970; 1974). Mahalanobis' Dsq is based on Mahalanobis (1936). Dsq is multivariate analogue to z scores, but based on the chi-sq distribution rather than normal distribution. Once can specify at what level one wishes to define multivariate outliers (e.g., .005, .001)
A list containing the following:
mult.test |
Values for multivariate skeweness and kurtosis and their significance |
Dsq |
Mahalanobis' distances |
CriticalDsq |
Critical value of chi-sq distribution based on df and specified critical level |
Mahalanobis is returned without regard to NAs (missing observations) and is useful only in detecting IF multivariate outliers are present. If one wishes to determine which cases are multivariate outliers and if one has missing observations, mahalanobis
is perhaps a better choice.
These statistics are known to be susceptible to sample size (as in their univariate counterparts). One should always use graphical methods such as qqplot
in addition to statistical.
Thomas D. Fletcher [email protected]
Khattree, R. & Naik, D. N. (1999). Applied multivariate statistics with SAS software (2nd ed.). Cary, NC: SAS Institute Inc.
# assess the multivariate normality of variables 4,5,6 in USJudgeRatings data(USJudgeRatings) mn <- mult.norm(USJudgeRatings[,4:6],chicrit=.001) mn mn$Dsq > mn$CriticalDsq
# assess the multivariate normality of variables 4,5,6 in USJudgeRatings data(USJudgeRatings) mn <- mult.norm(USJudgeRatings[,4:6],chicrit=.001) mn mn$Dsq > mn$CriticalDsq
Computes Skewness and Kurtosis of data.
norm(x) Skew(x) Kurt(x)
norm(x) Skew(x) Kurt(x)
x |
A data object such as a numeric or column from a data.frame |
norm
returns a table containing Skew
& Kurt
. Each contain the following elements:
Statistic |
value for Skewness or Kurtosis respectively |
SE |
Standard error for Skewness or Kurtosis |
t-val |
t or z ratio - Statistic/SE |
p |
p value associated with z distribution |
These statistics should be used with caution as they are influenced by sample size!
Thomas D. Fletcher [email protected]
# create negatively skewed dat with 100 observations xc <- -rchisq(100,3) norm(xc)
# create negatively skewed dat with 100 observations xc <- -rchisq(100,3) norm(xc)
Convert data to Normal Scores with the same Mean and SD. This reshapes data to conform to a Normal Distribution. It is not converting to z-scores (i.e., it is not standardizing data)
Normalize(x)
Normalize(x)
x |
Data to be normalized. Should be vector of scores |
A numeric with the same Mean and SD as x, but without skew or kurtosis
This is a primative function. I have a long to do list. For example, it is not yet written to handle missing observations.
Thomas D. Fletcher [email protected]
Joreskog, K., Sorbom, D., du Toit, S., & du Toit, M. (2000). LISREL 8: New Statistical Features. SSI.
Snippets of code were borrowed and modified from: http://zoonek2.free.fr/UNIX/48_R/03.html
summary(USJudgeRatings$CONT) plot(density(USJudgeRatings$CONT)) ContN <- Normalize(USJudgeRatings$CONT) summary(ContN) lines(density(ContN), col=2)
summary(USJudgeRatings$CONT) plot(density(USJudgeRatings$CONT)) ContN <- Normalize(USJudgeRatings$CONT) summary(ContN) lines(density(ContN), col=2)
Plots the density distribution of 'x' (e.g., smoothed histogram) with an overlaying normal density plot with the same mean and SD. This is useful for 'seeing' the degree of deviance from normality.
plotNormX(x) plotNormXm(x, im)
plotNormX(x) plotNormXm(x, im)
x |
any data object such as a column(s) or variable(s) from a data.frame |
im |
number of items in x-multivariate to be plotted |
plotNormX
is useful for single use (univariate) objects, but plotNormXm
is more useful for creating multiple graphs (i.e., multivariate) as in sending graphs to a postcript or pdf device. See examples below.
A graph of density of x.
Thomas D. Fletcher [email protected]
# plot.normX data(USJudgeRatings) # data packaged with R plotNormX(USJudgeRatings$CONT) # plot all 12 variables in USJudgeRatings, using function plotNormXm data(USJudgeRatings) plotNormXm(USJudgeRatings, 12)
# plot.normX data(USJudgeRatings) # data packaged with R plotNormX(USJudgeRatings$CONT) # plot all 12 variables in USJudgeRatings, using function plotNormXm data(USJudgeRatings) plotNormXm(USJudgeRatings, 12)
Computes power (1 - beta) to detect an effect with a given effect size, sample size (df) and specified alpha (significance) level.
powerF(PV, df2, df1 = 1, alpha = 0.05)
powerF(PV, df2, df1 = 1, alpha = 0.05)
PV |
Percent of variance accounted for by effect. |
df2 |
Denominator Degrees of Freedom for a given model |
df1 |
Numerator Degrees of Freedom for a given model |
alpha |
Significance level for desired effect |
Murphy & Myors (2004) detail the use of a similar function and the notion that most distributions can be converted to F. Therefore, they argue that the F distribution is the most versatile in computing power. Typically, alpha is set at .05 (default). Users will likely find conversions of various distributions to F corresponding to a df1=1 (default). Therefore, users can manipulate df2 based on their model to estiamte sample size needs. Likewise, one may begin with a given sample size (i.e., df2) and manipulate PV (effect size) to iteratively determine what power their study is likely to detect. Conventions maintain that .80 is a sufficient target, and that no study shold be designed with power = .5 or less.
A numeric value representing the power to detect the effect
It is critical that the user correctly specify the model for which the effect is obtained. For instance, if a single coeficient from a regression model is the object of inquiry (e.g., interaction effect in moderation model), the DF should reflect that effect and not the overall model, which also contains the 'main effects'.
Thomas D. Fletcher [email protected]
Murphy, K. R., & Myors, B. (2004). Statistical power analysis: A simple and general model for traditional and modern hypothesis tests (2nd ed.). Mahwah, NJ: Lawrence Erlbaum Associates.
# Simulated TRA example data(tra) lm1 <- lm (attitudes ~ beliefs*values, tra) summary(lm1) # power to detect the interaction effect, where df1 = 1 and df2 = n-k-1 = 996 # PV = t^2/(t^2+df2) = .1863 powerF(.1863, 996) # Estimate sample size needed to detect interaction effect with PV = .01 and power = .8 powerF(.01, 200) # too low powerF(.01, 1000) # too high powerF(.01, (800-3-1)) # just right: n=800 - k=3 - 1
# Simulated TRA example data(tra) lm1 <- lm (attitudes ~ beliefs*values, tra) summary(lm1) # power to detect the interaction effect, where df1 = 1 and df2 = n-k-1 = 996 # PV = t^2/(t^2+df2) = .1863 powerF(.1863, 996) # Estimate sample size needed to detect interaction effect with PV = .01 and power = .8 powerF(.01, 200) # too low powerF(.01, 1000) # too high powerF(.01, (800-3-1)) # just right: n=800 - k=3 - 1
Computes the Indirect Effect for a simple 3 variable mediation model: X -> M -> Y assuming direct effect X -> Y
proximal.med(data)
proximal.med(data)
data |
data.frame containing the variables labeled 'x', 'm', and 'y' respectively. |
This function computes all paths in the simple 3 variable system involving the following regressions:
Y = t'X + bM, and
M = aX
where t' + ab = t
The indirect effect is computed as the product of a*b. Several formula are used for the computation of the standard error for the indirect effect (see MacKinnon et al for a comprehensive review).
As noted below, one can use this function to create the indirect effect and then utilize bootstrapping for a more accurate estimate of the standard error and model the distribution of the direct effect.
Creates a table containing the following effects, their standard errors, and t-values :
a |
Effect of X on M |
b |
Effect of M on Y controlling for X |
t |
Total effect of X on Y |
t' |
Direct effect of X on Y accounting for M |
ab |
Indirect effect of X on Y though M |
Aroian |
Standard error of ab using Aroian method |
Goodman |
Standard error of ab using Goodman method |
Med.Ratio |
Mediation Ratio: indirect effect / total effect |
This function is primative in that it is based on a simplistic model AND forces the user to name the variables in the dataset x, m, and y.
This function uses the following undocumented functions: aroian.se.indirect2
, goodman.se.indirect2
, se.indirect2
Thomas D. Fletcher [email protected]
MacKinnon, D. P., Lockwood, C. M., Hoffman, J. M., West, S. G., & Sheets, V. (2002). A comparison of methods to test mediation and other intervening variable effects. Psychological Methods, 7, 83-104.
data(tra) tmp.tra <- tra names(tmp.tra) <- c('x','z','m','y') data.frame(proximal.med(tmp.tra)) ## data.frame() simple makes the table 'pretty'
data(tra) tmp.tra <- tra names(tmp.tra) <- c('x','z','m','y') data.frame(proximal.med(tmp.tra)) ## data.frame() simple makes the table 'pretty'
Calculates the indirect effect from proximal.med
in a form useful to send to boot
proxInd.ef(data, i)
proxInd.ef(data, i)
data |
data.frame used in |
i |
|
This function is not useful of itself. It is specifically created as an intermediate step in bootstrapping the indirect effect.
indirect effect that is passed to boot for each bootstrap sample
Thomas D. Fletcher [email protected]
Davison, A. C. & Hinkley, D. V. (1997). Bootstrap methods and their application. Cambridge, UK: Cambridge University Press.
MacKinnon, D. P., Lockwood, C. M., Hoffman, J. M., West, S. G., & Sheets, V. (2002). A comparison of methods to test mediation and other intervening variable effects. Psychological Methods, 7, 83-104.
MacKinnon, D. P., Lockwood, C. M., & Williams, J. (2004). Confidence limit for indirect effect: distribution of the product and resampling methods. Multivariate Behavioral Research, 39, 99-128.
require(boot) data(tra) tmp.tra <- tra names(tmp.tra) <- c('x','z','m','y') med.boot <- boot(tmp.tra, proxInd.ef, R=999) sort(med.boot$t)[c(25,975)] #95% CI plot(density(med.boot$t)) # Distribution of bootstapped indirect effect summary(med.boot$t)
require(boot) data(tra) tmp.tra <- tra names(tmp.tra) <- c('x','z','m','y') med.boot <- boot(tmp.tra, proxInd.ef, R=999) sort(med.boot$t)[c(25,975)] #95% CI plot(density(med.boot$t)) # Distribution of bootstapped indirect effect summary(med.boot$t)
Computes the simple slopes for a moderated regression model.
sim.slopes(mod, z, zsd = 1, mcz = FALSE)
sim.slopes(mod, z, zsd = 1, mcz = FALSE)
mod |
linear model - usually constructed with |
z |
moderating variable |
zsd |
Multiple for SD of z; number of SDs from mean to construct simple slopes |
mcz |
logical whether z is already centered or not in the original data |
Constructs the simple slopes for arbitrary values of z (e.g., +/- 1, 2, 3 standard deviations) involved in a moderated multiple regression equation.
A table with the following values for zHigh (Meanz + zsd*SDz), Mean(Meanz), and zLow (Meanz - zsd*SDz):
INT |
Intercept of simple slope |
Slope |
Slope of the simple slope |
SE |
Standard Error of the slope |
LCL , UCL
|
Lower and Upper confidence limits for slope |
Thomas D. Fletcher [email protected]
Aiken, L. S., & West, S. G. (1991). Multiple regression: Testing and interpreting interactions. Newbury Park: Sage Publications.
Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analysis for the behavioral sciences, 3rd ed. Mahwah, NJ: Lawrence Erlbaum Associates.
data(tra) lm.mod1 <- moderate.lm(beliefs, values, attitudes, tra) ss.mod1 <- sim.slopes(lm.mod1, tra$values) ss.mod1
data(tra) lm.mod1 <- moderate.lm(beliefs, values, attitudes, tra) ss.mod1 <- sim.slopes(lm.mod1, tra$values) ss.mod1
Simulated data loosely based on the Theory of Reasoned Action from Social Psychology. Similar data are frequently used in publications involving moderation and mediation. These data were created for illustrative purposes.
data(tra)
data(tra)
A data frame with 1000 observations on the following 4 variables.
beliefs
a numeric vector
values
a numeric vector
attitudes
a numeric vector
intentions
a numeric vector
The data were constructed with the following model(s) in mind. Attitudes are a function of beliefs as moderated by values. Beliefs lead to intentions though their association with attitudes.
data(tra) str(tra) eda.uni(tra$intentions)
data(tra) str(tra) eda.uni(tra$intentions)