example: Example of using the inference package

Description Usage Details References Examples

View source: R/example.R

Description

This is just an example on how to use this package to generate the distribution of the population count.

Usage

1

Details

This is a script that shows how to use the functions of this package to compute the distribution of the initial target population count, the distribution of the population count at successive time instants and the origin-destination matrix.

References

https://github.com/MobilePhoneESSnetBigData

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
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# set the folder where the necessary input files are stored and the prefix of the input file names.
path      <- 'extdata'

prefix <- 'postLocDevice'

# compute the deduplication factors
dpFileName <- system.file(path, 'duplicity.csv', package = 'inference')
rgFileName <- system.file(path, 'regions.csv', package = 'inference')

omega_r <- computeDeduplicationFactors(dpFileName, rgFileName, prefix,
system.file(path, package = 'inference'))

# reads the number of individuals detected by network
nFileName <- system.file(path, 'nnet.csv', package = 'inference')
nnet <- readNnetInitial(nFileName)

# compute the parameters of the distribution
pRFileName <- system.file(path, 'pop_reg.csv', package = 'inference')
pRateFileName <- system.file(path, 'pnt_rate.csv', package = 'inference')
grFileName <- system.file(path, 'grid.csv', package = 'inference')
params <- computeDistrParams(omega_r, pRFileName, pRateFileName, rgFileName, grFileName)

# A. Compute the population count distribution at t0
# compute the population count distribution using the Beta Negative Binomial distribution
n_bnb <- computeInitialPopulation(nnet, params, popDistr = 'BetaNegBin', rndVal = TRUE)

# display results
n_bnb$stats
head(n_bnb$rnd_values)


# compute the population count distribution using the Negative Binomial distribution
n_nb <- computeInitialPopulation(nnet, params, popDistr = 'NegBin', rndVal = TRUE)

# display results
n_nb$stats
head(n_nb$rnd_values)


# compute the population count distribution using the state process Negative Binomial distribution
n_stnb <- computeInitialPopulation(nnet, params, popDistr= 'STNegBin', rndVal = TRUE)

# display results
n_stnb$stats
head(n_stnb$rnd_values)


# B. compute the population count distribution at time instants t > t0
# first set the name of the file with the population moving from one region
# to another (output of the aggregation package)
nnetODFile <- system.file(path, 'nnetOD.zip', package = 'inference')

# 1.Using the Beta Negative Binomial distribution
nt_bnb <- computePopulationT(n_bnb$rnd_values, nnetODFile, rndVal = TRUE)


# display results
# first, select a random time instant
times <- names(nt_bnb)
t <- sample(1:length(times), size = 1)
t
nt_bnb[[t]]$stats
head(nt_bnb[[t]]$rnd_values)


# 2.Using the Negative Binomial distribution
nt_nb <- computePopulationT(n_nb$rnd_values, nnetODFile, rndVal = TRUE)

# display results
# first, select a random time instant
times <- names(nt_nb)
t <- sample(1:length(times), size = 1)
t
nt_nb[[t]]$stats
head(nt_nb[[t]]$rnd_values)
# 3.Using the state process Negative Binomial distribution
nt_stnb <- computePopulationT(n_stnb$rnd_values, nnetODFile, rndVal = TRUE)

# display results
# first, select a random time instant
times <- names(nt_stnb)
t <- sample(1:length(times), size = 1)
t
nt_stnb[[t]]$stats
head(nt_stnb[[t]]$rnd_values)

# C. compute the origin-destination matrices for all pairs of time instants time_from-time_to
# first set the name of the file with the population moving from one region
# to another (output of the aggregation package)
nnetODFile <- system.file(path, 'nnetOD.zip', package = 'inference')

# 1.Using the Beta Negative Binomial distribution
OD_bnb <- computePopulationOD(n_bnb$rnd_values, nnetODFile, rndVal = TRUE)

# display results
time_pairs <- names(OD_bnb)
# first, select a random time instants pair
i <- sample(1:length(time_pairs), size = 1)
time_pairs[i]
OD_bnb[[i]]$stats
head(OD_bnb[[i]]$rnd_values)

# 2.Using the Negative Binomial distribution
OD_nb <- computePopulationOD(n_nb$rnd_values, nnetODFile, rndVal = TRUE)

# display results
time_pairs <- names(OD_nb)
# first, select a random time instants pair
i <- sample(1:length(time_pairs), size = 1)
time_pairs[i]
OD_nb[[i]]$stats
head(OD_nb[[i]]$rnd_values)

# 3.Using the  state process Negative Binomial distribution
OD_stnb <- computePopulationOD(n_stnb$rnd_values, nnetODFile, rndVal = TRUE)

# display results
time_pairs <- names(OD_stnb)
# first, select a random time instants pair
i <- sample(1:length(time_pairs), size = 1)
time_pairs[i]
OD_stnb[[i]]$stats
head(OD_stnb[[i]]$rnd_values)

bogdanoancea/inference documentation built on Nov. 28, 2020, 9:20 p.m.