#Install the github package
#devtools::install_github("kserkcho/SCEM")
library(SCEM)
#>
#> Attaching package: 'SCEM'
#> The following object is masked from 'package:stats':
#>
#> kernel
data(armenia)
<- armenia
oxy = split(oxy,f = oxy$ID) armenia
= SCEM(armenia,bandwidth = -0.33)
results = makeFits(armenia,method ="OLS")
cosine rownames(cosine) = 1:nrow(cosine)
$results$Cosine = cosine$birth
results= abs(results$results$Cosine - results$results$Season)
dif $results$Difference = apply(cbind(dif,(1-dif)),1,min)
results$results$R = cosine$Pearson
results= results$results[order(results$results$Cluster),]
rrr.a
# Storing the birth seasonality estimates from two methods
= results$results$Cosine
c.armenia = results$results$Season s.armenia
# Plotting the estimates of birth seasonality from the two methods
plot(c.armenia,s.armenia,xlim = c(0,1),ylim = c(0,1),pch = 19)
abline(0,1)
legend("topleft","Tsaghkahovit")
title(xlab = "estimated birth seasonality from cosine method",ylab = "estimated birth seasonality from SCEM",outer = TRUE, line = 2)
# Plotting the graphs of the clusters for Armenia data
= max(results$results$Cluster)
gnum = par(mar=c(1.5,1.5,1,1), mfrow=c(2,2),oma = c(4, 4, 1, 1))
oldpar for(i in 1:gnum){
if(length(results$groups[[i]])>1){
= as.character()
cc plot(c(0,40),c(-14,0),type = "n",axes = T,xlab = "",ylab = "",xlim = rev(range(c(0,40))))
for(j in 1:length(results$groups[[i]])){
= armenia[[results$groups[[i]][j]]]
tt lines(tt$distance,tt$oxygen,lty = j)
= c(cc,paste(tt$lab[1],tt$ID[1],sep = ""))
cc
}legend("topleft",legend = cc,lty = c(1:j),lwd = 2)
}
}title(xlab = "distance from CEJ (mm)",ylab = expression(delta^18*O[VPDB]*' (per mil)'),outer = TRUE, line = 2)
par(oldpar)
# Fix the initial values of amplitude and intercept
= seq(1,10,by=0.5)
amp = seq(-25,0,by=0.5)
int
# Find the estimate of birth seasonality, period, delay and the R^2 for all cases
= array(0,dim = c(length(amp),length(int),length(armenia)))
cosfit.birth = array(0,dim = c(length(amp),length(int),length(armenia)))
cosfit.period = array(0,dim = c(length(amp),length(int),length(armenia)))
cosfit.delay = array(0,dim = c(length(amp),length(int),length(armenia)))
cosfit.R for (i in 1:length(amp)){
for (j in 1:length(int)){
= makeFits(armenia,amp[i],int[j],method="initial")
dd = dd$birth
cosfit.birth[i,j,] = dd$X
cosfit.period[i,j,] = dd$x0
cosfit.delay[i,j,] = dd$Pearson
cosfit.R[i,j,]
}
}= numeric(length(armenia))
birth.means = numeric(length(armenia))
birth.var for (i in 1:length(armenia)){
= mean(c(cosfit.birth[,,i]))
birth.means[i] = var(c(cosfit.birth[,,i]))
birth.var[i]
}
# Plots of the model fits to show the sensitivity to initial conditions
= par(mfrow = c(1,2),mar = c(4,4,1,1))
oldpar2plot(birth.means,sqrt(birth.var),xlab = "mean of birth season",ylab = "standard deviation",pch = 19)
hist(c(cosfit.R^2),25,freq = F,xlab = "R-squared value",main = "")
par(oldpar2)