huff.lambda: Fitting the distance parameter lambda in the Huff model

Description Usage Arguments Details Value Note Author(s) References See Also Examples

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

1
2
3
4
5
6
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 data.frame containing the origins, locations and the explanatory variables (attraction, transport costs)

origins

the column in the interaction matrix huffdataset containing the origins (e.g. ZIP codes)

locations

the column in the interaction matrix huffdataset containing the locations (e.g. store codes)

attrac

the column in the interaction matrix huffdataset containing the attraction variable (e.g. sales area)

dist

the column in the interaction matrix huffdataset containing the transport costs (e.g. travelling time or street distance)

gamma

a single numeric value of γ for the exponential weighting of the attraction variable (default: 1)

atype

Type of attraction weighting function: atype = "pow" (power function), atype = "exp" (exponential function) or atype = "logistic" (default: atype = "pow")

gamma2

if atype = "logistic" a second γ parameter is needed

lambda_startv

Start value for λ search

lambda_endv

End value for λ search

dtype

Type of distance weighting function: dtype = "pow" (power function), dtype = "exp" (exponential function) or dtype = "logistic" (default: dtype = "pow")

localmarket_dataset

A data.frame containing the origins saved in a column which has the same name as in huffdataset and another column containing the local market potential

origin_id

the column in the dataset localmarket_dataset containing the origins (e.g. statistical districts, ZIP codes)

localmarket

the column in the dataset localmarket_dataset containing the local market potential (e.g. purchasing power, number of customers)

location_dataset

A data.frame containing the suppliers/locations and their observed total values

location_id

the column in the dataset location_dataset containing the locations (e.g. store codes), j, according to the codes in huffdataset

location_total

the column in the dataset location_dataset containing the observed total values of suppliers/locations, T_{j,obs} (e.g. annual sales, total number of customers)

method

If method = "bisection" (default value), the optimal λ is found by bisection. If method = "compare", several values are tried and the best one is found ("trial and error")

iterations

a single numeric value for the desired number of iterations

output

If output = "iterations", the results for every single iteration is shown. If output = "total", total sales and market shares (or total market area) of the suppliers are shown.

plotVal

If plotVal = TRUE, the function shows a simple plot of λ values against residuals

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: show_proc = FALSE (messages off)

check_df

logical argument that indicates if the given dataset is checked for correct input, only for internal use, should not be deselected (default: TRUE)

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 λ 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 γ and λ.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 

Example output

$gamma
[1] 1

$lambda
[1] -2.000488

Iteration 1 of 10 ... 
Iteration 2 of 10 ... 
Iteration 3 of 10 ... 
Iteration 4 of 10 ... 
Iteration 5 of 10 ... 
Iteration 6 of 10 ... 
Iteration 7 of 10 ... 
Iteration 8 of 10 ... 
Iteration 9 of 10 ... 
Iteration 10 of 10 ... 

   Iteration    Lambda
