Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:31:00+00:00 2026-06-11T14:31:00+00:00

I am attempting to do a mediation analysis in R using the mediate package.

  • 0

I am attempting to do a mediation analysis in R using the mediate package. I have looked at the documentation on how to do this, and have read through the examples provided by R (i.e., I’ve already run “example(mediate)”). Despite this, I cannot get the simplest mediation to run. Ideally, I’d like to do a bootstrapping procedure, a la Preacher & Hayes (2004).

Here’s the code that I am trying to run:

model.m <- lm(desirdata1$zpers1 ~ desirdata1$zdesir1 + desirdata1$age)
model.y <- lm(desirdata1$zpers1 ~ desirdata1$age)
age1test <- mediate(model.m, model.y,treat="age", mediator="zdesir1",
                    boot=TRUE, sims=50)

Note that the dataset is called desirdata, the treatment is called age, the outcome is called zpers1 and the mediator is called “zdesir1”. When I run this, I get the following error:

Error in `[.data.frame`(m.data, , treat) : undefined columns selected

It seems to be claiming that a variable (specifically, the treatment variable) does not exist. However, running names(desirdata) shows that the variable is there, and it is named correctly, as are all of the other variables. The first two models (model.m and model.y) run fine, and the output looks as it should. It’s only the mediation model that I can’t get to run. I haven’t made a typo, as far as I can tell, and I’ve checked this a hundred times.

Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:31:01+00:00Added an answer on June 11, 2026 at 2:31 pm

    As I read the examples in the documentation, the model.m for the mediator model will have different outcome than that for the main regression object model.y. Since you haven’t described the background and what sorts of data it’s hard to be very certain of this, but wondering if you meant to type:

    model.m <- lm(zdesir1 ~  age, data=desirdata1)
    model.y <- lm(zpers1 ~ age, , data=desirdata1 )
    age1test <- mediate(model.m, model.y,treat="age", mediator="zdesir1",
                        boot=TRUE, sims=50)
    

    I cast it using formula and data objects, since some regression functions break down when just given vectors. Also makes it easier to see typos.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting to find printers / shares in Active Directory using C#. This is my
Attempting to build a C# NPAPI plugin I have found a tutorial which describes
Attempting to get Spring internationalization working. I have used classpath:messages basename, created .properties files
Attempting to use the data series from this example no longer passes the JSONLint
Attempting/struggling to get registration and sign-up working within an active admin project. I have
Attempting to set up Samba + OpenLDAP using nss_ldap. After joining Windows7 to Samba
Attempting to generics-ify some legacy code, I'm stuck. I have a ParentObject which wraps
Attempting to follow this Java tutorial . About 63 pages in, you are instructed
When attempting a file upload to an Alfresco Server using ssl the server logs
Attempting to upload a video, and this is the response I get back (after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.