Skip to content

Commit 98a1bcb

Browse files
authored
Merge pull request #13 from dd-harp/dev
fixing little things
2 parents d9ec07e + ce2c5ec commit 98a1bcb

37 files changed

+406
-238
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
.Rhistory
33
.RData
44
.Ruserdata
5-
.rda
65
docs

NAMESPACE

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ S3method(make_movie,BQ)
2626
S3method(make_movie,BQS)
2727
S3method(make_tiles,BQ)
2828
S3method(make_tiles,BQS)
29-
S3method(plot_Psi,BQ)
30-
S3method(plot_Psi,BQS)
29+
S3method(plot_all_Psi,BQ)
30+
S3method(plot_all_Psi,BQS)
3131
S3method(plot_points,BQ)
3232
S3method(plot_points,BQS)
3333
S3method(save_states_L,basicL)
@@ -89,7 +89,7 @@ export(make_Psi_BQS)
8989
export(make_Psi_xx)
9090
export(make_Psi_xy)
9191
export(make_all_graphs)
92-
export(make_all_graphs_common)
92+
export(make_common_graphs)
9393
export(make_convex_hull_i)
9494
export(make_convex_hulls)
9595
export(make_demography_BQ)
@@ -109,9 +109,6 @@ export(plot_Kbb)
109109
export(plot_Kbq)
110110
export(plot_Kqb)
111111
export(plot_Kqq)
112-
export(plot_Psi)
113-
export(plot_Psi_BQSmod)
114-
export(plot_Psi_BQmod)
115112
export(plot_Psi_bb)
116113
export(plot_Psi_bq)
117114
export(plot_Psi_bs)
@@ -121,6 +118,9 @@ export(plot_Psi_qs)
121118
export(plot_Psi_sb)
122119
export(plot_Psi_sq)
123120
export(plot_Psi_ss)
121+
export(plot_all_Psi)
122+
export(plot_all_Psi_BQ)
123+
export(plot_all_Psi_BQS)
124124
export(plot_convex_hulls)
125125
export(plot_dispersal_G)
126126
export(plot_dispersal_GG)

R/Psi_matrices.R

