#Simulate some fossil ranges with simFossilTaxa
set.seed(444)
taxa <- simFossilTaxa(p=0.1,q=0.1,nruns=1,mintaxa=20,maxtaxa=30,maxtime=1000,maxExtant=0)
#simulate a fossil record with imperfect sampling with sampleRanges
rangesCont <- sampleRanges(taxa,r=0.5)
#Now let's use binTimeData to bin in intervals of 1 time unit
rangesDisc <- binTimeData(rangesCont,int.length=1)
#now, get an estimate of the sampling rate (we set it to 0.5 above)
#for discrete data we can estimate the sampling probability per interval (R)
#i.e. this is not the same thing as the instantaneous sampling rate (r)
#can use sRate2sProb to see what we would expect
sRate2sProb(r=0.5)
#expect R = ~0.39
#now we can use maximum likelihood to taxon ranges to get sampling probability
SPres1 <- getSampProbDisc(rangesDisc)
print(SPres1) #let's look at the results
sProb<-SPres1[[2]][2]
print(sProb)
#est. R = ~0.42; not too off what we would expect!
#for the rate calibrated timescaling methods, we want an estimate of the instantaneous samp rate
#we can use sProb2sRate to get the rate. We will also need to also tell it the int.length
sRate <- sProb2sRate(sProb,int.length=1)
print(sRate)
#estimates that r=0.54... Not bad!
#Note: for real data, you may need to use an average int.length (no constant length)
#this data was simulated under homogenous sampling probabilities, extinction rates
#if we fit a model with random groups and allow for multiple timebins
#AIC should be higher (less informative models)
randomgroup <- sample(1:2,nrow(rangesDisc[[2]]),replace=TRUE)
SPres2 <- getSampProbDisc(rangesDisc,grp1=randomgroup)
SPres3 <- getSampProbDisc(rangesDisc,n_tbins=2)
print(c(SPres1$AICc,SPres2$AICc,SPres3$AICc))
#and we can see the most simple model has the lowest AICc (most informative model)
#testing temporal change in sampling probabiluty
set.seed(444)
taxa <- simFossilTaxa(p=0.1,q=0.1,nruns=1,mintaxa=100,maxtaxa=125,maxtime=1000,maxExtant=0,
plot=T)
#let's see what the 'true' diversity curve looks like in this case
#simulate two sets of ranges at r=0.7 and r=0.1
rangesCont <- sampleRanges(taxa,r=1.1)
rangesCont2 <- sampleRanges(taxa,r=0.2)
#now make it so that taxa which originated after 850 have r=0.1
rangesCont[taxa[,3]<850,] <- rangesCont2[taxa[,3]<850,]
rangesDisc <- binTimeData(rangesCont)
#lets plot the diversity curve
taxicDivDisc(rangesDisc)
SPres1 <- getSampProbDisc(rangesDisc)
SPres2 <- getSampProbDisc(rangesDisc,n_tbins=2)
#compare the AICc of the models
print(c(SPres1$AICc,SPres2$AICc)) #model 2 looks pretty good
#when does it find the break in time intervals?
print(rangesDisc[[1]][SPres2$interval.boundaries[2],1])
#not so great: estimates 940, not 850
#but look at the diversity curve: most richness in bin 1 is before 940
#might have found the right break time otherwise...
#the parameter values it found are less great. Finds variation in q
Run the code above in your browser using DataLab