Homework 3: The Social Relations Model

Advanced Network Analysis · ICPSR

Author

Your Name Here

Published

July 24, 2026

ImportantWhat You Need to Do

This assignment has four short tasks. The code is already written and the fitted model is included in the download, so you do not need to wait for the model to estimate. Run the chunks, examine the output, and replace each Your answer line with a short response in your own words.

Submit:

  1. Your completed .qmd file.
  2. The HTML file produced when you render it.

Most answers should take one short paragraph. Focus on what the results tell us about students’ friendship ratings rather than repeating statistical labels.

You need lame, ggplot2, patchwork, digest, and coda. Install the CRAN packages with:

install.packages(c("ggplot2", "patchwork", "digest", "coda", "remotes"))

lame will be on CRAN shortly. For now, the easiest installation is from GitHub if your computer has compilation tools:

remotes::install_github("netify-dev/lame")

If compilation is not available on your computer, use the compiled release for your operating system from the lame GitHub releases page.

1 The Question and the Data

We want to understand how friendship ratings depend on three kinds of structure: who is giving the rating, who is receiving it, and whether two students have a particularly positive or negative relationship with one another.

The data come from 32 Dutch university students. Each student rated every other student from (-1), a troubled relationship, to (4), best friends. Because the rating from student (i) to student (j) can differ from the rating from (j) to (i), this is a directed network. The data also record each student’s sex, smoking status, and degree program.

load("data/dutch_friends.rda")
Y[1:5, 1:5]
#>     s01 s02 s03 s04 s05
#> s01  NA   0   0   0   0
#> s02   1  NA   1   0   2
#> s03   0   1  NA   1   1
#> s04   0   1   1  NA   1
#> s05   0   1   1   0  NA
head(nodes)
student male smoker program
s01 0 1 3
s02 0 0 4
s03 0 0 4
s04 0 0 4
s05 0 0 4
s06 0 0 2

1.1 Task 1: Read the Outcome

Choose one nonmissing entry from the displayed section of Y. In two or three sentences, say who gave the rating, who received it, what the number means, and why reversing the row and column could produce a different answer.

TipYour Answer

Replace this line with your answer.

2 The Model

The code below organizes the covariates and loads the fitted Social Relations Model. The model includes:

  • A source effect for whether some students generally give warmer or colder ratings.
  • A target effect for whether some students generally receive warmer or colder ratings.
  • Reciprocity for whether two students’ ratings of one another are related.
  • Covariates for student attributes and shared attributes.

The fitted model is stored in cache/hwSRM.rda. Rendering this assignment should load that result rather than estimate it again.

Y <- Y[nodes$student, nodes$student]
Xn <- as.matrix(nodes[, c("male", "smoker")])
rownames(Xn) <- nodes$student
same <- function(v) {
  m <- outer(v, v, "==") * 1
  dimnames(m) <- list(nodes$student, nodes$student)
  m
}
Xd <- array(
  NA,
  dim = c(nrow(nodes), nrow(nodes), 3),
  dimnames = list(
    nodes$student,
    nodes$student,
    c("same_sex", "same_smoker", "same_program")
  )
)
Xd[, , "same_sex"] <- same(nodes$male)
Xd[, , "same_smoker"] <- same(nodes$smoker)
Xd[, , "same_program"] <- same(nodes$program)
hwSRM <- cache_fit("hwSRM", ame(
  Y = Y,
  Xdyad = Xd,
  Xrow = Xn,
  Xcol = Xn,
  family = "normal",
  symmetric = FALSE,
  R = 0,
  seed = 6886,
  nscan = 10000,
  burn = 10000,
  odens = 10,
  verbose = FALSE,
  plot = FALSE
))

3 Read the Actor Effects

The source effect tells us whether a student gives higher or lower ratings than the model otherwise expects. The target effect tells us whether a student receives higher or lower ratings than the model otherwise expects. These are adjustments on the original friendship-rating scale after accounting for the covariates.

ab_plot(hwSRM, effect = "sender") /
  ab_plot(hwSRM, effect = "receiver")

actor_effects <- data.frame(
  student = names(hwSRM$APM),
  source_effect = round(hwSRM$APM, 2),
  target_effect = round(hwSRM$BPM, 2)
)
head(actor_effects[order(-actor_effects$source_effect), ], 3)
student source_effect target_effect
s15 s15 0.63 -0.20
s07 s07 0.47 0.12
s20 s20 0.44 0.11
head(actor_effects[order(-actor_effects$target_effect), ], 3)
student source_effect target_effect
s10 s10 0.20 0.48
s30 s30 0.35 0.41
s22 s22 0.16 0.27

3.1 Task 2: Describe Two Students

Identify the student with the largest source effect and the student with the largest target effect. Explain each result using the actions in the data. Say who tended to give unusually warm ratings and who tended to receive unusually warm ratings. Do not describe either effect as a permanent personality trait.

TipYour Answer

Replace this line with your answer.

4 Read the Covariates

The estimate column gives the average fitted coefficient. The lower and upper columns give a 95% interval. Treat an association as clearly different from zero when its entire interval is either above or below zero.

coef_tbl(hwSRM)
term est lo hi clears_zero
intercept 0.247 -0.067 0.572
male_row 0.291 -0.058 0.606
smoker_row -0.211 -0.508 0.088
male_col 0.528 0.273 0.782 yes
smoker_col -0.108 -0.340 0.113
same_sex_dyad 0.405 0.250 0.555 yes
same_smoker_dyad 0.086 -0.028 0.205
same_program_dyad 0.230 0.100 0.355 yes

The coefficient names describe where each variable enters:

  • male_row and smoker_row concern the student giving the rating.
  • male_col and smoker_col concern the student receiving the rating.
  • same_sex_dyad, same_smoker_dyad, and same_program_dyad compare pairs who share an attribute with pairs who do not.

4.1 Task 3: Interpret Two Results

Choose two coefficients whose 95% intervals do not include zero. For each coefficient, state which ratings are being compared, whether the expected rating is higher or lower, and approximately how large the difference is on the (-1) to (4) rating scale. These are adjusted associations, not automatically causal effects.

TipYour Answer

Replace this line with your answer.

5 Check What the Model Still Misses

The plot compares the observed network with networks simulated from the fitted SRM. The vertical line is the observed value. The histogram shows what the model tends to produce. A large separation means the model is missing that feature.

gof_plot(hwSRM)

round(ppsd(hwSRM), 2)
#> sd.rowmean sd.colmean   dyad.dep  cycle.dep  trans.dep 
#>       0.11       0.26       0.19       6.56       9.52

Values near zero indicate close reproduction. Values much larger than two indicate a noticeable gap between the observed network and the networks generated by the model.

5.1 Task 4: Give the Bottom Line

In one short paragraph, answer all three questions:

  1. Which parts of the network does the SRM reproduce well?
  2. Which parts does it reproduce poorly?
  3. What have you learned about the friendship ratings that you would have missed by treating all directed ratings as independent observations?

Your answer should mention students giving ratings, receiving ratings, or rating one another. Avoid ending with only a technical statement such as “transitivity is high.”

TipYour Answer

Replace this line with your answer.

6 Submission Check

Before submitting, confirm that:

  • Your name appears at the top.
  • All four answer boxes have been replaced.
  • The document renders without an error.
  • You are submitting both the .qmd and rendered HTML file.
Session information
sessionInfo()
#> R version 4.3.3 (2024-02-29)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 24.04.3 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> time zone: America/New_York
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] patchwork_1.3.2 ggplot2_4.0.3   lame_1.3.4     
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtable_0.3.6         jsonlite_2.0.0       dplyr_1.2.1         
#>  [4] compiler_4.3.3       tidyselect_1.2.1     Rcpp_1.1.1-1.1      
#>  [7] parallel_4.3.3       tidyr_1.3.2          scales_1.4.0        
#> [10] yaml_2.3.12          fastmap_1.2.0        R6_2.6.1            
#> [13] labeling_0.4.3       generics_0.1.4       distributional_0.6.0
#> [16] knitr_1.51           htmlwidgets_1.6.4    backports_1.5.0     
#> [19] ggrepel_0.9.6        checkmate_2.3.4      tibble_3.3.1        
#> [22] pillar_1.11.1        RColorBrewer_1.1-3   posterior_1.6.1     
#> [25] rlang_1.2.0          broom_1.0.11         xfun_0.55           
#> [28] S7_0.2.2             otel_0.2.0           cli_3.6.6           
#> [31] withr_3.0.2          magrittr_2.0.5       digest_0.6.39       
#> [34] grid_4.3.3           lifecycle_1.0.5      vctrs_0.7.3         
#> [37] tensorA_0.36.2.1     evaluate_1.0.5       glue_1.8.1          
#> [40] farver_2.1.2         abind_1.4-8          purrr_1.2.2         
#> [43] rmarkdown_2.30       matrixStats_1.5.0    loo_2.9.0           
#> [46] tools_4.3.3          pkgconfig_2.0.3      htmltools_0.5.9