# NOT RUN {
library(phenology)
# Read a file with data
Gratiot <- read.delim("http://max2.ese.u-psud.fr/epc/conservation/BI/Complete.txt",
header=FALSE)
data(Gratiot)
# Generate a formatted list nammed data_Gratiot
data_Gratiot <- add_phenology(Gratiot, name="Complete",
reference=as.Date("2001-01-01"), format="%d/%m/%Y")
# Generate initial points for the optimisation
parg <- par_init(data_Gratiot, fixed.parameters=NULL)
# Run the optimisation
result_Gratiot <- fit_phenology(data=data_Gratiot,
fitted.parameters=parg, fixed.parameters=NULL)
data(result_Gratiot)
# Plot the phenology and get some stats
output <- plot(result_Gratiot)
# Use fit with co-factor
# First extract tide information for that place
td <- tide.info(year=2001, latitude=4.9167, longitude=-52.3333, tz="America/Cayenne")
td2 <- td[td$Tide=="High Tide", ]
td3 <- cbind(td2, Date=as.Date(td2$Date.Time))
td4 <- td3[(as.POSIXlt(td3$Date.Time)$hou<6) | (as.POSIXlt(td3$Date.Time)$hou>18), ]
with(td4, plot(Date.Time, Level, type="l"))
data_Gratiot$Complete$Date
td5 <- merge(data_Gratiot$Complete, td4, by.x="Date", by.y="Date")
td6 <- td5[, c("Date", "Level")]
parg <- par_init(data_Gratiot, fixed.parameters=NULL, add.cofactors="Level")
result_Gratiot_CF <- fit_phenology(data=data_Gratiot,
fitted.parameters=parg, fixed.parameters=NULL, cofactors=td6,
add.cofactors="Level")
compare_AIC(WithoutCF=result_Gratiot, WithCF=result_Gratiot_CF)
plot(result_Gratiot_CF)
# Example with two series fitted with different peaks but same Length of season
Gratiot2 <- Gratiot
Gratiot2[, 2] <- floor(Gratiot2[, 2]*runif(n=nrow(Gratiot2)))
data_Gratiot <- add_phenology(Gratiot, name="Complete",
reference=as.Date("2001-01-01"), format="%d/%m/%Y")
data_Gratiot <- add_phenology(Gratiot2, name="Complete2",
reference=as.Date("2001-01-01"),
format="%d/%m/%Y", previous=data_Gratiot)
pfixed=c(Min=0)
p <- par_init(data_Gratiot, fixed.parameters = pfixed)
p <- c(p, Peak_Complete=175, Peak_Complete2=175)
p <- p[-4]
p <- c(p, Length=90)
p <- p[-(3:4)]
result_Gratiot <- fit_phenology(data=data_Gratiot, fitted.parameters=p,
fixed.parameters=pfixed)
# An example with bimodality
g <- Gratiot
g[30:60, 2] <- sample(10:20, 31, replace = TRUE)
data_g <- add_phenology(g, name="Complete", reference=as.Date("2001-01-01"),
format="%d/%m/%Y")
parg <- c('Max.1_Complete' = 5.6344636692341856,
'MinB.1_Complete' = 0.15488810581002324,
'MinE.1_Complete' = 0.2,
'LengthB.1' = 22.366647176407636,
'Peak.1' = 47.902473939250036,
'LengthE.1' = 17.828495918533015,
'Max.2_Complete' = 33.053364083447434,
'MinE.2_Complete' = 0.42438173496989717,
'LengthB.2' = 96.651564706802702,
'Peak.2' = 175.3451874571835,
'LengthE.2' = 62.481968743789835,
'Theta' = 3.6423908093342572)
pfixed <- c('MinB.2_Complete' = 0,
'Flat.1' = 0,
'Flat.2' = 0)
result_g <- fit_phenology(data=data_g, fitted.parameters=p0, fixed.parameters=pfixed)
plot(result_g)
# }
Run the code above in your browser using DataLab