pbreheny / visreg

Visualization of regression functions
http://pbreheny.github.io/visreg/
62 stars 18 forks source link

Documentation about y-axis partial residuals for simple multiple regression #71

Closed utooley closed 3 years ago

utooley commented 5 years ago

I'm a bit confused as to the behavior of visreg with regards to just plain vanilla linear models and the interpretation of the y-axis, I may just be misunderstanding. Maybe I'm missing something about the residualization, or visreg uses different assumptions than other packages do? It seems that it does not match what I would expect, and digging through the documentation simply produced the fact that conditional plots use the median or the reference level of factors and hold those constant.

Given a model y~a+b, simply taking residuals from y~b and a~b and then plotting the residuals of a against the residuals of y (as I believe you should be doing for partial regression) yield a plot like this: Rplot01

This plot and the range of the y-axis looks similar to those from car::avPlots(see below), but not to that produced from visreg from the command visreg(mymodel, "age_scan"). Adding scale="response" to visreg does not produce a shift in the expected direction, either. Basically, I'm trying to understand why the distribution of the partial residuals look different in visreg than I would expect them to, and the shift in scale of the y-axis, given that the range of my response variable y is range -0.17 0.26, which is much larger than is shown on the visreg plot, and somewhat larger than what is shown in the car plot, which shows the partial regression plot, I gather.

Could this be solely due the the difference in holding covariates constant vs. regressing out the effect of the other covariates?

Visreg plot: Rplot04 avPlot: Rplot03

pbreheny commented 3 years ago

Sorry for the delay in responding...likely, you no longer care, but I'll respond anyway. The purpose of the visreg package is to visualize your model and what it is saying. Taking some residuals from a model and fitting a new model to them may be useful for diagnostic purposes, but does not describe the original model in any way. If you fit the model y~a+b, then submit visreg(fit, 'a'), the package plots the expected value of y versus a as b is held constant. Estimating this relationship is the purpose of a regression model, and the purpose of visreg is to illustrate that relationship.