Looking for the correct command for a sensitivity analysis with three serial mediators, a categorical independent variable and a continuous outcome.

169 views
Skip to first unread message

Hyeseung Koh

unread,
Jun 3, 2022, 4:17:21 AM6/3/22
to lavaan
Hello, 

I am trying to find a correct command that shows how to do a sensitivity power analysis in R for a model with 3 serial mediators, a categorical independent variable and a continuous outcome. 

Please help me find the command.  


Mauricio Garnier-Villarreal

unread,
Jun 3, 2022, 11:53:17 AM6/3/22
to lavaan
Do you mean a power sensitivity analysis? Find at a specific sample size what effect size can be rejected with 80% power for example?

If so, you can do this with the simsem package, you can create whatever population model maybe like this example

Hyeseung Koh

unread,
Jun 3, 2022, 12:16:39 PM6/3/22
to lav...@googlegroups.com
I am not sure how it is called. Would you explain how indirect effects could be created and estimated using the simsem?

When my population model includes the designated lettered-value for each path, I could create and estimate the indirect effects after I assign the numbered-value for each letter. How can I create and estimate the indirect effects in the analysis model that corresponds to the pop.model? It is not a CFA model. It is a path analysis using observed variables. 

###### population model
pop.model <- "
# regression part
dv ~ d*med3 + e*med2 + f*med1 + g*iv
med3 ~ c*med2
med2 ~ b*med1
med1 ~ a*iv

#indirect effect
af:=a*f
abe:=a*b*e
abcd:=a*b*c*d

#direct effect
g:=g

#total effect :=
g +af + abe+ abcd"

##### analysis model
analysis.model <-"
#regression part
dv ~ med3 + med2 + med1 + iv
med3 ~ med2
med2 ~ med1
med1 ~ iv

#indirect effect
"


-- 
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/3f1de576-cb9e-4cea-aceb-dc0b8e03affbn%40googlegroups.com.

Mauricio Garnier-Villarreal

unread,
Jun 3, 2022, 12:57:56 PM6/3/22
to lavaan
You would write the population model with the regression values that you expect, so just change the letter for the slopes (only direct effects)

For example (making up numbers that probably make no sense):

pop.model <- "
# regression part
dv ~ 0.5*med3 + 0.5*med2 + 0.5*med1 + 0.5*iv
med3 ~ 0.5*med2
med2 ~ 0.5*med1
med1 ~ 0.5*iv
"

And then the analysis model would be the one with all the labels and calculated parameters. This way simsem will take the indirect effects as part of the estmated parameters for which you can find power etc

analysis .model <- "
# regression part
dv ~ d*med3 + e*med2 + f*med1 + g*iv
med3 ~ c*med2
med2 ~ b*med1
med1 ~ a*iv

#indirect effect
af:=a*f
abe:=a*b*e
abcd:=a*b*c*d

#direct effect
g:=g

#total effect :=
g +af + abe+ abcd"

Hyeseung Koh

unread,
Jun 3, 2022, 3:09:30 PM6/3/22
to lav...@googlegroups.com
Given a sample size with alpha=.05 and 80% power, which part of the output do you check to find what effect size can be observable at a medium level? Also, which part of the output do you check to find what effect size can be observable at a medium level when 90% power while holding the sample size and alpha level constant ? 



Mauricio Garnier-Villarreal

unread,
Jun 4, 2022, 1:19:32 PM6/4/22
to lavaan
That part is not automated in simsem. In simsem you can run the simulation through a range of sample size and find the sample size for a specific effect size. You cannot do that to find the effect size has 80% power at a specific sample size.

You would have to do this step by step:
1- run the "normal" simulation at your sample size, with like 500 replication for the model at A effect size
2- find the power at that effect size
3- change effect size A for effect size B, and run the simulation again
4- repeat until you find the effect size at which you have

You change the effect size from A to B depending on the results of step 2. So, f the power is lower than 80% you need to increase the effect size, and if the power is larger than 80% you need to decrease the effect size

This should take a couple of steps, but still should be doable in a few models to find the desire values

Alex Schoemann

unread,
Jun 4, 2022, 9:39:30 PM6/4/22
to lavaan
One correction. In simsem you can vary both parameter values (or both sample size and parameter values) across replications to find power for a given parameter at a given sample size. To do so you need to use the simsem matrix style for model specification (not lavaan syntax). See example 20 from the simsem vignette: https://github.com/simsem/simsem/wiki/Example-20:-Simulation-with-Varying-Sample-Size-and-Parameters

Hyeseung Koh

unread,
Jun 5, 2022, 12:44:45 AM6/5/22
to lav...@googlegroups.com
To Alex Schoemann:

How to set up indirect effects in the matrix style when there are serial multiple mediators? 

-- 
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.

Hyeseung Koh