1          1 -1.750000
2          2 -2.125000
3          3 -1.937500
4          4 -2.031250
5          5 -1.984375
6          6 -2.007812
7          7 -1.996094
8          8 -2.001953
9          9 -1.999023
10        10 -2.000488
Iteration 1 of 151 ... 
Iteration 2 of 151 ... 
Iteration 3 of 151 ... 
Iteration 4 of 151 ... 
Iteration 5 of 151 ... 
Iteration 6 of 151 ... 
Iteration 7 of 151 ... 
Iteration 8 of 151 ... 
Iteration 9 of 151 ... 
Iteration 10 of 151 ... 
Iteration 11 of 151 ... 
Iteration 12 of 151 ... 
Iteration 13 of 151 ... 
Iteration 14 of 151 ... 
Iteration 15 of 151 ... 
Iteration 16 of 151 ... 
Iteration 17 of 151 ... 
Iteration 18 of 151 ... 
Iteration 19 of 151 ... 
Iteration 20 of 151 ... 
Iteration 21 of 151 ... 
Iteration 22 of 151 ... 
Iteration 23 of 151 ... 
Iteration 24 of 151 ... 
Iteration 25 of 151 ... 
Iteration 26 of 151 ... 
Iteration 27 of 151 ... 
Iteration 28 of 151 ... 
Iteration 29 of 151 ... 
Iteration 30 of 151 ... 
Iteration 31 of 151 ... 
Iteration 32 of 151 ... 
Iteration 33 of 151 ... 
Iteration 34 of 151 ... 
Iteration 35 of 151 ... 
Iteration 36 of 151 ... 
Iteration 37 of 151 ... 
Iteration 38 of 151 ... 
Iteration 39 of 151 ... 
Iteration 40 of 151 ... 
Iteration 41 of 151 ... 
Iteration 42 of 151 ... 
Iteration 43 of 151 ... 
Iteration 44 of 151 ... 
Iteration 45 of 151 ... 
Iteration 46 of 151 ... 
Iteration 47 of 151 ... 
Iteration 48 of 151 ... 
Iteration 49 of 151 ... 
Iteration 50 of 151 ... 
Iteration 51 of 151 ... 
Iteration 52 of 151 ... 
Iteration 53 of 151 ... 
Iteration 54 of 151 ... 
Iteration 55 of 151 ... 
Iteration 56 of 151 ... 
Iteration 57 of 151 ... 
Iteration 58 of 151 ... 
Iteration 59 of 151 ... 
Iteration 60 of 151 ... 
Iteration 61 of 151 ... 
Iteration 62 of 151 ... 
Iteration 63 of 151 ... 
Iteration 64 of 151 ... 
Iteration 65 of 151 ... 
Iteration 66 of 151 ... 
Iteration 67 of 151 ... 
Iteration 68 of 151 ... 
Iteration 69 of 151 ... 
Iteration 70 of 151 ... 
Iteration 71 of 151 ... 
Iteration 72 of 151 ... 
Iteration 73 of 151 ... 
Iteration 74 of 151 ... 
Iteration 75 of 151 ... 
Iteration 76 of 151 ... 
Iteration 77 of 151 ... 
Iteration 78 of 151 ... 
Iteration 79 of 151 ... 
Iteration 80 of 151 ... 
Iteration 81 of 151 ... 
Iteration 82 of 151 ... 
Iteration 83 of 151 ... 
Iteration 84 of 151 ... 
Iteration 85 of 151 ... 
Iteration 86 of 151 ... 
Iteration 87 of 151 ... 
Iteration 88 of 151 ... 
Iteration 89 of 151 ... 
Iteration 90 of 151 ... 
Iteration 91 of 151 ... 
Iteration 92 of 151 ... 
Iteration 93 of 151 ... 
Iteration 94 of 151 ... 
Iteration 95 of 151 ... 
Iteration 96 of 151 ... 
Iteration 97 of 151 ... 
Iteration 98 of 151 ... 
Iteration 99 of 151 ... 
Iteration 100 of 151 ... 
Iteration 101 of 151 ... 
Iteration 102 of 151 ... 
Iteration 103 of 151 ... 
Iteration 104 of 151 ... 
Iteration 105 of 151 ... 
Iteration 106 of 151 ... 
Iteration 107 of 151 ... 
Iteration 108 of 151 ... 
Iteration 109 of 151 ... 
Iteration 110 of 151 ... 
Iteration 111 of 151 ... 
Iteration 112 of 151 ... 
Iteration 113 of 151 ... 
Iteration 114 of 151 ... 
Iteration 115 of 151 ... 
Iteration 116 of 151 ... 
Iteration 117 of 151 ... 
Iteration 118 of 151 ... 
Iteration 119 of 151 ... 
Iteration 120 of 151 ... 
Iteration 121 of 151 ... 
Iteration 122 of 151 ... 
Iteration 123 of 151 ... 
Iteration 124 of 151 ... 
Iteration 125 of 151 ... 
Iteration 126 of 151 ... 
Iteration 127 of 151 ... 
Iteration 128 of 151 ... 
Iteration 129 of 151 ... 
Iteration 130 of 151 ... 
Iteration 131 of 151 ... 
Iteration 132 of 151 ... 
Iteration 133 of 151 ... 
Iteration 134 of 151 ... 
Iteration 135 of 151 ... 
Iteration 136 of 151 ... 
Iteration 137 of 151 ... 
Iteration 138 of 151 ... 
Iteration 139 of 151 ... 
Iteration 140 of 151 ... 
Iteration 141 of 151 ... 
Iteration 142 of 151 ... 
Iteration 143 of 151 ... 
Iteration 144 of 151 ... 
Iteration 145 of 151 ... 
Iteration 146 of 151 ... 
Iteration 147 of 151 ... 
Iteration 148 of 151 ... 
Iteration 149 of 151 ... 
Iteration 150 of 151 ... 
Iteration 151 of 151 ... 

    Iteration Lambda
