Description Usage Arguments Examples
The model considered is the full model which contains two parameters: the baseline rate parameter, and the social parameter. The hazard function used therefore contains two basic components: lambda0, the baseline rate parameter and the social parameter, s'. The hazard function for individual i at time t is expressed as: lambda(it) = lambda0 + (s'*Sum Aij_j)* z_j(t). In the hazard function, Sum Aij_j represents the sum of the interactions of individuals j on individual i. The term z_j(t) =1, if individual j has previously displayed the behaviour under study by time t, and zero otherwise. The example provided describes the analysis of the times shown in the figure above:
1 | mcmc(formatteddata, its, pilot_tuner1, pilot_tuner2, start1, start2)
|
formatteddata |
data formatted using the function FormatData |
its |
number of iterations |
pilot_tuner1 |
tuning parameter for the social effect |
pilot_tuner2 |
tuning parameter for the asocial effect |
start1 |
start value for the social parameter |
start2 |
start value for the asocial parameter |
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 | # library(calibrate)
# loading the x and y spatial coordinates to construct the spatially derived
#social network
data(Xx)
data(Yy)
X <- cbind(Xx,Yy)
plot(X[,1],X[,2],pch=16,cex=1,xlim=c(0,1),ylim=c(0,1),xlab="x",
ylab="y",main="",cex.axis=2,cex.lab=2)
areas = calculate.areas(X[,1], X[,2], rep(0.2,length(X[,1])), 1000)
spatialareas = areas
len = length(X[,1])
spatialnetwork = matrix(0,nrow=len,ncol=len)
for(i in 1:len){
for(j in i:len){
template = spatialareas[[i]][j]
spatialnetwork[i,j] = spatialnetwork[j,i] = template
#spatialareas[[i]]=NULL
}
}
# loading the times and ids to plot the diffusion times and run nbda
data(Times)
data(Ids)
numdiff = 10
plot_colors = colors()[c(12,28,31,32,34,37,41,47,59,62,146,176,258,
117,154,625,563,376,113,556)]
for(i in 1:numdiff){
a = (i-1) * (len)
b = a + (len)
startindex = a + 1
endindex = b
plot(Times[startindex:endindex,1],c(1:len),type="o",lwd=4,col=plot_colors[i],ylab="Solver index",
main="",xlab="Time(s)",yaxt='n',ylim=c(0,len),xlim=range(Times))
#textxy(c(1:len), Times[startindex:endindex,1], Ids[startindex:endindex,1],cex = .8,col="red")
par(new=TRUE)
}
par(new=TRUE)
plot( Times[1:len,1],c(1:len),type="o",lwd=4,col=plot_colors[1],ylab="",main="",xlab="",
ylim=c(0,len),xlim=range(Times))
Diffusions = rep(1,len)
for(i in 2:numdiff){
addon = rep(i,len)
Diffusions = c(Diffusions,addon)
}
Groups = rep(1,length(Times[,1]))
Events = c(1:length(Times[,1]))
space = rep(1,length(Times[,1]))
spatialnetwork = 1*spatialnetwork
shape = FormatData(Times[,1],spatialnetwork,Ids[,1],Groups,Diffusions,Events,spatialnetwork)
# running nbda to obtain posterior estimates of the social and
# baseline rate parameters
#ptm <- proc.time()
#mcmc(shape,10000,0.05,0.05,-3,-5)
#proc.time() - ptm
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.