R arm of the Python modules morie.fn.igrav*. Igrav:
log-linear gravity OLS on the positive flows. Igravbl: iterative
proportional fitting to origin and destination totals (as
stats::loglin with a start table). Igravcl: distance-decay
exponent by Poisson ML with the mass product as offset (reproduces total
flow and mean log distance). Igraver: RMSE and standardised RMSE.
Igravfe: PPML with origin and destination fixed effects.
Igravlm: LM error test on gravity residuals. Igravnb:
negative-binomial (NB2) gravity by ML, as MASS::glm.nb.
Igravrt: Huff retail probabilities. Igravsq: symmetric
gravity on a square OD matrix with an asymmetry index. Igravvf:
variance function \(\phi\mu^p\). Igravwl: Wilson's doubly
constrained entropy model.
Usage
Igrav(flows, mass_o, mass_d, dist)
Igravbl(flow_matrix, row_totals, col_totals, tol = 1e-12, max_iter = 10000)
Igravcl(flows, mass_o, mass_d, dist)
Igraver(flows, flows_hat)
Igravfe(flows, origin_id, dest_id, dist)
Igravlm(resid, W)
Igravnb(flows, mass_o, mass_d, dist)
Igravrt(mass, dist, beta = 2, demand = NULL)
Igravsq(flow_matrix, mass, dist_matrix)
Igravvf(flows_hat, phi = 1, power = 1)
Igravwl(flows, mass_o, mass_d, dist, beta = 1, tol = 1e-12, max_iter = 10000)Arguments
- flows
Observed flows (vector of pairs; a matrix for
Igravwl, or NULL there).- mass_o, mass_d
Origin and destination masses (totals for
Igravwl).- dist
Distances (a cost matrix for
Igravwl, a consumer by centre matrix forIgravrt).- flow_matrix
Square or rectangular flow matrix.
- row_totals, col_totals
Target totals.
- tol
Relative tolerance.
- max_iter
Iteration cap.
- flows_hat
Predicted flows.
- origin_id, dest_id
Origin and destination labels.
- resid
Gravity residuals.
- W
Weights between origin-destination pairs.
- mass
Attractiveness (
Igravrt) or masses of the places (Igravsq).- beta
Distance- or cost-decay parameter.
- demand
Demand at each consumer location.
- dist_matrix
Distances between the places.
- phi
Dispersion.
- power
Variance power.
References
Tinbergen, J. (1962). Shaping the World Economy. Twentieth Century Fund, New York.
Santos Silva, J. M. C. and Tenreyro, S. (2006). The log of gravity. Review of Economics and Statistics 88, 641-658.
Wilson, A. G. (1967). A statistical theory of spatial distribution models. Transportation Research 1, 253-269.
Deming, W. E. and Stephan, F. F. (1940). On a least squares adjustment of a sampled frequency table when the expected marginal totals are known. Annals of Mathematical Statistics 11, 427-444.
Huff, D. L. (1963). A probabilistic analysis of shopping center trade areas. Land Economics 39, 81-90.
Hyman, G. M. (1969). The calibration of trip distribution models. Environment and Planning 1, 105-112.
Anderson, J. E. and van Wincoop, E. (2003). Gravity with gravitas. American Economic Review 93, 170-192.
Knudsen, D. C. and Fotheringham, A. S. (1986). Matrix comparison, goodness-of-fit, and spatial interaction modeling. International Regional Science Review 10, 127-147.
Examples
Fl <- c(12, 3, 30, 7, 55, 4, 9, 21)
mo <- c(5, 5, 9, 9, 20, 20, 7, 7)
md <- c(9, 20, 5, 20, 5, 9, 20, 9)
d <- c(1, 3, 1, 2, 3, 2, 2.5, 1.5)
Igrav(Fl, mo, md, d)$coefficients
#> [1] 7.4646102 -0.5715425 -1.7577700 0.5894246
Igravcl(Fl, mo, md, d)$statistic
#> [1] 0.9079358
Igravbl(matrix(1:4, 2, byrow = TRUE), c(5, 5), c(6, 4))$balanced
#> [,1] [,2]
#> [1,] 2.757651 2.242349
#> [2,] 3.242349 1.757651