1           1  -1.00
2           2  -1.01
3           3  -1.02
4           4  -1.03
5           5  -1.04
6           6  -1.05
7           7  -1.06
8           8  -1.07
9           9  -1.08
10         10  -1.09
11         11  -1.10
12         12  -1.11
13         13  -1.12
14         14  -1.13
15         15  -1.14
16         16  -1.15
17         17  -1.16
18         18  -1.17
19         19  -1.18
20         20  -1.19
21         21  -1.20
22         22  -1.21
23         23  -1.22
24         24  -1.23
25         25  -1.24
26         26  -1.25
27         27  -1.26
28         28  -1.27
29         29  -1.28
30         30  -1.29
31         31  -1.30
32         32  -1.31
33         33  -1.32
34         34  -1.33
35         35  -1.34
36         36  -1.35
37         37  -1.36
38         38  -1.37
39         39  -1.38
40         40  -1.39
41         41  -1.40
42         42  -1.41
43         43  -1.42
44         44  -1.43
45         45  -1.44
46         46  -1.45
47         47  -1.46
48         48  -1.47
49         49  -1.48
50         50  -1.49
51         51  -1.50
52         52  -1.51
53         53  -1.52
54         54  -1.53
55         55  -1.54
56         56  -1.55
57         57  -1.56
58         58  -1.57
59         59  -1.58
60         60  -1.59
61         61  -1.60
62         62  -1.61
63         63  -1.62
64         64  -1.63
65         65  -1.64
66         66  -1.65
67         67  -1.66
68         68  -1.67
69         69  -1.68
70         70  -1.69
71         71  -1.70
72         72  -1.71
73         73  -1.72
74         74  -1.73
75         75  -1.74
76         76  -1.75
77         77  -1.76
78         78  -1.77
79         79  -1.78
80         80  -1.79
81         81  -1.80
82         82  -1.81
83         83  -1.82
84         84  -1.83
85         85  -1.84
86         86  -1.85
87         87  -1.86
88         88  -1.87
89         89  -1.88
90         90  -1.89
91         91  -1.90
92         92  -1.91
93         93  -1.92
94         94  -1.93
95         95  -1.94
96         96  -1.95
97         97  -1.96
98         98  -1.97
99         99  -1.98
100       100  -1.99
101       101  -2.00
102       102  -2.01
103       103  -2.02
104       104  -2.03
105       105  -2.04
106       106  -2.05
107       107  -2.06
108       108  -2.07
109       109  -2.08
110       110  -2.09
111       111  -2.10
112       112  -2.11
113       113  -2.12
114       114  -2.13
115       115  -2.14
116       116  -2.15
117       117  -2.16
118       118  -2.17
119       119  -2.18
120       120  -2.19
121       121  -2.20
122       122  -2.21
123       123  -2.22
124       124  -2.23
125       125  -2.24
126       126  -2.25
127       127  -2.26
128       128  -2.27
129       129  -2.28
130       130  -2.29
131       131  -2.30
132       132  -2.31
133       133  -2.32
134       134  -2.33
135       135  -2.34
136       136  -2.35
137       137  -2.36
138       138  -2.37
139       139  -2.38
140       140  -2.39
141       141  -2.40
142       142  -2.41
143       143  -2.42
144       144  -2.43
145       145  -2.44
146       146  -2.45
147       147  -2.46
148       148  -2.47
149       149  -2.48
150       150  -2.49
151       151  -2.50

MCI documentation built on May 2, 2019, 6:02 a.m.