# 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)
# }
Run the code above in your browser using DataLab