Learn R Programming

adoption (version 0.6.4)

distances: Special distances for adoption

Description

Distance function given here are defined for the sole use within the model definition for adoption. These functions increase the processing speed in adoption.

THESE FUNCTIONS SHOULD NEVER BE USED OUTSIDE THE MODEL DEFINITION FOR adoption. THEY SHOULD BE USED ONLY IN THE SAME WAY AS GIVEN IN THE EXAMPLES OF adoption, WITHOUT ANY MODIFICATIONS!

Usage

GoldenbergDistance(param, dist, W, Goldenberg_C)
  VarDistance(param, dist, W)

Arguments

param

the weight parameter. For the Goldenberg distance it has (at least) two parameters; for the VAR distance it has one parameter.

dist

the matrix for Euclidean distances between the coordinates that are given by the function coord in the model definition.

W

A square matrix of size m, where m is the market size. Because of this argument, (nearly) any arbitrary use of the distance function will crash the whole system! Within adoption the correct size of the matrix will be passed.

Goldenberg_C

Some large constant, e.g. \(1e6\)

Value

NULL

Details

DO NOT USE THESE FUNCTIONS OUTSIDE THE MODEL DEFINITIONS FOR adoption.

References

  • Schlather, M. (2018) Introduction to the Gui of the R package 'adoption'. Technical Report. Attached with the package.

Examples

Run this code
# NOT RUN {
<!-- %  library(adoption);  library(RandomFieldsUtils) -->
# }
# NOT RUN {
Goldenberg <- list( ## model by Goldenberg, Libai, Muller (2010)
    m = 1000L,
    repetitions=10L,
    dt = 1,
    relative.instance = 0.2,
    SOCIAL = c(1, 5, 5),
    PRIVATE = c(5, 1, 5),
    Ic.start = function(param, m, rep, ...) {
      m * rnorm(m * rep, param[1], prod(param[1:2]))
    },
    Ic = function(param, Nt, m, start) {
      Inf * (2 * (Nt > start) - 1) ## start has size m * rep, i.e. Nt is
      ##                                   recycled
    },
    Ic.param = c("mean h" = 0.02,
		 "sigma" = 0.4),
    Ic.param.min = c(0.005, 0.08),
    Ic.param.max = c(0.1, 1.5),
    
    coord = function(param, m) {
      if (param[1] == 1) as.matrix(1:m)
      else {
	m2 <- ceiling(sqrt(m))
	m3 <- ceiling(m / m2)
	as.matrix(expand.grid(1:m2, 1:m3))[1:m, ]
      }},
    coord.param = c(dim = 2),
    weight =  function(param, dist, W) {
      GoldenbergDistance(param, dist, W, 1e6)
    },
 
    weight.param.min = 1.5,
    weight.param.max = 1.5,
    weight.param = c("max distance d"=1.5),
 
    Utrafo = function(U, threshold, ...) 1e6 * as.double(U>=threshold),
    
    Uthreshold = 0, ## here: constant for any people; we might
    Uthreshold.min = 0,
    Uthreshold.max = 0,
    Up.start = function(param, m, rep) rep(-1, m * rep),
    Up = function(param, m, nT, rep, ...) {
      pmax(-1e6 + 1,
	   -log(runif(nT * rep * m)/(1-param[1])) / log(1-param[2]))
      },
    Up.param = c(prob_a=0.1, prob_b=0.1),
    Up.param.min = c(0.005, 0.05),
    Up.param.max = c(0.99, 0.99),
    
    "MAX/PLUS OPERATORS" = rep(5, 3),
    alpha = c("alpha_1"=0, "alpha_2"=1),
    alpha.min = c(0, 1),
    alpha.max = c(0, 1),
    beta = c("beta_1"=1, "beta_2"=1),
    beta.min = c(1, 1),
    beta.max = c(1, 1),
    gamma = c("gamma_1"=0.5, "gamma_2"=0.5),
    gamma.min = c(0.5, 0.5),
    gamma.max = c(0.5, 0.5)
 )

RFoptions(cores=2)  ## see package RandomFieldsUtils
print(adoption(Goldenberg, join_models=FALSE, buttons2right=TRUE,
               gui=interactive()))
# }

Run the code above in your browser using DataLab