Adjacent matrix from igraph package to be used for autologistic model in ngspatial package in R












0














I am interested on running an autologistic model in ngspatial package in R. My data objects are polygones. Usually, adjacency matrices for polygones are built up based on the coordinates of the polygones centroids. However, i have define my adjacency (0/1) based on a minimum distance criterium between polygones, measured from and to the border of each polygone. I have done this in arcmap, and then with igraph package i generated the Adjacency matrix:




g<-graph_from_data_frame(My data)



A<-as_adjacency_matrix(g, attr="Dist")



A



42 x 42 sparse Matrix of class "dgCMatrix"
[[ suppressing 42 column names ‘1’, ‘2’, ‘3’ ... ]]




My matrix is just 0 and 1 values, totally symmetric (42 x 42).



However, when i try to use it in a autologistic model in ngspatial i get an error messege:




ms_autolog<-autologistic(Occupancy~Area, A=A )



'You must supply a numeric and symmetric adjacency matrix'.




I supposed that dgCMatrix is just not compatible with ngspatial, but havent found how to convert it. I have also tried directly to shape my data.csv file as a matrix, read it as a matrix, but still it cannot be read by the autologistic model.



Does anybody has any idea how can i solve this?



Many thanks in advance!



Ana María.










share|improve this question



























    0














    I am interested on running an autologistic model in ngspatial package in R. My data objects are polygones. Usually, adjacency matrices for polygones are built up based on the coordinates of the polygones centroids. However, i have define my adjacency (0/1) based on a minimum distance criterium between polygones, measured from and to the border of each polygone. I have done this in arcmap, and then with igraph package i generated the Adjacency matrix:




    g<-graph_from_data_frame(My data)



    A<-as_adjacency_matrix(g, attr="Dist")



    A



    42 x 42 sparse Matrix of class "dgCMatrix"
    [[ suppressing 42 column names ‘1’, ‘2’, ‘3’ ... ]]




    My matrix is just 0 and 1 values, totally symmetric (42 x 42).



    However, when i try to use it in a autologistic model in ngspatial i get an error messege:




    ms_autolog<-autologistic(Occupancy~Area, A=A )



    'You must supply a numeric and symmetric adjacency matrix'.




    I supposed that dgCMatrix is just not compatible with ngspatial, but havent found how to convert it. I have also tried directly to shape my data.csv file as a matrix, read it as a matrix, but still it cannot be read by the autologistic model.



    Does anybody has any idea how can i solve this?



    Many thanks in advance!



    Ana María.










    share|improve this question

























      0












      0








      0







      I am interested on running an autologistic model in ngspatial package in R. My data objects are polygones. Usually, adjacency matrices for polygones are built up based on the coordinates of the polygones centroids. However, i have define my adjacency (0/1) based on a minimum distance criterium between polygones, measured from and to the border of each polygone. I have done this in arcmap, and then with igraph package i generated the Adjacency matrix:




      g<-graph_from_data_frame(My data)



      A<-as_adjacency_matrix(g, attr="Dist")



      A



      42 x 42 sparse Matrix of class "dgCMatrix"
      [[ suppressing 42 column names ‘1’, ‘2’, ‘3’ ... ]]




      My matrix is just 0 and 1 values, totally symmetric (42 x 42).



      However, when i try to use it in a autologistic model in ngspatial i get an error messege:




      ms_autolog<-autologistic(Occupancy~Area, A=A )



      'You must supply a numeric and symmetric adjacency matrix'.




      I supposed that dgCMatrix is just not compatible with ngspatial, but havent found how to convert it. I have also tried directly to shape my data.csv file as a matrix, read it as a matrix, but still it cannot be read by the autologistic model.



      Does anybody has any idea how can i solve this?



      Many thanks in advance!



      Ana María.










      share|improve this question













      I am interested on running an autologistic model in ngspatial package in R. My data objects are polygones. Usually, adjacency matrices for polygones are built up based on the coordinates of the polygones centroids. However, i have define my adjacency (0/1) based on a minimum distance criterium between polygones, measured from and to the border of each polygone. I have done this in arcmap, and then with igraph package i generated the Adjacency matrix:




      g<-graph_from_data_frame(My data)



      A<-as_adjacency_matrix(g, attr="Dist")



      A



      42 x 42 sparse Matrix of class "dgCMatrix"
      [[ suppressing 42 column names ‘1’, ‘2’, ‘3’ ... ]]




      My matrix is just 0 and 1 values, totally symmetric (42 x 42).



      However, when i try to use it in a autologistic model in ngspatial i get an error messege:




      ms_autolog<-autologistic(Occupancy~Area, A=A )



      'You must supply a numeric and symmetric adjacency matrix'.




      I supposed that dgCMatrix is just not compatible with ngspatial, but havent found how to convert it. I have also tried directly to shape my data.csv file as a matrix, read it as a matrix, but still it cannot be read by the autologistic model.



      Does anybody has any idea how can i solve this?



      Many thanks in advance!



      Ana María.







      r igraph adjacency-list






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 17:29









      Ana Prieto

      134




      134
























          1 Answer
          1






          active

          oldest

          votes


















          0














          It's difficult to check this without a minimal working example but you could try this:



          A <- as_adjacency_matrix(g, attr = "Dist", sparse = F)


          This way you get a binary matrix with 0 and 1 instead of a sparse matrix.






          share|improve this answer

















          • 1




            Yes, that's how it worked! Thanks for the confirmation though. I found it finally yesterday, and was actually comming to make an update ;). It was a very easy solution, but i had assumed sparse=T because in theory an adj. matrix can be a sparse matrix.
            – Ana Prieto
            Nov 21 at 16:00













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398421%2fadjacent-matrix-from-igraph-package-to-be-used-for-autologistic-model-in-ngspati%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          It's difficult to check this without a minimal working example but you could try this:



          A <- as_adjacency_matrix(g, attr = "Dist", sparse = F)


          This way you get a binary matrix with 0 and 1 instead of a sparse matrix.






          share|improve this answer

















          • 1




            Yes, that's how it worked! Thanks for the confirmation though. I found it finally yesterday, and was actually comming to make an update ;). It was a very easy solution, but i had assumed sparse=T because in theory an adj. matrix can be a sparse matrix.
            – Ana Prieto
            Nov 21 at 16:00


















          0














          It's difficult to check this without a minimal working example but you could try this:



          A <- as_adjacency_matrix(g, attr = "Dist", sparse = F)


          This way you get a binary matrix with 0 and 1 instead of a sparse matrix.






          share|improve this answer

















          • 1




            Yes, that's how it worked! Thanks for the confirmation though. I found it finally yesterday, and was actually comming to make an update ;). It was a very easy solution, but i had assumed sparse=T because in theory an adj. matrix can be a sparse matrix.
            – Ana Prieto
            Nov 21 at 16:00
















          0












          0








          0






          It's difficult to check this without a minimal working example but you could try this:



          A <- as_adjacency_matrix(g, attr = "Dist", sparse = F)


          This way you get a binary matrix with 0 and 1 instead of a sparse matrix.






          share|improve this answer












          It's difficult to check this without a minimal working example but you could try this:



          A <- as_adjacency_matrix(g, attr = "Dist", sparse = F)


          This way you get a binary matrix with 0 and 1 instead of a sparse matrix.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 17:45









          Ben Nutzer

          9316




          9316








          • 1




            Yes, that's how it worked! Thanks for the confirmation though. I found it finally yesterday, and was actually comming to make an update ;). It was a very easy solution, but i had assumed sparse=T because in theory an adj. matrix can be a sparse matrix.
            – Ana Prieto
            Nov 21 at 16:00
















          • 1




            Yes, that's how it worked! Thanks for the confirmation though. I found it finally yesterday, and was actually comming to make an update ;). It was a very easy solution, but i had assumed sparse=T because in theory an adj. matrix can be a sparse matrix.
            – Ana Prieto
            Nov 21 at 16:00










          1




          1




          Yes, that's how it worked! Thanks for the confirmation though. I found it finally yesterday, and was actually comming to make an update ;). It was a very easy solution, but i had assumed sparse=T because in theory an adj. matrix can be a sparse matrix.
          – Ana Prieto
          Nov 21 at 16:00






          Yes, that's how it worked! Thanks for the confirmation though. I found it finally yesterday, and was actually comming to make an update ;). It was a very easy solution, but i had assumed sparse=T because in theory an adj. matrix can be a sparse matrix.
          – Ana Prieto
          Nov 21 at 16:00




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398421%2fadjacent-matrix-from-igraph-package-to-be-used-for-autologistic-model-in-ngspati%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin