Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new function request: hts_prep_vmt (little sister to hts_prep_triprate) #165

Open
ashleyasmus opened this issue Jun 25, 2024 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@ashleyasmus
Copy link
Collaborator

Sent in email to @Ennazus. Can we consider this in the next feature update for the package, @erika-redding?

I think the most accurate way to calculate a weighted VMT is to follow the same process we use when calculating weighted trip rates. I had actually considered re-writing the hts_prep_triprate function to calculate VMT at one point using the same workflow – you can actually kind of trick hts_prep_triprate to do what I describe below with some creative subsetting, but it's not the prettiest.

I have the Met Council's data open on my computer, so this code below written for their data, but the concept should be the same:

Starting with the trip table:
vmt = trip[, .(
hh_id,
person_id,
day_id,
trip_id,
trip_weight,
distance_miles,
num_travelers,
mode_type
)]

Get the subset of trips made by auto modes, where the number of occupants is known:
vmt = vmt[num_travelers != 995 &
mode_type %in% c(8:9)]

Calculate trip-level vmt:
vmt[, vmt := distance_miles/num_travelers]

Calculate weighted vmt:
vmt[, weighted_vmt = sum(vmt * trip_weight]

Sum weighted VMT for each person-day:
weighted_vmt = vmt[,
.(weighted_vmt_personday = sum(weighted_vmt)),
.(day_id)]

Join weighted VMT to day table:
day_vmt = copy(day)
day_vmt[weighted_vmt,
weighted_vmt_personday := i.weighted_vmt_personday ,
on = .(day_id)]

Set weighted_vmt_personday to 0 where person did not travel by car that day:
day_vmt[is.na(weighted_vmt_personday ), weighted_vmt_personday := 0]

Join to household to get your city center variable,
... your code here
then get your total VMT by city center name:
day_vmt[day_weight > 0,
.(
weighted_vmt = sum(weighted_vmt),
weighted_num_days = sum(day_weight),
weighted_vmt_percap = sum(weighted_vmt) /
sum(day_weight)
),
keyby = 'city_center']

@ashleyasmus ashleyasmus added the enhancement New feature or request label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant