[R-sig-Geo] Spatial Lags Excluding Neighbors' Missing Attribute Values

Christopher Moore moor0554 at umn.edu
Tue Dec 30 22:27:41 CET 2008


Greetings,

I posted a request for assistance on 12/27/08: 
<https://stat.ethz.ch/pipermail/r-sig-geo/2008-December/004733.html>.

I developed a satisfactory solution, which is posted below for others who 
wish to similarly exclude neighbors' missing attribute values from W style 
spatial lags.

I did not receive any responses to my original message but would still 
appreciate any thoughts or suggestions regarding this approach or the 
general problem of neighbors with missing attribute values. For example, do 
spatial statisticians prefer to impute missing attribute values before 
lagging, or is there a good justification for treating NA as zero when 
calculating spatial lags, thereby pulling lagged values downward?

Thanks,
Chris

-- 
Christopher Moore, M.P.P.
Doctoral Student
Quantitative Methods in Education
University of Minnesota
moor0554 at umn.edu
http://www.tc.umn.edu/~moor0554/


> ##########
> 
> ##Solution developed 12/30/08 attributes <- 
> data.frame(NAME=nc.sids at data$NAME, ID=1:dim(nc.sids at data)[1], 
> SID79=nc.sids at data$SID79) for(i in 1:6) 
> print(merge(data.frame(ID=wts$neighbours[[i]]), attributes, by="ID"))
  ID       NAME SID79
1 17    Caswell     2
2 19    Chatham     3
3 41   Guilford    38
4 68     Orange     6
5 76   Randolph    12
6 79 Rockingham     5
  ID     NAME SID79
1 14 Caldwell     9
2 18  Catawba    21
3 49  Iredell     5
4 97   Wilkes    NA
  ID   NAME SID79
1  5   Ashe     0
2 86  Surry     6
3 97 Wilkes    NA
  ID       NAME SID79
1 62 Montgomery     8
2 77   Richmond     7
3 84     Stanly     7
4 90      Union     9
  ID      NAME SID79
1  3 Alleghany     3
2 95   Watauga     1
3 97    Wilkes    NA
  ID     NAME SID79
1 12    Burke    15
2 14 Caldwell     9
3 56 McDowell     5
4 61 Mitchell     2
5 95  Watauga     1
> attributes$LAG.NEW.W=rep(NA, dim(nc.sids at data)[1]) for(i in 
> 1:dim(nc.sids at data)[1]) attributes[i,"LAG.NEW.W"] <- 
> round(mean(merge(data.frame(ID=wts$neighbours[[i]]), attributes, 
> by="ID")$SID79, na.rm=T), 3) attributes$LAG.ORIG.W <- round(lag(wts, 
> nc.sids at data$SID79), 3) attributes[,c(1,3:5)]
            NAME SID79 LAG.NEW.W LAG.ORIG.W
1       Alamance    11    11.000     11.000
2      Alexander     2    11.667      8.750
3      Alleghany     3     3.000      2.000
4          Anson     4     7.750      7.750
5           Ashe     0     2.000      1.333
6          Avery     0     6.400      6.400
7       Beaufort     4     5.167      5.167
8         Bertie     5     5.200      5.200
9         Bladen     5    21.400     21.400
10     Brunswick     6     9.667      9.667
11      Buncombe    18     5.143      5.143
12         Burke    15    10.143     10.143
13      Cabarrus    20    12.800     12.800
14      Caldwell     9     7.800      6.500
15        Camden     2     2.667      2.667
16      Carteret     4    14.333     14.333
17       Caswell     2    12.800     12.800
18       Catawba    21     9.833      9.833
19       Chatham     3    12.875     12.875
20      Cherokee     1     1.500      1.500
21        Chowan     1     1.000      1.000
22          Clay     0     2.000      2.000
23     Cleveland    21    15.400     15.400
24      Columbus    17    10.000     10.000
25        Craven    18     6.000      6.000
26    Cumberland    57     9.333      9.333
27     Currituck     2     2.000      2.000
28          Dare     1     0.000      0.000
29      Davidson     8    13.429     13.429
30         Davie     3     8.000      8.000
31        Duplin     7    11.500     11.500
32        Durham    22     9.600      9.600
33     Edgecombe     9     9.800      9.800
34       Forsyth    18     9.429      9.429
35      Franklin     0    11.429     11.429
36        Gaston    26    21.000     21.000
37         Gates     2     2.400      2.400
38        Graham     1     2.000      2.000
39     Granville     4    12.600     12.600
40        Greene     4    15.250     15.250
41      Guilford    38     8.714      8.714
42       Halifax    17     3.857      3.857
43       Harnett    10    17.000     17.000
44       Haywood     8     6.500      6.500
45     Henderson     8     7.600      7.600
46      Hertford     5     3.333      3.333
47          Hoke     6    22.200     22.200
48          Hyde     0     1.250      1.250
49       Iredell     5    12.125     10.778
50       Jackson     5     4.250      4.250
51      Johnston    13    12.571     12.571
52         Jones     2    13.200     13.200
53           Lee     6     6.000      6.000
54        Lenoir    14    10.833     10.833
55       Lincoln     7    20.500     20.500
56      McDowell     5     7.333      7.333
57         Macon     3     1.800      1.800
58       Madison     2     9.000      9.000
59        Martin     1     7.667      7.667
60   Mecklenburg    35    13.400     13.400
61      Mitchell     2     2.000      2.000
62    Montgomery     8     7.286      7.286
63         Moore     5    13.889     13.889
64          Nash     7    12.143     12.143
65   New Hanover     9     4.500      4.500
66   Northampton     3     9.000      9.000
67        Onslow    23     4.000      4.000
68        Orange     6     8.400      8.400
69       Pamlico     1    11.000     11.000
70    Pasquotank     4     1.333      1.333
71        Pender     3    10.143     10.143
72    Perquimans     0     2.333      2.333
73        Person     4     8.500      8.500
74          Pitt    11     9.000      9.000
75          Polk     0     8.000      8.000
76      Randolph    12    12.167     12.167
77      Richmond     7     7.667      7.667
78       Robeson    26    20.200     20.200
79    Rockingham     5    14.800     14.800
80         Rowan     8     8.500      8.500
81    Rutherford     8    11.167     11.167
82       Sampson     4    16.857     16.857
83      Scotland    16    11.000     11.000
84        Stanly     7     9.143      9.143
85        Stokes     5    16.750     16.750
86         Surry     6     6.750      5.400
87         Swain     2     3.600      3.600
88  Transylvania     4     9.750      9.750
89       Tyrrell     0     0.000      0.000
90         Union     9    16.500     16.500
91         Vance     6     2.000      2.000
92          Wake    31     8.429      8.429
93        Warren     2     7.500      7.500
94    Washington     0     2.000      2.000
95       Watauga     1     3.000      2.250
96         Wayne    23     9.167      9.167
97        Wilkes    NA     3.375      3.375
98        Wilson    13    11.167     11.167
99        Yadkin     1     8.000      6.400
100       Yancey     1     6.750      6.750
> 
> ##########
>




More information about the R-sig-Geo mailing list