This is a group for users of my textbooks (and anyone else really) to discuss the books, post questions and so on.
This is a group for users of my textbooks (and anyone else really) to discuss the books, post questions and so on.
Categories: Quantitative
Creating 3d slope moderation graph
 This topic has 4 replies, 2 voices, and was last updated 5 years, 9 months ago by Nicolas Stefaniak.

AuthorPosts

15th October 2014 at 11:59 am #801Sahand AleboyehMember
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
15th October 2014 at 12:44 pm #805Nicolas StefaniakMemberHello,
this could answer your question :
# 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[1], table2$Estimate[2], table2$Estimate[3], table2$Estimate[4],
x.min = min(data[,VI[1]]), x.max = max(data[,VI[1]]), z.min = min(data[,VI[2]]),
z.max = max(data[,VI[2]]), 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
15th October 2014 at 1:17 pm #804Sahand AleboyehMemberExcuse my stupidity
but could you use this value please because i dont totaly catch your explaination sorry
Moderator value(s) defining JohnsonNeyman significance region(s):
Value % below % above
,0964 39,3484 60,6516Conditional 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 ,395615th October 2014 at 1:46 pm #803Nicolas StefaniakMemberOk, 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[1], table2$Estimate[2], table2$Estimate[3], table2$Estimate[4],
x.min = min(data[,VI[1]]), x.max = max(data[,VI[1]]), z.min = min(data[,VI[2]]),
z.max = max(data[,VI[2]]), 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
15th October 2014 at 2:15 pm #802Sahand AleboyehMemberThanks 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

AuthorPosts
 You must be logged in to reply to this topic.