# Discovering Statistics

## Creating 3d slope moderation graph

Viewing 5 posts - 1 through 5 (of 5 total)
• Author
Posts
• #801

Hello everybody  do you know how to create a 3d slope  graph for a moderation regression graph

I am a bit lost on that one

thank you all

#805

Hello,

# table2 is the table in which the estimates of the linear model are presented (from the lm function).

# exemple :

lm(data[,1]~data[,2]+data[,3]+data[,2]*data[,3])->model # where data is the dataframe, 1 is the dependant variable and 2 and 3 the independant variables

VI<-c(2,3) # a vector for the graph

summary(model)\$coefficients->table2

library(MBESS)
intr.plot(table2\$Estimate, table2\$Estimate, table2\$Estimate, table2\$Estimate,
x.min = min(data[,VI]), x.max = max(data[,VI]), z.min = min(data[,VI]),
z.max = max(data[,VI]), n.x = 50, n.z = 50, col = “lightblue”, hor.angle = -60,
vert.angle = 15, xlab = “Value of X”, zlab = “Value of Z”, ylab = “Dependent Variable”, expand = 0.5,
lines.plot=TRUE, col.line = “red”, line.wd = 2, gray.scale = FALSE, ticktype=”detailed”)

Hope that it helps.

Nicolas

#804

Excuse my stupidity

but could you use this value please because i dont totaly catch your explaination sorry

Moderator value(s) defining Johnson-Neyman significance region(s):
Value % below % above
-,0964 39,3484 60,6516

Conditional effect of X on Y at values of the moderator (M)
sport_sa Effect  se        t             p       LLCI ULCI
-1,8981 -,1913 ,1538 -1,2437 ,2144 -,4938 ,1111
-1,7603 -,1693 ,1442 -1,1744 ,2410 -,4528 ,1141
-1,6224 -,1473 ,1346 -1,0945 ,2744 -,4119 ,1173
-1,4846 -,1253 ,1251 -1,0015 ,3172 -,3712 ,1206
-1,3467 -,1033 ,1157 -,8924 ,3727 -,3307 ,1242
-1,2089 -,0812 ,1065 -,7629 ,4460 -,2906 ,1281
-1,0711 -,0592 ,0974 -,6077 ,5437 -,2508 ,1324
-,9332 -,0372 ,0887 -,4195 ,6751 -,2115 ,1371
-,7954 -,0152 ,0802 -,1892 ,8500 -,1729 ,1425
-,6576 ,0068 ,0722 ,0947 ,9246 -,1352 ,1489
-,5197 ,0289 ,0649 ,4449 ,6567 -,0987 ,1564
-,3819 ,0509 ,0584 ,8717 ,3839 -,0639 ,1656
-,2441 ,0729 ,0530 1,3744 ,1701 -,0314 ,1772
-,1062 ,0949 ,0493 1,9263 ,0548 -,0020 ,1918
-,0964 ,0965 ,0491 1,9660 ,0500 ,0000 ,1930
,0316 ,1169 ,0474 2,4650 ,0141 ,0237 ,2102
,1695 ,1390 ,0478 2,9094 ,0038 ,0451 ,2329
,3073 ,1610 ,0502 3,2068 ,0015 ,0623 ,2597
,4451 ,1830 ,0545 3,3598 ,0009 ,0759 ,2901
,5830 ,2050 ,0602 3,4068 ,0007 ,0867 ,3233
,7208 ,2270 ,0670 3,3904 ,0008 ,0954 ,3587
,8586 ,2491 ,0745 3,3415 ,0009 ,1025 ,3956

#803

Ok, I guess that the value in your table are the slope for each value of your variable sport_sa.

It would be easier if you could post the data for your analyses instead of this table.

If you ant to try by yourself: you don’t need to have these values.

The moderation in linear regression is the interaction between two variables. In other terms, you have to make the multiplication between two variables.

For the 3D graph, you need three information : the slope for the effect of A, the slope for the effect of B and the slope for the interaction. You can obtain these information thanks to a linear model.

Let say that your data frame is called data and let say data you want to predict the variable A by the interaction of  B and C, your data could be as follows :

A     B     C

1     4      7

2     5      8

3     6      9

What you have to do is to make a dataframe in R in which the variable that you want to predict is in the first column (as the variable A) and the two variables of the moderation effect in the second and third columns (as the variable B and C in my example)

thus, you want to predict A by the interaction between B and C. The linear model you need to create is the next one :

lm(data\$A~data\$B+data\$C+data\$B*data\$C)

This model can be stored in R as follows :

lm(data\$A~data\$B+data\$C+data\$B*data\$C)-> model

The previous model is exactly the same as the following :

lm(data[,1]~data[,2]+data[,3]+data[,2]*data[,3])->model

The différence is that the last model does not need to refer to the name of a column in the dataframe but to the number of the column. It means that I want to predict the value in the column 1 of data by the simple effect of the value in the column 2, by the simple effect of column 3 and by the moderation effect of both these variables.

This model is necessary for your graph. Without the model, no graph.

In the model, the information which are useful for the graph (the intercept, the slope of A, the slope of B and the slope of AB) can be obtained by :

summary(model)\$coefficients

You can store these information in an object called “table”

summary(model)\$coefficients->table

The next step is that we need the minimal and maximal values of the variable B and C. My proposition is to store in an object called VI (independant variable in French) the column which corresponds to two predictors. In the example, the predictors are B and C and stored in the column 2 and 3. So I am going to store 2 and 3 in the object VI.

VI<-c(2,3)

Once you have done all these steps in R, you can copy and paste the next codes lines :

library(MBESS)
intr.plot(table2\$Estimate, table2\$Estimate, table2\$Estimate, table2\$Estimate,
x.min = min(data[,VI]), x.max = max(data[,VI]), z.min = min(data[,VI]),
z.max = max(data[,VI]), n.x = 50, n.z = 50, col = “lightblue”, hor.angle = -60,
vert.angle = 15, xlab = “Value of X”, zlab = “Value of Z”, ylab = “Dependent Variable”, expand = 0.5,
lines.plot=TRUE, col.line = “red”, line.wd = 2, gray.scale = FALSE, ticktype=”detailed”)

Note : you need to have installed the package MBESS before you can execute the code !

Good luck

Nicolas

#802

Thanks btw de way im using andrew heyes moderation process so i have all the info necessary but i didnt find a way to simply render the graph in spss I have all three variable necessary but i see no possibility to crete the 3d graph in spss i will try with R

Viewing 5 posts - 1 through 5 (of 5 total)
• You must be logged in to reply to this topic.