# How to perform the Sobel test in R

How to perform the Sobel test in R, This tutorial will show you how to perform a Sobel test in R.

The Sobel test is used to see if a variable carries (or mediates) an independent variable’s effect to the dependent variable the desired outcome.

A significant test statistic indicates that an independent variable has an indirect effect on the dependent variable (i.e., an effect that is mediated in whole or in part by another variable).

This is accomplished by determining whether or not there is a statistical difference between the total and direct effects after accounting for the influence of a putative mediator.

## Using R to do a Sobel Test

The bda library in R can be used to perform a Sobel test.

if the bda package isn’t already installed, install it.

install.packages('bda')

Let’s load bda package

library(bda)

The following is the fundamental syntax for performing a Sobel test.

mediation.test(mv,iv,dv)

The mediator variable is mv, the independent variable is iv, and the dependent variable is DV.

For the mediator variable, independent variable, and dependent variable, the following code does a Sobel test with a list of 150 normal random variables:

mv <- rnorm(300) iv <- rnorm(300) dv <- rnorm(300) mediation.test(mv,iv,dv)

This code produces the following output:

Sobel Aroian Goodman z.value 0.4985178 0.3696514 1.1710077 p.value 0.6181192 0.7116423 0.2415957

In this case, we are interested primarily in the values in the Sobel column. The z value is 0.498 and the corresponding p-value is 0.618.

We would fail to reject the null hypothesis that there is no mediation effect because this p-value is bigger than the alpha level of 0.05.

As a result, the mediation effect does not appear to be statistically significant.

How to find z score in R-Easy Calculation-Quick Guide » finnstats

Subscribe to our newsletter!