+14-13
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ make_Psi_xx = function(S, kF=make_kF_exp(), w=1, stay=0){
5353
#'
5454
#' @return the model, a compound [list]
5555
#' @export
56-
plot_Psi = function(model, max_pt_sz=2,
56+
plot_all_Psi = function(model, max_pt_sz=2,
5757
min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){
58-
UseMethod("plot_Psi", model)
58+
UseMethod("plot_all_Psi", model$Mpar)
5959
}
6060

6161
#' Visualize the one-bout dispersal matrices for a BQ model
@@ -69,11 +69,12 @@ plot_Psi = function(model, max_pt_sz=2,
6969
#'
7070
#' @return the model, a compound [list]
7171
#' @export
72-
plot_Psi.BQ = function(model, max_pt_sz=2,
72+
plot_all_Psi.BQ = function(model, max_pt_sz=2,
7373
min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){
74-
with(model,{plot_Psi_BQmod(b,q,Psi_bb, Psi_qb, Psi_bq, Psi_qq,
74+
with(model,with(Mpar,{plot_Psi_BQ(b,q,Psi_bb, Psi_qb, Psi_bq, Psi_qq,
7575
max_pt_sz=max_pt_sz, min_edge_frac=min_edge_frac,
76-
r=r, arw_lng=arw_lng, lwd=lwd)})}
76+
r=r, arw_lng=arw_lng, lwd=lwd)}))}
77+
7778

7879

7980
#' Visualize the one-bout dispersal matrices for a BQ model
@@ -92,7 +93,7 @@ plot_Psi.BQ = function(model, max_pt_sz=2,
9293
#'
9394
#' @return no visible return value
9495
#' @export
95-
plot_Psi_BQmod = function(b, q,
96+
plot_all_Psi_BQ = function(b, q,
9697
Psi_bb, Psi_qb,
9798
Psi_bq, Psi_qq,
9899
max_pt_sz=2, min_edge_frac = 0.01,
@@ -118,15 +119,15 @@ plot_Psi_BQmod = function(b, q,
118119
#'
119120
#' @return the model, a compound [list]
120121
#' @export
121-
plot_Psi.BQS = function(model,max_pt_sz=2,
122+
plot_all_Psi.BQS = function(model,max_pt_sz=2,
122123
min_edge_frac = 0.01, r=.01, arw_lng=0.05, lwd=2){
123-
with(model,{plot_Psi_BQSmod(b,q,s,
124+
with(model,with(Mpar,{plot_Psi_BQS(b,q,s,
124125
Psi_bb, Psi_qb, Psi_sb,
125126
Psi_bq, Psi_qq, Psi_sq,
126127
Psi_bs, Psi_qs, Psi_ss,
127128
max_pt_sz=max_pt_sz, min_edge_frac=min_edge_frac,
128129
r=r, arw_lng=arw_lng, lwd=lwd)
129-
})}
130+
}))}
130131

131132

132133
#' Visualize the one-bout dispersal matrices for a BQS model
@@ -151,7 +152,7 @@ plot_Psi.BQS = function(model,max_pt_sz=2,
151152
#'
152153
#' @return no visible return value
153154
#' @export
154-
plot_Psi_BQSmod = function(b,q,s,
155+
plot_all_Psi_BQS = function(b,q,s,
155156
Psi_bb, Psi_qb, Psi_sb,
156157
Psi_bq, Psi_qq, Psi_sq,
157158
Psi_bs, Psi_qs, Psi_ss,
@@ -186,7 +187,7 @@ plot_Psi_BQSmod = function(b,q,s,
186187
#' @export
187188
plot_Psi_bb = function(b, q, Psi_bb,
188189
max_pt_sz=2, min_edge_frac = 0.01,
189-
r=.01, arw_lng=0.05, lwd=2){
190+
r=.02, arw_lng=0.05, lwd=2){
190191

191192
## b to b
192193
frame_bq(b,q, mtl=expression(Psi[b %<-% b]))
@@ -213,9 +214,9 @@ plot_Psi_bq = function(b,q, Psi_bq,
213214
max_pt_sz=2, min_edge_frac = 0.01,
214215
r=.01, arw_lng=0.05, lwd=2){
215216
frame_bq(b, q, mtl = expression(Psi * scriptstyle(b %<-% q)))
216-
add_points_q(q, max_pt_sz = 0.6)
217217
add_arrows_xy(q, b, Psi_bq, min_edge_frac=min_edge_frac,
218218
r=r, arw_lng=arw_lng, lwd=lwd, clr="tomato")
219+
add_points_q(q, max_pt_sz = 0.3)
219220
add_points_b(b, rowSums(Psi_bq), max_pt_sz = max_pt_sz)
220221
return(invisible())
221222
}
@@ -264,9 +265,9 @@ plot_Psi_qb = function(b, q, Psi_qb,
264265

265266
## b to q
266267
frame_bq(b, q, mtl = expression(Psi*scriptstyle(q %<-% b)))
267-
add_points_b(b, max_pt_sz=0.6)
268268
add_arrows_xy(b, q, Psi_qb, min_edge_frac=min_edge_frac,
269269
r=r, arw_lng=arw_lng, lwd=lwd, clr = "skyblue")
270+
add_points_b(b, max_pt_sz=0.3)
270271
add_points_q(q, rowSums(Psi_qb), max_pt_sz=max_pt_sz)
271272
return(invisible())
272273
}

R/adult-BQS.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ setup_dispersal_BQS = function(model, opts = list(),
126126
model$Mpar$setup$ws = ws
127127
model$Mpar$setup$stayB=stayB
128128
model$Mpar$setup$stayQ=stayQ
129-
model$Ppar$setup$stayS=stayS
129+
model$Mpar$setup$stayS=stayS
130130
model = make_Psi_BQS(model)
131131
return(model)
132132
})})
@@ -214,7 +214,7 @@ make_demography_BQS = function(model){
214214
model$Mpar$Msq = Psi_sq %*% diag(pQ*(sigf*psiQ + sigq*(1-psiQ)), nq)
215215
# from s
216216
model$Mpar$Mbs = Psi_bs %*% diag(pS*psiS, ns)
217-
model$Mpar$Mqs = 0*t(Msq)
217+
model$Mpar$Mqs = 0*t(model$Mpar$Msq)
218218
model$Mpar$Mss = Psi_ss %*% diag(pS*(1-psiS), ns)
219219
# recently emerged adults
220220
model$Mpar$Mbl = Psi_bq %*% diag(pQ*(1-sigL), nq)

R/graphs.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ make_graph_obj = function(M, type ="b", tag = ""){
3636
#'
3737
#' @returns a ramp.micro model object
3838
#' @export
39-
make_all_graphs_common = function(model){with(model,{
39+
make_common_graphs = function(model){with(model,{
4040
model$graphs <- list()
4141
model$graphs$Kbb_net <- make_graph_obj(KGV$Kbb, "b", expression(K*scriptstyle(b%->%b)))
4242
model$graphs$Kqq_net <- make_graph_obj(KGV$Kqq, "q", expression(K*scriptstyle(q%->%q)))
@@ -70,7 +70,7 @@ make_all_graphs = function(model){UseMethod("make_all_graphs",model)}
7070
#' @returns a ramp.micro model object
7171
#' @export
7272
make_all_graphs.BQ = function(model){
73-
model = make_all_graphs_common(model)
73+
model = make_common_graphs(model)
7474
BQ <- with(model$steady$M, diag(as.vector(c(B, Q))))
7575
bigMM <- model$Mpar$bigM %*% BQ
7676
model$Mpar$bigMM <- bigMM
@@ -88,7 +88,7 @@ make_all_graphs.BQ = function(model){
8888
#' @returns a ramp.micro model object
8989
#' @export
9090
make_all_graphs.BQS = function(model){
91-
model = make_all_graphs_common(model)
91+
model = make_common_graphs(model)
9292
BQS <- with(model$steady$M, diag(as.vector(c(B, Q, S))))
9393
bigMM <- model$Mpar$bigM %*% BQS
9494
model$Mpar$bigMM <- bigMM

R/kernels.R

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11

2-
#' Make an exponential function to weight points by distance
2+
#' Make an exponential function for weight by distance
3+
#'
4+
#' @description This returns a function of the form
5+
#' \deqn{F_w (d, \omega=1) = \omega_j e^{-k \left( \frac{d_{i,j}}{s}\right)^\gamma}}
6+
#' where \eqn{s} and \eqn{\gamma} are shape parameters, \eqn{k} is the rate
7+
#' parameter, and \eqn{\omega} is a weight.
8+
#'
9+
#' In effect, \eqn{s} is the location of a shoulder, and for \eqn{\gamma>1}, the decay is
10+
#' slower for \eqn{d<s}.
11+
#'
12+
#' The function returned accepts \eqn{\omega} as
13+
#' an optional argument so that it can be passed at the time of simulation.
14+
#'
15+
#' By default, the function returns scaled values -- the maximum is 1.
316
#'
417
#' @param k decay by distance
518
#' @param s a scale parameter
619
#' @param gamma a shape parameter
720
#'
821
#' @return a function
922
#' @export
23+
#' @examples
24+
#' kF1 = make_kF_exp(k=1, s=1, gamma=1.5)
25+
#' kF2 = make_kF_exp(k=2, s=0.1, gamma=2)
26+
#' dd = seq(0, 2, by = 0.01)
27+
#' plot(dd, kF1(dd), type = "l", ylab = "Weight", xlab = "Distance")
28+
#' lines(dd, kF2(dd))
1029
make_kF_exp = function(k=1, s=2, gamma=1){
1130
return(function(dd, w=1){
1231
wij = w*(exp(-k*(dd/s)^gamma))
@@ -32,15 +51,16 @@ make_kF_pwr = function(delta=1, s=1){
3251
#'
3352
#' @param p the weight on the power function
3453
#' @param k decay by distance
35-
#' @param s a scale parameter
54+
#' @param s1 a scale parameter
55+
#' @param s2 a scale parameter
3656
#' @param gamma a shape parameter
3757
#' @param delta the power on distance
3858
#'
3959
#' @return a function
4060
#' @export
41-
make_kF_mix = function(p=0.001, k=1, s=2, gamma=1, delta=1){
61+
make_kF_mix = function(p=0.001, k=1, s1=1, s2=1, gamma=1, delta=1){
4262
return(function(dd, w=1){
43-
wij = (1-p)*w*(exp(-k*(dd/s)^gamma)) + p*w/(dd+s)^delta
63+
wij = (1-p)*w*(exp(-k*(dd/s1)^gamma)) + p*w/(dd+s2)^delta
4464
wij/max(wij)
4565
})
4666
}

R/plot_points.R

+8-4
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ add_points_s = function(s, wts=1, pw=1, max_pt_sz=1, clr="olivedrab2"){
192192
#' @return invisible(NULL)
193193
#' @export
194194
add_points_bb = function(b, M, pw=1, max_pt_sz=2, colA="#cc444b66", colB="#cc444bCC"){
195-
add_points_b(b, as.vector(rowSums(M)), pw, max_pt_sz, colA)
195+
wts1 <- as.vector(rowSums(M))
196+
add_points_b(b, wts1, pw, max_pt_sz, colA)
196197
diag(M) <- 0
197-
add_points_b(b, as.vector(rowSums(M)), pw, max_pt_sz, colB)
198+
wts2 <- as.vector(rowSums(M))
199+
add_points_b(b, wts2, pw, max_pt_sz*max(wts2)/max(wts1), colB)
198200
return(invisible())
199201
}
200202

@@ -210,9 +212,11 @@ add_points_bb = function(b, M, pw=1, max_pt_sz=2, colA="#cc444b66", colB="#cc444
210212
#' @return invisible(NULL)
211213
#' @export
212214
add_points_qq = function(q, M, pw=1, max_pt_sz=2, colA="skyblue", colB="skyblue3"){
213-
add_points_q(q, as.vector(rowSums(M)), pw, max_pt_sz, colA)
215+
wts1 <- as.vector(rowSums(M))
216+
add_points_q(q, wts1, pw, max_pt_sz, colA)
214217
diag(M) <- 0
215-
add_points_q(q, as.vector(rowSums(M)), pw, max_pt_sz, colB)
218+
wts2 <- as.vector(rowSums(M))
219+
add_points_q(q, wts2, pw, max_pt_sz*max(wts2)/max(wts1), colB)
216220
return(invisible())
217221
}
218222

R/setup_model.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#' @param kFs a kernel shape for sugar site searching
1010
#' @param Mname the adult model name
1111
#' @param Lname the aquatic model name
12+
#' @param dispersal_opts a [list] to
1213
#' @param bionomic_opts a [list] to overwrite defaults
1314
#' @param aquatic_opts a [list] to overwrite defaults
1415
#' @param M0_opts options to overwrite defaults
@@ -17,8 +18,10 @@
1718
#'
1819
#' @return a [list] defining a BQ-class adult model
1920
#' @export
20-
setup_model = function(b, q, s=c(), kFb, kFq, kFs = NULL,
21+
setup_model = function(b, q, s=c(),
22+
kFb=NULL, kFq=NULL, kFs=NULL,
2123
Mname="BQ", Lname="basicL",
24+
dispersal_opts = list(),
2225
bionomic_opts = list(),
2326
aquatic_opts = list(),
2427
M0_opts = list(),
@@ -35,7 +38,8 @@ setup_model = function(b, q, s=c(), kFb, kFq, kFs = NULL,
3538
model$nq = length(q[,1])
3639
if(!is.null(s)) model$ns = length(s[,1])
3740

38-
dispersal_opts = list(kFb=kFb, kFq=kFq)
41+
if(!is.null(kFb)) dispersal_opts$kFb = kFb
42+
if(!is.null(kFq)) dispersal_opts$kFq = kFq
3943
if(!is.null(kFs)) dispersal_opts$kFs = kFs
4044

4145
Mpar = list()

_pkgdown.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ navbar:
99
href: articles/point_sets.html
1010
- text: Kernels
1111
href: articles/kernels.html
12-
- text: Adult Mosquito Models
13-
href: articles/adult.html
14-
- text: Aquatic Mosquito Models
15-
href: articles/aquatic.html
16-
- text: Setting Up Models
12+
- text: Building a Model
1713
href: articles/models.html
1814
- text: Simulation
1915
href: articles/simulation.html
@@ -33,6 +29,10 @@ navbar:
3329
href: articles/dispersal.html
3430
- text: Communitites
3531
href: articles/community.html
32+
- text: Modularity - Adult Mosquito Models
33+
href: articles/adult.html
34+
- text: Modularity - Aquatic Mosquito Models
35+
href: articles/aquatic.html
3636
- text: Functions
3737
href: reference/index.html
3838
right:
@@ -281,18 +281,18 @@ reference:
281281
- plot_Psi_sb
282282
- plot_Psi_sq
283283
- plot_Psi_ss
284-
- plot_Psi
285-
- plot_Psi.BQ
286-
- plot_Psi_BQmod
287-
- plot_Psi.BQS
288-
- plot_Psi_BQSmod
284+
- plot_all_Psi
285+
- plot_all_Psi.BQ
286+
- plot_all_Psi_BQ
287+
- plot_all_Psi.BQS
288+
- plot_all_Psi_BQS
289289
- title: Graphs
290290
desc: |
291291
Make Graphs
292292
contents:
293293
- make_graph_obj
294+
- make_common_graphs
294295
- make_all_graphs
295-
- make_all_graphs_common
296296
- make_all_graphs.BQ
297297
- make_all_graphs.BQS
298298
- title: Metapopulations

man/make_all_graphs_common.Rd man/make_common_graphs.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/make_kF_exp.Rd

+20-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)