willow1980
2009-Aug-13 10:05 UTC
[R] How to plot 3-D surface graph from lmer mixed models?
Dear R users, I have a problem in plotting 3 dimensional graph using mixed models. My model is sur_prop ~ afr_c+I(afr_c^2)+I(afr_c^3)+byear_c+I(byear_c^2)+I(byear_c^3)+I(byear_c^4)+(1|Studyparish)+afr_c:byear_c +afr_c:I(byear_c^2)+afr_c:I(byear_c^3)+afr_c:I(byear_c^4)+I(afr_c^2):byear_c+I(afr_c^2):I(byear_c^2)+I(afr_c^2):I(byear_c^3)+I(afr_c^2):I(byear_c^4) This is a study on the effect of mothers' age and cohort year on children's survival. I can extract predicted value using a suggested method from website: model at X%*%fixef(model). To my knowledge, this method is reasonable. It is a bit alike matrix representation in multiple regression. However, I cannot use such predicted values together with age and cohort values to plot a 3-D surface plot. Since my dataset is very large, it is certainly useless to plot 3-D points scatter plot, which is very difficult to discern the pattern. By the way, I have tried "plot3d", "scatterplot" and "regr2.plot" to give scatter plot. So, do you have any suggestion on how to plot a surface plot given above information? For example, how to use "persp" or "wireframe" in case of lmer with more than two explanatory variables? Thank you very much for helping! Best wishes! -- View this message in context: http://www.nabble.com/How-to-plot-3-D-surface-graph-from-lmer-mixed-models--tp24952273p24952273.html Sent from the R help mailing list archive at Nabble.com.
Duncan Murdoch
2009-Aug-13 12:00 UTC
[R] How to plot 3-D surface graph from lmer mixed models?
willow1980 wrote:> Dear R users, > I have a problem in plotting 3 dimensional graph using mixed models. > My model is > sur_prop ~ > afr_c+I(afr_c^2)+I(afr_c^3)+byear_c+I(byear_c^2)+I(byear_c^3)+I(byear_c^4)+(1|Studyparish)+afr_c:byear_c > +afr_c:I(byear_c^2)+afr_c:I(byear_c^3)+afr_c:I(byear_c^4)+I(afr_c^2):byear_c+I(afr_c^2):I(byear_c^2)+I(afr_c^2):I(byear_c^3)+I(afr_c^2):I(byear_c^4) > This is a study on the effect of mothers' age and cohort year on children's > survival. > I can extract predicted value using a suggested method from website: > model at X%*%fixef(model). To my knowledge, this method is reasonable. It is a > bit alike matrix representation in multiple regression. > However, I cannot use such predicted values together with age and cohort > values to plot a 3-D surface plot. Since my dataset is very large, it is > certainly useless to plot 3-D points scatter plot, which is very difficult > to discern the pattern. By the way, I have tried "plot3d", "scatterplot" and > "regr2.plot" to give scatter plot. > So, do you have any suggestion on how to plot a surface plot given above > information? For example, how to use "persp" or "wireframe" in case of lmer > with more than two explanatory variables? > Thank you very much for helping!I only see two explanatory variables: afr_c, byear_c. If you have more than two, you can't use a surface plot: surfaces are two dimensional. All of the 3D surface functions want basically the same thing: a matrix giving evaluations of a function at locations of the explanatory variables. So you need to calculate that. I'd do it by using expand.grid to create a large set of combinations of values of the explanatory variables, ask your model to do predictions at all of those locations, and then reshape the result into a matrix. Duncan Murdoch
willow1980
2009-Aug-15 13:51 UTC
[R] How to plot 3-D surface graph from lmer mixed models?
Hi, First of all, I thank Professor Murdoch and Dr Sarkar for providing important information. Now, this problem has been basically solved. The package "akima" helps to fultil the objective originally resorting to "expand.grid". Now, I can use contour or perspective 3-D plot. Hopefully, this experience can do some help to other users with similar problems. However, I am still trying to use the method suggested by Dr Sarkar, since I think wireframe or levelplot may produce more beautiful pictures. Thank you again! Cheers! willow1980 wrote:> > Dear R users, > I have a problem in plotting 3 dimensional graph using mixed models. > My model is > sur_prop ~ > afr_c+I(afr_c^2)+I(afr_c^3)+byear_c+I(byear_c^2)+I(byear_c^3)+I(byear_c^4)+(1|Studyparish)+afr_c:byear_c > +afr_c:I(byear_c^2)+afr_c:I(byear_c^3)+afr_c:I(byear_c^4)+I(afr_c^2):byear_c+I(afr_c^2):I(byear_c^2)+I(afr_c^2):I(byear_c^3)+I(afr_c^2):I(byear_c^4) > This is a study on the effect of mothers' age and cohort year on > children's survival. > I can extract predicted value using a suggested method from website: > model at X%*%fixef(model). To my knowledge, this method is reasonable. It is > a bit alike matrix representation in multiple regression. > However, I cannot use such predicted values together with age and cohort > values to plot a 3-D surface plot. Since my dataset is very large, it is > certainly useless to plot 3-D points scatter plot, which is very difficult > to discern the pattern. By the way, I have tried "plot3d", "scatterplot" > and "regr2.plot" to give scatter plot. > So, do you have any suggestion on how to plot a surface plot given above > information? For example, how to use "persp" or "wireframe" in case of > lmer with more than two explanatory variables? > Thank you very much for helping! > Best wishes! >-- View this message in context: http://www.nabble.com/How-to-plot-3-D-surface-graph-from-lmer-mixed-models--tp24952273p24984809.html Sent from the R help mailing list archive at Nabble.com.
Apparently Analagous Threads
- How to deal with multicollinearity in mixed models (with lmer)?
- RandomForest tuning the parameters
- Factor level with no cases shows up in a plot
- Why there is no p-value from likelihood ratio test using anova in GAM model fitting?
- Can't find the error in a Binomial GLM I am doing, please help