An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20070417/d21d3a0b/attachment.pl>
problems with read.gwt2nb function
5 messages · Antonio Ramos, Roger Bivand
On Tue, 17 Apr 2007, Antonio Ramos wrote:
Hi everybody, I'm using Geoda and R in order to calculate Moran I test for my data. I use GeoDa to create my spatial weight and then R to run a code that allows me calculate several Moran I test for different attributes of my data at once, avoiding tedious repetition. However it seems that the very same code that worked pretty good for .gal files is not working for .gwt files. In fact, there is a warning message after the read.gwt2nb command, but I cannot figure it out. Does anybody can shed any light?
I believe that you should pay attention to the warning. Please run the example for the function. If you do not see the same issues there, you will need to look carefully at your GWT file, which may not be what you think. It is a text file, so is easy to examine. Please also try to provide access to the GWT file, if you think that it does contain what you think. At least some regions seem to have no neighbours. Roger
library(spdep) #write de zero's matrix where the final results will be written. ba.gwt.results <- matrix(0,nrow=39,ncol=5) n <- nrow(ba.gwt.results) ba <- read.csv(file = "d:/BrasilDep2006/BA BASE PRONTA/ba_base_toda.csv",
header=T)
ba.gwt.nb <- (file = "d:/BrasilDep2006/BA BASE PRONTA/ba.gwt") ba.gwt.nb <- read.gwt2nb(ba.gwt.nb)
Warning messages: 1: region.id not named ID_ in: read.gwt2nb(ba.gwt.nb) 2: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 22 in: read.gwt2nb(ba.gwt.nb) 3: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 22 in: read.gwt2nb(ba.gwt.nb)
#Alternatively, one may use the funcion "read.gwt2nb",
# from the same library (spdep) to read .gwt objects.
#Create my weight?s matrix:
ba.gwt.listw <- nb2listw(ba.gwt.nb, style="W")
Error in nb2listw(ba.gwt.nb, style = "W") :
Empty neighbour sets found
for(i in 1:n)
+ {
+ moran.test(ba[,i+2],ba.gwt.listw)$statistic->ba.gwt.results[i,1]
+ moran.test(ba[,i+2],ba.gwt.listw)$estimate[1]->ba.gwt.results[i,2]
+ moran.test(ba[,i+2],ba.gwt.listw)$estimate[2]->ba.gwt.results[i,3]
+ moran.test(ba[,i+2],ba.gwt.listw)$estimate[3]->ba.gwt.results[i,4]
+ moran.test(ba[,i+2],ba.gwt.listw)$p.value->ba.gwt.results[i,5]
+ }
Error in inherits(listw, "listw") : object "ba.gwt.listw" not found
Thank you very much, Antonio Pedro Ramos. [[alternative HTML version deleted]]
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
Hi Roger, I believe that you should pay attention to the warning. Please run the
example for the function.
I already did it but it seems there is similar problems:
?read.gwt2nb
data(baltimore)
STATION <- baltimore$STATION
gwt1 <- read.gwt2nb(system.file("etc/weights/baltk4.GWT",
package="spdep")[1],
+ STATION)
Warning message:
102, 115, 208 are not destinations in:
read.gwt2nb(system.file("etc/weights/baltk4.GWT",
package = "spdep")[1],
cat(paste("Neighbours list symmetry;", is.symmetric.nb(gwt1, FALSE, TRUE),
+ "\n")) Neighbours list symmetry; FALSE
listw1 <- nb2listw(gwt1, style="B", glist=attr(gwt1, "GeoDa")$dist) tmpGWT <- tempfile() write.sn2gwt(listw2sn(listw1), tmpGWT) gwt2 <- read.gwt2nb(tmpGWT, STATION)
Warning message: 102, 115, 208 are not destinations in: read.gwt2nb(tmpGWT, STATION)
cat(paste("Neighbours list symmetry;", is.symmetric.nb(gwt2, FALSE, TRUE),
+ "\n")) Neighbours list symmetry; FALSE
diffnb(gwt1, gwt2)
Neighbour list object: Number of regions: 211 Number of nonzero links: 0 Percentage nonzero weights: 0 Average number of links: 0 211 regions with no links: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
data(oldcol) tmpMAT <- tempfile()
If you do not see the same issues there, you
will need to look carefully at your GWT file, which may not be what you think.It is a text file, so is easy to examine. Please also try to provide access to the GWT file, if you think that it does contain what you think.
I also did it but I see no problem with my gwt file (made via Geoda): 0 417 ba_base_toda ID_ 291110 290320 1.14838787 291110 292620 1.20007809 291110 292840 1.26206315 291110 291955 1.39205921 291110 290140 1.54464659 291110 292045 1.7405391 291110 290740 1.81707945 291110 290940 1.83009167 290320 292620 0.466408625 290320 291955 0.650969045 290320 290140 0.757652243 290320 290740 0.890575291 290320 292890 0.912077132 Attached to this email there is the whole file. At least some regions seem to have no neighbours. Since I use the option k-nearest neighbors in GeoDa, it is impossible there is regions without neighbours in this .gwt file. Any second thoughts? Help and advice really appreciated, Antonio. -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20070418/f635846a/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: ba.GWT Type: application/octet-stream Size: 113447 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20070418/f635846a/attachment.obj>
On Wed, 18 Apr 2007, Antonio Ramos wrote:
Hi Roger, I believe that you should pay attention to the warning. Please run the
example for the function.
I think this gets you there - you have to give the IDs as the region.id=
argument, otherwise the function is looking for a sequence 1:417:
ba0 <- read.table("ba.GWT", header=FALSE, skip=1)
str(ba0)
ID_ <- unique(ba0$V1)
ba <- read.gwt2nb("ba.GWT", region.id=ID_)
ba
Roger
I already did it but it seems there is similar problems:
?read.gwt2nb
data(baltimore)
STATION <- baltimore$STATION
gwt1 <- read.gwt2nb(system.file("etc/weights/baltk4.GWT",
package="spdep")[1],
+ STATION)
Warning message:
102, 115, 208 are not destinations in:
read.gwt2nb(system.file("etc/weights/baltk4.GWT",
package = "spdep")[1],
cat(paste("Neighbours list symmetry;", is.symmetric.nb(gwt1, FALSE, TRUE),
+ "\n")) Neighbours list symmetry; FALSE
listw1 <- nb2listw(gwt1, style="B", glist=attr(gwt1, "GeoDa")$dist) tmpGWT <- tempfile() write.sn2gwt(listw2sn(listw1), tmpGWT) gwt2 <- read.gwt2nb(tmpGWT, STATION)
Warning message: 102, 115, 208 are not destinations in: read.gwt2nb(tmpGWT, STATION)
cat(paste("Neighbours list symmetry;", is.symmetric.nb(gwt2, FALSE, TRUE),
+ "\n")) Neighbours list symmetry; FALSE
diffnb(gwt1, gwt2)
Neighbour list object: Number of regions: 211 Number of nonzero links: 0 Percentage nonzero weights: 0 Average number of links: 0 211 regions with no links: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
data(oldcol) tmpMAT <- tempfile()
If you do not see the same issues there, you
will need to look carefully at your GWT file, which may not be what you think.It is a text file, so is easy to examine. Please also try to provide access to the GWT file, if you think that it does contain what you think.
I also did it but I see no problem with my gwt file (made via Geoda): 0 417 ba_base_toda ID_ 291110 290320 1.14838787 291110 292620 1.20007809 291110 292840 1.26206315 291110 291955 1.39205921 291110 290140 1.54464659 291110 292045 1.7405391 291110 290740 1.81707945 291110 290940 1.83009167 290320 292620 0.466408625 290320 291955 0.650969045 290320 290140 0.757652243 290320 290740 0.890575291 290320 292890 0.912077132 Attached to this email there is the whole file. At least some regions seem to have no neighbours. Since I use the option k-nearest neighbors in GeoDa, it is impossible there is regions without neighbours in this .gwt file. Any second thoughts? Help and advice really appreciated, Antonio.
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
1 day later
On Tue, 17 Apr 2007, Antonio Ramos wrote:
Hi everybody, I'm using Geoda and R in order to calculate Moran I test for my data. I use GeoDa to create my spatial weight and then R to run a code that allows me calculate several Moran I test for different attributes of my data at once, avoiding tedious repetition. However it seems that the very same code that worked pretty good for .gal files is not working for .gwt files. In fact, there is a warning message after the read.gwt2nb command, but I cannot figure it out. Does anybody can shed any light?
I believe that you should pay attention to the warning. Please run the example for the function. If you do not see the same issues there, you will need to look carefully at your GWT file, which may not be what you think. It is a text file, so is easy to examine. Please also try to provide access to the GWT file, if you think that it does contain what you think. At least some regions seem to have no neighbours. Roger
library(spdep) #write de zero's matrix where the final results will be written. ba.gwt.results <- matrix(0,nrow=39,ncol=5) n <- nrow(ba.gwt.results) ba <- read.csv(file = "d:/BrasilDep2006/BA BASE PRONTA/ba_base_toda.csv",
header=T)
ba.gwt.nb <- (file = "d:/BrasilDep2006/BA BASE PRONTA/ba.gwt") ba.gwt.nb <- read.gwt2nb(ba.gwt.nb)
Warning messages: 1: region.id not named ID_ in: read.gwt2nb(ba.gwt.nb) 2: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 22 in: read.gwt2nb(ba.gwt.nb) 3: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 22 in: read.gwt2nb(ba.gwt.nb)
#Alternatively, one may use the funcion "read.gwt2nb",
# from the same library (spdep) to read .gwt objects.
#Create my weight?s matrix:
ba.gwt.listw <- nb2listw(ba.gwt.nb, style="W")
Error in nb2listw(ba.gwt.nb, style = "W") :
Empty neighbour sets found
for(i in 1:n)
+ {
+ moran.test(ba[,i+2],ba.gwt.listw)$statistic->ba.gwt.results[i,1]
+ moran.test(ba[,i+2],ba.gwt.listw)$estimate[1]->ba.gwt.results[i,2]
+ moran.test(ba[,i+2],ba.gwt.listw)$estimate[2]->ba.gwt.results[i,3]
+ moran.test(ba[,i+2],ba.gwt.listw)$estimate[3]->ba.gwt.results[i,4]
+ moran.test(ba[,i+2],ba.gwt.listw)$p.value->ba.gwt.results[i,5]
+ }
Error in inherits(listw, "listw") : object "ba.gwt.listw" not found
Thank you very much, Antonio Pedro Ramos. [[alternative HTML version deleted]]
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 _______________________________________________ Openspace mailing list Openspace at sal.uiuc.edu http://sal.uiuc.edu/mailman/listinfo/openspace