1

I am following this tutorial for Multiple Regression - Quadratic Assignment Procedure http://www.umasocialmedia.com/socialnetworks/lecture-9-patterns-in-social-networks/. It is used to study the multiplexity of nodes i.e age, gender attribute. I have tried to execute the given code for given context. In this tutorial they find similarity on basis of gender, same political party, country and number of bills cosponsor together. First they read 4 CSV files and convert them into matrix format. When I tried to execute, got this error

Error in predicting_matrices[1, , ] <- gender_matrix : number of items to replace is not a multiple of replacement length

 getwd()
    library(sna)
    #Load Same-County Network
    county_network=read.csv(file.choose(),header=TRUE)
    county_matrix=as.matrix(county_network)

    #Load Same-Gender Network
    gender_network=read.csv(file.choose(),header=TRUE)
    gender_matrix=as.matrix(gender_network)

    #Load Same-Party Network
    party_network=read.csv(file.choose(),header=TRUE)
    party_matrix=as.matrix(party_network)

    #Load Number-Joint-Cosponsorships Network
    cosp_network=read.csv(file.choose(),header=TRUE)
    cosp_matrix=as.matrix(cosp_network)

    #Join The Predicting Matrices Together
    predicting_matrices <- array (NA, c(3, length(county_network[1,]), length(county_network[1,])))

    predicting_matrices[1,,] <- county_matrix
    Error in predicting_matrices[1, , ] <- county_matrix : 
      number of items to replace is not a multiple of replacement length

    predicting_matrices[2,,] <- gender_matrix
    Error in predicting_matrices[1, , ] <- gender_matrix : 
      number of items to replace is not a multiple of replacement length

    predicting_matrices[3,,] <- party_matrix
    Error in predicting_matrices[1, , ] <- party_matrix : 
      number of items to replace is not a multiple of replacement length


    #Now Run a QAP Regression called model and Show the Results
    model <- netlm(cosp_matrix,predicting_matrices)
    Error in netlm(cosp_matrix, predicting_matrices) : 
      Homogeneous graph orders required in netlm.
user12
  • 761
  • 8
  • 24
  • Please, could you post the links to the 4 csv files ? – Marco Sandri May 11 '17 at 09:57
  • The links of the files are given in the mentioned link in the post – user12 May 11 '17 at 10:35
  • http://www.umasocialmedia.com/socialnetworks/wp-content/uploads/2016/10/127th1ModeDV.csv http://www.umasocialmedia.com/socialnetworks/wp-content/uploads/2016/10/127th1ModeParty.csv http://www.umasocialmedia.com/socialnetworks/wp-content/uploads/2016/10/127th1ModeGender.csv http://www.umasocialmedia.com/socialnetworks/wp-content/uploads/2016/11/127thLegislatureSenateSponsorshipDomesticViolence.csv – user12 May 11 '17 at 10:36
  • Your datasets have different dimensions; all have 35 rows but one has 33 columns and the others 36. This is why you get error messages. In addiction, be careful with the conversion from data.frame to matrix. Try for example `head(gender_matrix)`: it is a matrix of strings. – Marco Sandri May 11 '17 at 11:03
  • the link of 4th data file is not given please visit this page. http://www.umasocialmedia.com/socialnetworks/lecture-9-patterns-in-social-networks/ i have use the correct datafile now … The data is given under this line of webpage "and the adjacency matrix of senators connected through joint county representation would look like this…" – user12 May 11 '17 at 12:50
  • After using correct file the error is removed o this line predicting_matrices[1,,] <- county_matrix predicting_matrices[2,,] <- gender_matrix Error in predicting_matrices[2, , ] <- gender_matrix : number of items to replace is not a multiple of replacement length – user12 May 11 '17 at 12:51
  • 1
    `predicting_matrices` has dimension 3 x 36 x 36 while `county_matrix`, `gender_matrix`, `party_matrix` and `cosp_matrix` are 35 x 36. Check the definition of `predicting_matrices` – Marco Sandri May 11 '17 at 13:36

0 Answers0