Giter Site home page Giter Site logo

modmed's Introduction

modmed

Edwards Moderated Mediation in R

Estimate Models

This helper script runs Edwards & Lambert’s (2007) moderated mediation analysis using basic OLS regressions from Equations 5 and 20 of the article. The first step is to estimate both regression models using lm(). Something like:

lmm <- lm(m ~ {controls} + x + xz + z,data=dat)
lmy <- lm(y ~ {controls} + x + xz + z + m,data=dat)

Bootstrap and calculate CI’s

After estimating both models, bootstrap samples from the data and recompute the same models. Then compute confidence intervals for those distributions. Note that at present the script only computes the percentile method (the bias-corrected CI would be better in a revised version).

source('edwards.modmed.R')
coefs <- bootstrap(lmm,lmy,dat)
edwards.modmed(coefs=coefs,lmm=lmm,lmy=lmy,zlevels=c(-1*sd(dat$z),sd(dat$z)),p=.05)

The z-levels here assume z is centered (a mean of zero simplifies calculating the levels of z to calculate the effect of x). These should be adjusted if z is not centered.

modmed's People

Contributors

pdownes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.