Skip to content

"Abridged" description of SpatialPolygonsDataFrame objects?

7 messages · Sam Field, Roger Bivand, ONKELINX, Thierry

#
On Mon, 29 Oct 2007, Michael Sumner wrote:

            
Another possibility is to use the arguments to str(), in particular, 
setting max.level=2 prevents str() going into deeper levels of the nested 
object. Judicious use of slot() in str(), with the max.level= gives a good 
degree of control.

Roger

  
    
#
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


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
#
On Mon, 5 Nov 2007, Sam Field wrote:

            
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.

  
    
#
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:
(Intercept)       HOVAL      DISCBD 
0.468345807 0.009013047 0.146973631
(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:
(Intercept)       HOVAL      DISCBD         INC       PLUMB 
 0.52884967  0.01002545  0.17186710  0.03379109  0.04940024
(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:

            
No, because the fit[["imat"]] matrix has not been multiplied by s^2 (in 
summary.spautolm):

     object$resvar <- object$fit$s2 * object$fit$imat

So:
(Intercept)       HOVAL      DISCBD
  4.68573631  0.09017431  1.47045126
(Intercept)       HOVAL      DISCBD
  4.68573631  0.09017431  1.47045126

And it is not multiplied in spautolm() because of the adj.se= argument to 
summary.spautolm, so that the SE values in Waller and Gotway - adjusting 
s^2 for the number of fitted coefficients - could be reproduced.

Roger

  
    
#
Maybe spautolm() rescales the coordinates before calculating the model
parameters. In that case maybe het units mod1$fit are in the new scale
and the units of summary() in the original scale.

HTH,

Thierry

------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be 
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: r-sig-geo-bounces at stat.math.ethz.ch
[mailto:r-sig-geo-bounces at stat.math.ethz.ch] Namens Sam Field
Verzonden: maandag 5 november 2007 23:19
Aan: Roger.Bivand at nhh.no
CC: r-sig-geo at stat.math.ethz.ch
Onderwerp: Re: [R-sig-Geo] spautolm - standard errors of regression
paramters

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:
(Intercept)       HOVAL      DISCBD 
0.468345807 0.009013047 0.146973631
(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:
(Intercept)       HOVAL      DISCBD         INC       PLUMB 
 0.52884967  0.01002545  0.17186710  0.03379109  0.04940024
(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>:
--
********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)

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
#
On Tue, 6 Nov 2007, ONKELINX, Thierry wrote:

            
No, no rescaling or other tricks. The code is quite clear, the returned 
matrix is not premultiplied by s^2 - see my other reply.

Roger