Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • spmat idistance

    Dear All,

    I am working to create an inverse distance weights Matrix for some spatial analysis. First I use:

    spmat idistance dW longitude latitude, id(_ID) dfunction(rhaversine) norm(row)

    Then, I want to create a distance cutoff, using 1000 km limits. Therefore, I write:

    spmat idistance dW1000 longitude latitude, id(_ID) dfunction(rhaversine) norm(row) vtruncated(1/1000)

    What is not clear to me is why I get a warning saying "spatial-weighting matrix contains 37 islands"

    Of course I do not have 37 islands in my dataset. Moreover, I noticed that if I reduce the cutoff, say 1/500 the number of "supposed" islands increases to 63. Differently, it reduces if I set 1/2000.

    As far as I understood, if I use vtruncated option, I set the weights of neighbors of each spatial unit to zero if they lie 1000 or more
    km from a given unit. Therefore, why I get the warning above, which does not appear when I do not set vtruncated?

    Thanks,

    Dario
    Last edited by Dario Maimone Ansaldo Patti; 25 May 2017, 02:54.

  • #2
    As far as I understood, if I use vtruncated option, I set the weights of neighbors of each spatial unit to zero if they lie 1000 or more
    km from a given unit.
    Yes and those areas that are islands have zero weights and therefore have zero links to other areas.

    Code:
    . clear*
    
    . use pollute
    (Dataset used in the help files for spmat, spreg, spivreg)
    
    . sort longi
    
    . keep in 1/10
    (531 observations deleted)
    
    . replace id = _n
    (10 real changes made)
    First estimate weight matrix without truncation:
    Code:
    . spmat idistance dobj longitude latitude, id(id) dfunction(dhaversine) replace
    
    . spmat getmatrix dobj mymat
    Display the calculated distance:
    Code:
    . mata:  1:/mymat
    [symmetric]
                      1             2             3             4             5             6             7             8             9            10
         +---------------------------------------------------------------------------------------------------------------------------------------------+
       1 |            .                                                                                                                                |
       2 |  858.7211768             .                                                                                                                  |
       3 |  217.3526469   642.4249421             .                                                                                                    |
       4 |  452.5332616   407.5172598   235.4009689             .                                                                                      |
       5 |  293.1122069   568.7706027   76.25031625   161.2593068             .                                                                        |
       6 |  154.9431458    1008.76316   366.4825122   601.3442823   440.2488704             .                                                          |
       7 |  113.4742444   962.1936669   320.2569883    554.694974     393.49429   47.53902351             .                                            |
       8 |  1037.230999   183.4193258   820.1033986   584.7234386    745.255426   1185.366789   1138.398586             .                              |
       9 |  73.19565657   869.9652546   231.2181966   462.6921079   301.6045875   144.2963109   96.88165697   1044.712794             .                |
      10 |  162.8890043   717.9220322   91.29359608   311.3952831   151.6592864   295.7010176   248.2181349   891.9305749   152.9132906             .  |
         +---------------------------------------------------------------------------------------------------------------------------------------------+
    
    . spmat sum dobj, link detail
    
    Summary of spatial-weighting object dobj
    -----------------------------------------
            Matrix |             Description
    ---------------+-------------------------
        Dimensions |                 10 x 10
         Stored as |                 10 x 10
     Links         |
             total |                      90
               min |                       9
              mean |                       9
               max |                       9
    -----------------------------------------
    
    Tabulation of links
    -------------------------
     # of links |        Obs
    ------------+------------
              9 |         10
    ------------+------------
            Sum |         10
    -------------------------
    Now set truncation at 100 km:

    Code:
    . spmat idistance dobj longitude latitude, id(id) dfunction(dhaversine) replace vtrunc(1/100)
    warning: spatial-weighting matrix contains 3 islands
    
    . spmat getmatrix dobj mymat
    Display distance - all distances greater than 100 have been set to 0 (and therefore 1/0 is missing) . Note that ares 2, 4, and 8 have zero links to the other areas and are now islands:
    Code:
    . mata:  1:/mymat
    [symmetric]
                      1             2             3             4             5             6             7             8             9            10
         +---------------------------------------------------------------------------------------------------------------------------------------------+
       1 |            .                                                                                                                                |
       2 |            .             .                                                                                                                  |
       3 |            .             .             .                                                                                                    |
       4 |            .             .             .             .                                                                                      |
       5 |            .             .   76.25031625             .             .                                                                        |
       6 |            .             .             .             .             .             .                                                          |
       7 |            .             .             .             .             .   47.53902351             .                                            |
       8 |            .             .             .             .             .             .             .             .                              |
       9 |  73.19565657             .             .             .             .             .   96.88165697             .             .                |
      10 |            .             .   91.29359608             .             .             .             .             .             .             .  |
         +---------------------------------------------------------------------------------------------------------------------------------------------+
    
    . spmat sum dobj, link detail
    
    Summary of spatial-weighting object dobj
    -----------------------------------------
            Matrix |             Description
    ---------------+-------------------------
        Dimensions |                 10 x 10
         Stored as |                 10 x 10
     Links         |
             total |                      10
               min |                       0
              mean |                       1
               max |                       2
    -----------------------------------------
    
    Tabulation of links
    -------------------------
     # of links |        Obs
    ------------+------------
              0 |          3
              1 |          4
              2 |          3
    ------------+------------
            Sum |         10
    -------------------------
    
    Ids of observations with 0 links:
     2 4 8
    
    Ids of observations with 2 links:
     3 7 9

    Comment


    • #3
      Thank you very much Scott. Now it is clear
      ​​​

      Comment

      Working...
      X