unread,
Jun 5, 2022, 3:12:12 AM6/5/22
to lav...@googlegroups.com
To be clear, To Alex Schoemann <alexander...@gmail.com>

Alex Schoemann

unread,
Jun 5, 2022, 7:21:09 PM6/5/22
to lavaan
The con argument in the sim function allows you to constrain parameters or to create new parameters (see this example: https://github.com/simsem/simsem/blob/master/SupportingDocs/Examples/Version05/exMultipleFormat/moderatedMediation.R) The part setting up the con argument is on line 132 in the file. But you also need to make sure you're using the correct labels when setting up the simsem matrices (the example linked above also does this).

Hyeseung Koh

unread,
Jun 6, 2022, 4:17:59 PM6/6/22
to lav...@googlegroups.com
I am not sure whether you have checked this thread. I also manually copied and pasted below as a reminder for retrieving, otherwise for encoding and storing to be retrieved. I tried based on the content on the webpage that I found and you also referred to. It indeed works in a certain way. When doing getPower (output, alpha=0.05, nVal=107) and getPower (output, alpha=0.05, nVal=93), the output showed me an identical value for each parameter. I am not sure whether it is because of the sample size which is not that huge or something else. My original sample size for the effect sizes varies I also used 10000 and 1000 resampling. One thing I could not do is to set the range of sample size for simulation, which does not allow to use findPower in the command. Please let me know when that is an incorrect output.


On May 23, 2022, at 9:43 AMCDT, balal izanloo <b.ez...@GMAIL.COM> wrote:


I would remember and apply the k-1 for the number of dummy codes when the number of factorial levels is k, such as 5 dummies for 6 groups with the 3 x 2 design, which should be a between-subject design. Beyond the between-subject design, what I said is still applicable.

i think yes

On May 23, 2022, at 13:39, balal izanloo <b.ez...@gmail.com> wrote:


as long as I know if the number of levels is k its dummy code is k-1. i find bellow point in the text and may be useful for you
3 (Self-efficacy) x 2 (Feedback condition) design with 5 dummy codes for 6 groups:

---------- Forwarded message ---------
From: Hyeseung Koh <thedinosa...@gmail.com>
Date: Mon, May 23, 2022 at 4:11 AM
Subject: Re: Simsem error using sim function
To: lavaan <lav...@googlegroups.com>


Please check that #k-1 = the number of dummy codes when k refers to the level of a variable. It would be inaccurate information on the number of dummy codes here: https://github.com/simsem/simsem/blob/master/SupportingDocs/Examples/Version05/exMultipleFormat/moderatedMediation.R

In addition, do you have any plan to construct the command for a multi-group model with three mediators with an independent variable and an outcome variable using an observed variables? 
2020년 10월 26일 월요일 오후 4시 35분 14초 UTC-5에 donne...@gmail.com님이 작성:
I cannot thank you enough. Please let me know if there is anyway I can support your generous work here. 

On Monday, October 26, 2020 at 3:27:38 PM UTC-5 Terrence Jorgensen wrote:
The hypothesis I'm testing is "Self-efficacy will have an indirect effect on performance through effort that is greater in the ambiguous condition than in the unambiguous condition".  Should I make any modifications to better reflect this direction?

You can add another user-defined parameter that is the difference between indirect effects in those 2 conditions:

ind1.diff := ind1.amb - ind1.unamb
ind2.diff := ind2.amb - ind2.unamb

Then the summaryParam() output will show power for that specific NHST.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Hyeseung Koh

unread,
Jun 10, 2022, 1:26:39 PM6/10/22
to lav...@googlegroups.com
On Jun 4, 2022, at 12:19 PMCDT, Mauricio Garnier-Villarreal <mauga...@gmail.com> wrote:

That part is not automated in simsem. In simsem you can run the simulation through a range of sample size and find the sample size for a specific effect size. You cannot do that to find the effect size has 80% power at a specific sample size. 
Indeed.


You would have to do this step by step:
1- run the "normal" simulation at your sample size, with like 500 replication for the model at A effect size
The simulation in simsem would not necessarily take care of the sample size of an individual analysis. 

2- find the power at that effect size
3- change effect size A for effect size B, and run the simulation again
4- repeat until you find the effect size at which you have
Please explain this: "the effect size at which you have" 

You change the effect size from A to B depending on the results of step 2.

So, f the power is lower than 80% you need to increase the effect size, and if the power is larger than 80% you need to decrease the effect size.

This should take a couple of steps, but still should be doable in a few models to find the desire values



On Friday, June 3, 2022 at 9:09:30 PM UTC+2 thedinosa...@gmail.com wrote:
Given a sample size with alpha=.05 and 80% power, which part of the output do you check to find what effect size can be observable at a medium level? Also, which part of the output do you check to find what effect size can be observable at a medium level when 90% power while holding the sample size and alpha level constant ? 




--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages