[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: graph mean and sd over/by category
Among other things, George Hoffman <firstname.lastname@example.org> asks,
> [...] fitted curves under scatter plots look beautiful - can the
> regression coefficients from fplotci or qplotci be captured somehow,
> as poor-man's curve fit?
I think George is referring to the -fpfitci- and -qfitci- plot types of
-graph twoway-. If so, he can readily perform the regressions that produced
-qfitci- just performs a quadratic regression. If we use the auto data,
-sysuse auto-, the lines for the graph command,
. twoway qfitci mpg weight
are the predictions of the quadratic fit,
. gen weight2 = weight^2
. regress mpg weight weight2
The coefficients can be seen in the output of -regress-, or manipulated in the
usual way through the saved results.
If George wants to add the predictions, and their CIs to his dataset, he can
. predictnl mpg_hat2 = predict() , ci(ci_low ci_high)
This is a very simple application of -predictnl-, Bobby Gutierrez
<email@example.com> said more in a prior post, but it lets us get both the
predictions and their CIs with one command.
We could then get a graph similar to our earlier -twoway qfitci-, by typing,
. twoway rarea ci_low ci_high weight, sort || line mpg_hat2 weight, sort
which we will immediately think looks ugly and decide to relabel the CI in the
legend, option -legend(label())-, and change the fill color of the CI to be
the standard for our scheme, option -p(ci)-.
. twoway rarea ci_low ci_high weight , sort p(ci) ||
line mpg_hat2 weight , sort legend(label(1 "CI"))
The -fpfitci- plot type just uses -fracpoly- as the engine to produce the
fits, much like -regress- is used for the quadratic fit. For our example, the
corresponding -fracpoly- estimation command is,
. fracpoly regress mpg weight
and we can repeat the rest of the story, or just use -fracplot-, to plot the
fit and CI.
* For searches and help try: