Quadratic Assignment Procedure (QAP) Regression

WEN, Tzai-Hung (NTU Geography)

Source: McFarland, Daniel, et.al. 2010. “Social Network Analysis Labs in R.” Stanford University.
library(sna)

1. Load network data

data(studentnets.mrqap173, package="NetData")
ls()
## [1] "m173_sem1_FRN"  "m173_sem1_GND"  "m173_sem1_RCE"  "m173_sem1_SEAT"
## [5] "m173_sem1_SSL"  "m173_sem1_TSL"  "m173_sem2_SSL"  "m173_sem2_TSL"

FRN: Friendship (2 = best friend, 1 = friend, 0 = not friend)

GND: Gender homophily

RCE: Race homophily

SEAT: who sits next to whom (2 = faces, 1 = behind, 0 = not adjacent)

SSL: social interactions per hour

TSL: task interactions per hour


2. Predictor matrices

m173_sem1_SSL <- as.matrix(m173_sem1_SSL)
m173_sem1_TSL <- as.matrix(m173_sem1_TSL)
m173_sem1_FRN <- as.matrix(m173_sem1_FRN)
m173_sem1_SEAT <- as.matrix(m173_sem1_SEAT)
m173_sem1_RCE <- as.matrix(m173_sem1_RCE)
m173_sem1_GND <- as.matrix(m173_sem1_GND)

3. Response matrices

m173_sem2_SSL <- as.matrix(m173_sem2_SSL)
m173_sem2_TSL <- as.matrix(m173_sem2_TSL)

4. Predictor matrices: creating a # 3-d matrix (predictor x n x n)

predictor_matrices <- array(NA, c(6, length(m173_sem1_SSL[1,]),length(m173_sem1_SSL[1,]))) 
# OR: predictor_matrices <- array(NA, c(6, 26,26))

predictor_matrices[1,,] <- m173_sem1_SSL
predictor_matrices[2,,] <- m173_sem1_TSL
predictor_matrices[3,,] <- m173_sem1_FRN
predictor_matrices[4,,] <- m173_sem1_SEAT
predictor_matrices[5,,] <- m173_sem1_RCE
predictor_matrices[6,,] <- m173_sem1_GND

5. Model A. SSL2 <- SSL1 + TSL1 + FRN1 + SEAT1 + RCE + GND

# Fit a netlm model: the response matrix and the array of predictor matrices
nl<-netlm(m173_sem2_SSL, predictor_matrices)

# Make the model easier ot read
nlLabeled <- list()
nlLabeled <- summary(nl)

# adding lables
nlLabeled$names <- c("Intercept", "SSL1", "TSL1", "Friends", "Seat","Race","Gender")

# Round the ocefficients to two decimals
nlLabeled$coefficients = round(nlLabeled$coefficients, 2)
nlLabeled
## 
## OLS Network Model
## 
## Residuals:
##           0%          25%          50%          75%         100% 
## -1.652583881 -0.067206384  0.008678721  0.015216870  2.924942741 
## 
## Coefficients:
##           Estimate Pr(<=b) Pr(>=b) Pr(>=|b|)
## Intercept -0.02    0.351   0.649   0.630    
## SSL1       0.45    1.000   0.000   0.000    
## TSL1       0.03    0.959   0.041   0.051    
## Friends    0.16    0.994   0.006   0.006    
## Seat       0.08    0.993   0.007   0.007    
## Race       0.00    0.473   0.527   0.930    
## Gender     0.01    0.582   0.418   0.870    
## 
## Residual standard error: 0.3437 on 643 degrees of freedom
## Multiple R-squared: 0.3817   Adjusted R-squared: 0.3759 
## F-statistic: 66.16 on 6 and 643 degrees of freedom, p-value:     0 
## 
## 
## Test Diagnostics:
## 
##  Null Hypothesis: qap 
##  Replications: 1000 
##  Coefficient Distribution Summary:
## 
##        Intercept      SSL1      TSL1   Friends      Seat      Race
## Min    -5.492360 -2.894450 -5.205903 -3.178890 -3.337085 -3.715495
## 1stQ   -1.081998 -0.738184 -0.826869 -0.839301 -1.081920 -1.122872
## Median -0.194435 -0.209618 -0.351726 -0.102976 -0.185271  0.006572
## Mean   -0.199786 -0.005014 -0.041617 -0.007233 -0.090209  0.016332
## 3rdQ    0.789871  0.406819  0.320421  0.706268  0.762406  1.129563
## Max     3.050729  9.749465  9.243939  6.888217  4.807709  4.842567
##           Gender
## Min    -3.817561
## 1stQ   -1.034453
## Median -0.080123
## Mean   -0.013190
## 3rdQ    0.900824
## Max     5.113198

6. Model B. TSL2 <- TSL1 + SSL1 + FRN1 + SEAT1 + RCE + GND

n2<-netlm(m173_sem2_TSL, predictor_matrices)

n2Labeled <- list()
n2Labeled <- summary(n2)
n2Labeled$names <- c("Intercept", "SSL1", "TSL1", "Friends", "Seat","Race","Gender")

n2Labeled$coefficients = round(n2Labeled$coefficients, 2)
n2Labeled
## 
## OLS Network Model
## 
## Residuals:
##          0%         25%         50%         75%        100% 
## -6.79570345 -0.10044585 -0.00923077  0.02628499  7.90740702 
## 
## Coefficients:
##           Estimate Pr(<=b) Pr(>=b) Pr(>=|b|)
## Intercept  0.10    0.788   0.212   0.234    
## SSL1      -0.28    0.004   0.996   0.022    
## TSL1       1.01    1.000   0.000   0.000    
## Friends    0.01    0.564   0.436   0.900    
## Seat      -0.14    0.011   0.989   0.030    
## Race      -0.04    0.390   0.610   0.736    
## Gender    -0.09    0.136   0.864   0.278    
## 
## Residual standard error: 0.8241 on 643 degrees of freedom
## Multiple R-squared: 0.756    Adjusted R-squared: 0.7538 
## F-statistic: 332.1 on 6 and 643 degrees of freedom, p-value:     0 
## 
## 
## Test Diagnostics:
## 
##  Null Hypothesis: qap 
##  Replications: 1000 
##  Coefficient Distribution Summary:
## 
##        Intercept     SSL1     TSL1  Friends     Seat     Race   Gender
## Min     -3.34277 -7.59617 -2.17734 -4.72054 -3.62313 -3.30472 -3.79525
## 1stQ    -0.05125 -0.76490 -1.05840 -0.73691 -0.90071 -1.12233 -0.75809
## Median   0.72559 -0.05542 -0.68363 -0.03735 -0.08047 -0.13830  0.05028
## Mean     0.76274  0.01907  0.04372  0.04684 -0.03585  0.02499  0.03552
## 3rdQ     1.62982  0.65128 -0.16802  0.67981  0.80931  1.08513  0.85754
## Max      4.83562 10.92928 25.46084  5.52852  4.33466  4.46433  4.59682