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

draft si_gravity.R #27

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions R/si_gravity.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
si_gravity <- function(O_i, D_j, C_ij, flows, data,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try adding some examples? You can use the "Insert Roxygen Skeleton" button, in the Code tab if I remember, to do this I think.

mu = 1, alpha = 1, beta = -1){

data = data %>%
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor issues with this:

  1. Use of both equals and arrow assignment in same script file, please use = throughout as that's the package style
  2. Use of pipe operator in function calls, not sure about this but if it works I'm happy to give it a spin

dplyr::mutate(
# Sum all flows from Origins to Destinations
total_flows = sum({{flows}}),

# Influence of scaling parameters on model variables
Oi_mu = {{O_i}}^mu,
Dj_alpha = {{D_j}}^alpha,
Cij_beta = {{C_ij}}^beta,

# Calculate unscaled flows Tij
T_ij = Oi_mu * Dj_alpha * Cij_beta,

# Calculate constrain parameter k
k = total_flows / sum(T_ij),

# Calculate flows based on total unconstrained model
T_ij = T_ij * k)

return(data %>% dplyr::select(-c(Oi_mu, Dj_alpha, Cij_beta, k, total_flows)))



}