rm(list=ls()) #remove all the objects in the work space
setwd("/Users/se776257/OneDrive - University of Central Florida/Desktop/Prof. An/02 Teaching/Guest lecture/2026 Kyungpook/Method workshop/Network/Outcome/") #the folder where you extract data and save files
You need to download necessary R packages. R is like Roblox; R provides a platform and users create fun games (packages) and share them with other users. Today, the following packages are needed to play the ‘Network Analysis’ game!
library(haven)
library(igraph)
## Warning: package 'igraph' was built under R version 4.3.3
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:igraph':
##
## as_data_frame, groups, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Import raw data file
df <- read.csv(file="network_2025_06_30.csv")
Check the number of individuals in the dataset
length(unique(df$master_PID))
## [1] 15179
Let’s see the frequency by exit type
table(df$dest_unshelter)
##
## 0 1
## 28697 2451
table(df$dest_shelter)
##
## 0 1
## 29184 1964
table(df$dest_housing)
##
## 0 1
## 29893 1255
table(df$dest_no_interview)
##
## 0 1
## 28680 2468
table(df$dest_deceased)
##
## 0 1
## 31118 30
table(df$dest_dbl_up)
##
## 0 1
## 27921 3227
table(df$dest_institution)
##
## 0 1
## 30477 671
table(df$dest_temp_housing)
##
## 0 1
## 29459 1689
table(df$dest_other)
##
## 0 1
## 24557 6591
See the column: projecttype
table(df$projecttype)
##
##
## 247
## 1. Emergency Shelter
## 5784
## 10. PH – Housing with Services (no disability required for entry)
## 62
## 12. Homelessness Prevention
## 1378
## 13. PH - Rapid Re-Housing
## 1478
## 14. Coordinated Entry
## 5371
## 15
## 10785
## 15. Youth shelter
## 1
## 2. Transitional Housing
## 700
## 3. PH - Permanent Supportive Housing (disability required for entry)
## 165
## 4. Street Outreach
## 1222
## 6. Services Only
## 3437
## 7. Other
## 518
#we only need numbers for network analysis, so let's remove text.
df$projecttype <- gsub("^(\\d+)\\..*", "\\1", df$projecttype)
#See if you correctly cleaned the data
table(df$projecttype)
##
## 1 10 12 13 14 15 2 3 4 6 7
## 247 5784 62 1378 1478 5371 10786 700 165 1222 3437 518
Now, only select those who exited unsheltered (dest_unshelter == 1)
db <- df %>%
filter(dest_unshelter == 1)
Extract two columns of data and create a network data.frame
y <- data.frame(db$projecttype, db$next_entry)
colnames(y) <- c("source", "target")
Delete cases whose the next entry is NA
y <- y[!is.na(y$source), ]
y <- y[!is.na(y$target), ]
We will keep “unsheltered”- the final destination to show in the network
y$target[y$target =="16"] <- "UNSHELTER"
y <- y[!is.na(y$target), ]
y <- y[!is.na(y$source), ]
See how the network data look like
table(y$target)
##
## 1 10 12 13 14 15 2 3
## 201 1 7 67 463 395 12 1
## 4 6 7 UNSHELTER
## 65 76 20 1143
Save the network data as CSV file
write.csv(y, file = "networkgephi_project_unshelter.csv")
Do the same job for other projecttype: Shelter, housing, no_interview, deceased, dbl_up, institution, temp_housing, and others