huff.lambda {MCI} | R Documentation |
Fitting the distance parameter lambda in the Huff model
Description
This function estimates a distance decay parameter from observed total store/location data (e.g. complete annual turnovers) using bisection or "trial and error"
Usage
huff.lambda(huffdataset, origins, locations, attrac, dist, gamma = 1, atype = "pow",
gamma2 = NULL, lambda_startv = -1, lambda_endv = -3, dtype = "pow",
localmarket_dataset, origin_id, localmarket,
location_dataset, location_id, location_total,
method = "bisection", iterations = 10, output = "matrix",
plotVal = FALSE, show_proc = FALSE, check_df = TRUE)
Arguments
huffdataset |
an interaction matrix which is a |
origins |
the column in the interaction matrix |
locations |
the column in the interaction matrix |
attrac |
the column in the interaction matrix |
dist |
the column in the interaction matrix |
gamma |
a single numeric value of |
atype |
Type of attraction weighting function: |
gamma2 |
if |
lambda_startv |
Start value for |
lambda_endv |
End value for |
dtype |
Type of distance weighting function: |
localmarket_dataset |
A |
origin_id |
the column in the dataset |
localmarket |
the column in the dataset |
location_dataset |
A |
location_id |
the column in the dataset |
location_total |
the column in the dataset |
method |
If |
iterations |
a single numeric value for the desired number of iterations |
output |
If |
plotVal |
If |
show_proc |
logical argument that indicates if the function prints messages about the state of process during the work (e.g. “Processing variable xyz ...”). Default: |
check_df |
logical argument that indicates if the given dataset is checked for correct input, only for internal use, should not be deselected (default: |
Details
In many cases, only total empirical values of the suppliers/locations (e.g. annual turnover) can be used for market area estimation. This function fits the Huff model by estimating the \lambda
parameter iteratively using an optimization algorithm based on the idea of Klein (1988). The fitting process in the huff.lambda
includes of given number of iterations, while the fit gets better with every iteration, measured using the sum of squared residuals of observed vs. expected total values. The iterative optimization can be done via bisection (see Kaw et al. 2011, ch. 03.03) or "trial and error" (see Fuelop et al. 2011).
Value
The function output can be controlled by the function argument output
. If output = "iterations"
, the results for every single iteration is shown (data.frame
). If output = "total"
, total sales and market shares (or total market area) of the suppliers are shown (data.frame
). The default output is a list
with \gamma
and \lambda
.
Note
Note that the iterations can be time-consuming and depend on the number of suppliers/locations. Use show_proc = TRUE
for monitoring the iteration process.
Author(s)
Thomas Wieland
References
Fuelop, G./Kopetsch, T./Schoepe, P. (2011): “Catchment areas of medical practices and the role played by geographical distance in the patient's choice of doctor”. In: The Annals of Regional Science, 46, 3, p. 691-706.
Kaw, A. K./Kalu, E. E./Nguyen, D. (2011): “Numerical Methods with Applications”. http://nm.mathforcollege.com/topics/textbook_index.html
Klein, R. (1988): “Der Lebensmittel-Einzelhandel im Raum Verden. Raeumliches Einkaufsverhalten unter sich wandelnden Bedingungen”. Flensburger Arbeitspapiere zur Landeskunde und Raumordnung, 6. Flensburg.
See Also
huff.attrac
, huff.shares
, huff.decay
, huff.fit
Examples
data(DIY1)
data(DIY2)
data(DIY3)
# Loading the three DIY store datasets
DIY_alldata <- merge (DIY1, DIY2, by.x = "j_destination", by.y = "j_destination")
# Add store data to distance matrix
huff_DIY <- huff.shares (DIY_alldata, "i_origin", "j_destination", "A_j_salesarea_sqm",
"t_ij_min", gamma = 1, lambda = -2)
# Calculating Huff local market shares
# Gamma = 1, Lambda = -2
huff_DIY <- merge (huff_DIY, DIY3, by.x = "i_origin", by.y = "district")
# Add data for origins
huff_DIY_total <- shares.total (huff_DIY, "i_origin", "j_destination", "p_ij",
"population")
# Calculating total market areas (=sums of customers)
colnames(DIY3) <- c("district", "pop")
# Change column name to "pop" (must be other name)
huff.lambda (huff_DIY, "i_origin", "j_destination", "A_j_salesarea_sqm",
"t_ij_min", gamma = 1, atype = "pow", gamma2 = NULL,
lambda_startv = -1, lambda_endv = -2.5, dtype= "pow",
DIY3, "district", "pop", huff_DIY_total, "suppliers_single", "sum_E_j",
method = "bisection", iterations = 10)
# Iterative search for the best lambda value using bisection
# Output: gamma and lambda
huff.lambda (huff_DIY, "i_origin", "j_destination", "A_j_salesarea_sqm",
"t_ij_min", gamma = 1, atype = "pow", gamma2 = NULL,
lambda_startv = -1, lambda_endv = -2.5, dtype= "pow",
DIY3, "district", "pop", huff_DIY_total, "suppliers_single", "sum_E_j",
method = "bisection", iterations = 10, output = "iterations", show_proc = TRUE)
# Same procedure, output: single iterations
huff.lambda (huff_DIY, "i_origin", "j_destination", "A_j_salesarea_sqm",
"t_ij_min", gamma = 1, atype = "pow", gamma2 = NULL,
lambda_startv = -1, lambda_endv = -2.5, dtype= "pow",
DIY3, "district", "pop", huff_DIY_total, "suppliers_single", "sum_E_j",
method = "compare", iterations = 10, output = "iterations", show_proc = TRUE, plotVal = TRUE)
# Using compare method, output: single iterations and plot