Get startedGet started for free

Most Traveled To and From Stations with Weights

So far, we've only looked at our network with unweighted edges. But our edge weights are actually the number of trips, so it seems logical that we would want to extend our analysis of degrees by adding a weighted degree distribution. This is important because while a balanced degree ratio is important, the item that would need to be rebalanced is bikes. If the weights are the same across all stations, then an unweighted degree ratio would work. But if we want to know how many bikes are actually flowing, we need to consider weights.

The weighted analog to degree distribution is strength. We can calculate this with the strength() function, which presents a weighted degree distribution based on the weight attribute of a graph's edges.

This exercise is part of the course

Case Studies: Network Analysis in R

View Course

Exercise instructions

  • Create a data frame containing the following columns.
    • trip_out should contain the "out" weighted degree (strength) distribution of trip_g_simp.
    • trip_in should contain the "in" weighted degree distribution.
    • ratio should contain the ratio of "out" degrees divided by "in" degrees.
  • Filter trip_strng for rows where both trip_out and trip_in are greater than 10.
  • Plot a histogram of the filtered ratios.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

trip_strng <- data_frame(
  # Find the "out" strength distribution
  trip_out = strength(___, mode = "___"), 
  # ... and the "in" strength distribution
  trip_in = strength(___, mode = "in"),
  # Calculate the ratio of out / in
  ratio = ___ / trip_in
)

trip_strng_filtered <- trip_strng %>%
  # Filter for rows where trips in and out are both over 10
  filter(___ > 10, ___ > 10) 

# Plot histogram of filtered ratios
hist(___$ratio)
Edit and Run Code