Graph component-plus-residual plots for transformed regressors
cprplot2 varlist [if exp] [in range] [, retransform(exp) yretransform(exp) rlopts(cline_options) lowess lsopts(lowess_options) mspline msopts(mspline_options) lpoly lpopts(lpoly_options) plot(plot) scatter_options twoway_options ]
cprplots2 vargroups [if exp] [in range] [, retransform(explist) yretransform(explist) rlopts(cline_options) lowess lsopts(lowess_options) mspline msopts(mspline_options) lpoly lpopts(lpoly_options) scatter_options combine_options ]
where vargroups is
"varlist" "varlist" ...
and explist is
"exp" "exp" ...
cprplot2 and cprplots2 are for use after regress and anova; see help regress and anova.
cprplot2 is a variation of official Stata's cprplot (see help cprplot) and is used for graphing component-plus-residual plots (a.k.a. partial residual plots). There are three main additional features (compared to cprplot):
(1) The partial residuals (and the "partial" predictions that are used to draw the reference line) can be computed taking into account multiple variables (the varlist). These adjusted values are then plotted against the first variable in varlist. cprplot2 can therefore be used to produce a single component-plus-residual plot for a variable that enters the model repeatedly via different transformations (for example, polynomials). Note that all variables in varlist must be independent variables currently included in the model.
(2) Regressors entering the model via a univariate transformation can be re-transformed before drawing the plots using the retransform() option. It is thus possible to display the plots using the original units of the regressors. Naturally, the reference line (i.e. the line representing the predictions from the model being estimated) will be curved in the re-transformed plot. Moreover, it is possible to re-transform the-right hand side of the equation, i.e. the partial residuals, using the yretransform() option. This may be useful for models with a transformed dependent variable.
(3) The cprplots2 command offers the possibility of quickly displaying several component-plus-residual plots in a single image. If vargroups is omitted, component-plus-residual plots are graphed for all independent variables in the model. cprplots2 is implemented as a wrapper for cprplot2 and supports features (1) and (2) discussed above.
cprplot2 only uses observations that are in the estimation sample. Use if and in to further restrict the sample.
retransform(exp) specifies that the regressor used in the graph be transformed through the application of exp (see help exp). Use @ as a placeholder for the regressor in exp. For example, assume that the regressor has been centered for the purpose of model estimation and that the sample mean of the regressor is 21.2973. To use the original scale of the regressor in the plot, specify retransform(@+21.2973). If exp does not contain @, @ is appended to the end of exp in parentheses. Thus, say, retransform(exp) is equivalent to retransform(exp(@)).
If you use retransform() with cprplots2, specify either a single exp (enclosed in double quotes if containing blanks) to be applied to all plots or a list of exps to be applied one after another to the individual plots. Enclose individual exps that contain blanks with double quotes. Type "" to indicate that no transformation be applied to a certain plot. Example: retransform("" "1/@" "").
yretransform(exp) specifies that the partial residuals (and the "partial" predictions which are used to draw the reference line) be transformed. See the retransform() option above.
rlopts(cline_options) affect the rendition of the reference curve; see help cline_options.
lowess adds a lowess smooth of the plotted points in order to assist in detecting nonlinearities.
lsopts(lowess_options) affect the rendition of the lowess smooth; see help twoway_lowess. Specifying lsopts() implies the lowess option.
mspline adds a median spline of the plotted points in order to assist in detecting nonlinearities.
msopts(mspline_options) affect the rendition of the median spline smooth; see help twoway_mspline. Specifying msopts() implies the mspline option.
lpoly adds a local polynomial smooth of the plotted points in order to assist in detecting nonlinearities. Stata 10 is required.
lpopts(lpoly_options) affect the rendition of the local polynomial smooth; see help twoway_lpoly. Specifying lpopts() implies the lpoly option. Stata 10 is required.
plot(plot) provides a way to add other plots to the generated graph; see help plot_option.
scatter_options affect the rendition of the plotted points; see help scatter.
twoway_options are any of the options documented in help twoway_options excluding by(). These include options for titling the graph (see help title_options) and options for saving the graph to disk (see help saving_option).
combine_options are any of the options documented in help graph_combine. These include options for titling the graph (see help title_options) and options for saving the graph to disk (see help saving_option).
. sysuse auto . generate mpg2 = mpg^2 . generate mpg3 = mpg^3 . regress price weight mpg mpg2 mpg3 . cprplot2 mpg mpg2 mpg3 . cprplots2 weight "mpg mpg2 mpg3"
. generate lnmpg = ln(mpg) . regress price weight lnmpg . cprplot2 lnmpg, retransform(exp(@)) . cprplots2 weight lnmpg, retransform("" "exp(@)")
. gen lnweight = ln(weight) . reg lnweight mpg . cprplots2 mpg mpg , yretransform("" "exp(@)")
Ben Jann, ETH Zurich, firstname.lastname@example.org
Manual: [R] regress, [R] regression diagnostics