Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Normally distributed error term & testing normality of residuals


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Normally distributed error term & testing normality of residuals
Date   Tue, 16 Oct 2012 09:52:24 +0200

On Mon, Oct 15, 2012 at 6:56 PM, Seed, Paul wrote:
> I might add that I generally work on the raw data, not the residuals, as it is easier to
> understand the qnorm plot and the transformation needed; and I'm not interested in testing the
> residuals formally.

The problem with that is that Ebru is working in a regression like
context, and we would not expect the raw data to be
normally/Poisson/Gamma/... distributed when there are explanatory
variables involved. The marginal distribution of the
dependent/explained/left-hand-side/y-variable can deviate considerably
from the distribution that gives your regression model its name. This
is what I wrote the -margdistfit- package for. To borrow an example
from my talk at the 2012 German Stata Users' meeting
(<http://www.maartenbuis.nl/presentations/berlin12.html>):

*------------------------- begin example ---------------------------
// create random data made for a linear regression
set seed 12345
clear all
set obs 1000
gen x = _n < 250
gen y = 0 + 3*x + rnormal()

// show that y is not normally distributed
qnorm y, name(qnorm, replace)

// A more fancy version of the previous graph
// requires -qenv- (SSC) and -qplot- (SJ)
qenvnormal y, gen(lb ub) reps(1000)
sum y
local l = `r(mean)' + `r(sd)' * invnormal((     1 - .5)/`r(N)')
local u = `r(mean)' + `r(sd)' * invnormal((`r(N)' - .5)/`r(N)')

qplot y lb ub, ms(oh none ..) c(. l l) lc(gs10 ..) legend(off)  ///
        ytitle("y") trscale(`r(mean)' + `r(sd)' * invnormal(@)) ///
        xtitle(Normal quantiles) ylab(-6(2)8) xlab(-6(2)8)      ///
        aspect(1) name(gauss, replace)                          ///
        addplot(function y = x, range(`l' `u')                  ///
                lpattern(solid) lc(gs10))

// show that the distribution of y corresponds with
// the marginal distribution implied by -regress-
// requires -margdistfit- (SSC)
reg y x
margdistfit , qq name(marg, replace)
*-------------------------- end example ----------------------------
(For more on examples I sent to the Statalist see:
 http://www.maartenbuis.nl/example_faq )

Hope this works,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index