[R-sig-Geo] spautolm - standard errors of regression paramters
Sam Field
fieldsh at mail.med.upenn.edu
Mon Nov 5 23:18:57 CET 2007
thanks Roger!
In my haste, I mistyped. I meant to write:
sqrt(diag(mod1$fit[["imat"]]))
which should be equivalent to
summary(mod1)$Coef[,2],
the standard errors of the regression coefficients.
In any case, I have managed to replicate the case where the two commands produce
different results. Using the "columbus data"...
library(spdep)
data(columbus)
#defining W
columbus_poly <- readShapePoly(system.file("etc/shapes/columbus.shp",
package="spdep")[1])
columbus_nb <- poly2nb(columbus_poly)
columbus_listw <- nb2listw(columbus_nb)
#running spautolm()
mod1 <- spautolm(CRIME ~ HOVAL + DISCBD,listw=columbus_listw,data =
columbus,family="SAR")
sqrt(diag(mod1$fit[["imat"]]))
summary(mod1)$Coef[,2]
and the result:
> sqrt(diag(mod1$fit[["imat"]]))
(Intercept) HOVAL DISCBD
0.468345807 0.009013047 0.146973631
> summary(mod1)$Coef[,2]
(Intercept) HOVAL DISCBD
4.68573639 0.09017431 1.47045128
looks like the decimal place is shifted over one place. If you add more
variables to the model, the results differ by more then a decimal place in this
case (in my case the results are very different). For example,
mod2 <- spautolm(CRIME ~ HOVAL + DISCBD + INC + PLUMB,listw=columbus_listw,data
= columbus,family="SAR")
sqrt(diag(mod2$fit[["imat"]]))
summary(mod2)$Coef[,2]
results in:
> sqrt(diag(mod2$fit[["imat"]]))
(Intercept) HOVAL DISCBD INC PLUMB
0.52884967 0.01002545 0.17186710 0.03379109 0.04940024
>
> summary(mod2)$Coef[,2]
(Intercept) HOVAL DISCBD INC PLUMB
4.86800598 0.09228322 1.58201870 0.31104348 0.45472408
Initially, I just wanted the standard errors so that I could write them out in a
text file and put them in a table for a MSWord document. However, I will also
need the covariances of the parameters and, thus, need the off diagonal elements
of the variance covariance matrix. Am I reading this matrix incorrectly?
thanks for all of your help!
Sam
Quoting Roger Bivand <Roger.Bivand at nhh.no>:
> On Mon, 5 Nov 2007, Sam Field wrote:
>
> > List,
> >
> > I would like to grab the standard errors of the regression parameters from
> an
> > spautolm object. Currently I am using...
> >
> > mod1 <- spautolm(y~var1 + var2,....)
> >
> > mod1_sd <- (diag(mod1$fit[["imat"]])^2
>
> As with most model fitting functions, you use the summary method, so
>
> summary(mod1)$Coef
>
> is a four-column matrix, and
>
> summary(mod1)$Coef[,2]
>
> is the column you want.
>
> Roger
>
> PS. Reading summary.spautolm shows that the diagonal values of the matrix
> you refer to are the squares of the SE values.
>
> >
> >
> > This does produce a vector of the diagonal elements of a matrix that look
> like a
> > variance covariance matrix (correct dimensions and row and column labels),
> but
> > the values I get do not agree with what the summary() function displays --
> they
> > also seem implausibly small.
> >
> > any hints?
> >
> > Thanks!
> >
> > Sam
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
> --
> Roger Bivand
> Economic Geography Section, Department of Economics, Norwegian School of
> Economics and Business Administration, Helleveien 30, N-5045 Bergen,
> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
> e-mail: Roger.Bivand at nhh.no
>
>
--
********Note the new contact information*******
Samuel H. Field, Ph.D.
Senior Research Investigator
CHERP/Division of Internal Medicine - University of Pennsylvania
Philadelphia VA Medical Center
3900 Woodland Ave (9 East)
Philadelphia, PA 19104
(215) 823-5800 EXT. 6155 (Office)
(215) 823-6330 (Fax)
More information about the R-sig-Geo
mailing list