Plot_dyn: Visualisation of the dynamic of the epidemic

Description Usage Arguments Details Value See Also Examples

View source: R/contact_plot.R

Description

Visualisation of the process.

Usage

1
2
3
Plot_dyn(rast, param, grid_lines, pop_grid, age_level = c(1, 1),
  age_dist = c(1, 0), m_start = 1, t_max = 118,
  t_intervention = 365, EI_model = 3, k, kern_model = 4)

Arguments

rast

The raser object provided.

param

Indicating a data frame containing a vector of parameters including:

epsion

The primary infection rate. See func_time_beta

beta_0

Baseline or average transmission rate. See func_time_beta

beta_1

Amplitude of the seasonality. See func_time_beta

alpha1,alpha2

The dispersal kernel parameters.

mu_lat,var_lat

mean and variance of the latent period. See E_to_I for details.

t0

Time at which the primary source became active

.

omega

Period of the forcing. See func_time_beta

gama

The mean proportion of short range dispersal events.

.

pop_grid

Population density of the grid a case resides. This is filled from bottom to top, then left to right.

age_level

Vectors of age level and the propportion of each age group respectively. See details.

age_dist

Vectors of age level and the propportion of each age group respectively. See details.

m_start

The size of initial cases. Default is 1.

t_max

Final observation time.

t_intervention

Start of the intervention if any.

EI_model

Take integer values to specify the type of model used for the latent period. See E_to_I

k

Indicate the rank of the simulation

kern_model

Take integer values to specify the type of dispersal kernel used. See Samp_dis

Details

Plot_dyn Provide a basic mode of visualising the spread of the epidemic

Value

A raster plot with points representing infections premisses:

See Also

raster

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
data(bbtv)
attach(bbtv)
Dat<- bbtv[,c("longitude","latitude","BBTV","inspectiondate","leavesinfected","treatmentdate","location")]
Dat1<-subset(Dat,Dat$latitude> -27.4698 & Dat$BBTV%in%c("P&I","P", "NI") & difftime(as.Date(Dat$inspectiondate), as.Date("2010/01/01"), unit="days")>=0)  # data up in queensland
Dat1$treatmentdate[is.na(Dat1$treatmentdate)]<- Dat1$inspectiondate[is.na(Dat1$treatmentdate)]
Dat1$detection<-as.numeric(difftime(as.Date(Dat1$inspectiondate), as.Date("2010/01/01"), unit="days"))
Dat1$removal<-as.numeric(difftime(as.Date(Dat1$treatmentdate), as.Date("2010/01/01"), unit="days"))
Dat1$removal[which(Dat1$removal<0)]<- Dat1$detection[which(Dat1$removal<0)]
Datt<-Dat1[,c("longitude","latitude","BBTV","leavesinfected","detection","removal")]
Datt=Datt[with(Datt,order(Datt$detection)),]


# Australian reference system
sp::coordinates(Datt) <- c("longitude", "latitude")
sp::proj4string(Datt) <- sp::CRS("+init=epsg:4326")
australianCRS <- sp::CRS("+init=epsg:3577")

pointsinaustraliangrid = sp::spTransform(Datt,australianCRS)

# Raster
rast <- raster::raster()
raster::extent(rast) <- raster::extent(pointsinaustraliangrid) # Set same extent

raster::res(rast)=5000 # Set resolution


dif=(xmax(pointsinaustraliangrid)-xmin(pointsinaustraliangrid))/size
cei= ceiling(dif)

if(cei!=dif){
  if(xmax(rast)!=xmax(pointsinaustraliangrid)){
    xmax(rast)<- xmin(rast) + size*cei
  }
  if(xmin(rast)!=xmin(pointsinaustraliangrid)){
    xmin(rast)<- xmax(rast) - size*cei
  }

}

# Adding row at the top or bottom of the grid if raster leaves points out

dif1=(ymax(pointsinaustraliangrid)-ymin(pointsinaustraliangrid))/size
cei1= ceiling(dif1)

if(cei1!=dif1){
  if(ymax(rast)!=ymax(pointsinaustraliangrid)){
    ymax(rast)<- ymin(rast) + size*cei1
  }
  if(ymin(rast)!=ymin(pointsinaustraliangrid)){
    ymin(rast)<- ymax(rast) - size*cei1
  }

}
# And then ... rasterize it! This creates a grid version
# of your points using the cells of rast,

# And then ... rasterize it! This creates a grid version
# of your points using the cells of rast,

rast2 <- raster::rasterize(pointsinaustraliangrid, rast, 1, fun=sum)

# Extract infos on the grid


n_row_grid=nrow_grid=raster::nrow(rast)
n_col_grid=ncol_grid=raster::ncol(rast)
grid_size=raster::res(rast)[1]     # Resolution

n_line=(nrow_grid+1) + (ncol_grid +1)  # Number of grid  lines

x_min=raster::xmin(rast)  # min max of the bounding box
x_max=raster::xmax(rast)

y_min=raster::ymin(rast)
y_max=raster::ymax(rast)

da=as.data.frame(pointsinaustraliangrid)

pop_per_grid=raster::values(rast2)
pop_per_grid[is.na(pop_per_grid)]=0
mat=matrix(pop_per_grid,nrow = nrow_grid, byrow = TRUE)
pop_grid=apply(mat,2,rev)     # population per grid

# Structure of the grid
x=seq(x_min,x_max,grid_size)
y=seq(y_min,y_max,grid_size)

grid_lines=array(0,c(n_line,6))
for(i in 1:n_line){
  if(i<=(nrow_grid +1)){
    grid_lines[i,]=c(i,1,x[1],y[i],x[length(x)],y[i])
  }
  else{
    grid_lines[i,]=c(i,2,x[i-length(y)],y[1],x[i-length(y)],y[length(y)])
  }
}

grid_lines=as.data.frame(grid_lines)
colnames(grid_lines)<- c("indx","orient_line","coor_x_1","coor_y_1","coor_x_2","coor_y_2")
# Simulation with exponential kernel
alpha<- 30; beta<- 0.012; epsilon<- 0.02; omega<- 0.12; mu_lat<- 30; var_lat<- 20; t0<- 0; c<- 20;
param=data.frame(alpha1=alpha, alpha2=alpha, beta=beta, epsilon=epsilon, omega=omega, mu_lat=mu_lat, var_lat=var_lat, t0=t0, c=c)
Plot_dyn(rast2,param,grid_lines, pop_grid,k=1)

holaanna/contactsimulator documentation built on Dec. 2, 2019, 2:39 a.m.