if (FALSE) {
library(phenology)
# Read a file with data
data(Gratiot)
# Generate a formatted list nammed data_Gratiot
refdate <- as.Date("2001-01-01")
data_Gratiot <- add_phenology(Gratiot, name="Complete",
reference=refdate, 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)
#############################################
# Example of use of include0 and datepeakfor0
#############################################
# Let create a times series with only 0
data0 <- data.frame(Date=c("11/3/2015", "12/3/2015", "13/3/2015-18/3/2015", "25/3/2015"),
Number=c(0, 0, 0, 0),
Beach=rep("Site", 4), stringsAsFactors=FALSE)
# Here I don't include beach with no observation: error message
try1 <- add_phenology(data0, format="%d/%m/%Y", month_ref=1, include0=FALSE)
# Here I include timeseries with no observation
try1 <- add_phenology(data0, format="%d/%m/%Y", month_ref=1, include0=TRUE, datepeakfor0=100)
try1 <- add_phenology(data0, format="%d/%m/%Y", month_ref=1, include0=TRUE, datepeakfor0=73)
try1 <- add_phenology(data0, format="%d/%m/%Y", month_ref=1, include0=TRUE, datepeakfor0=70)
# It can be done in two steps
try1 <- add_phenology(data0, format="%d/%m/%Y", month_ref=1, include0=TRUE)
try2 <- add_phenology(previous=try1, include0=TRUE, datepeakfor0=100)
# Here I include the series without observation
try1 <- add_phenology(add=data0, format="%d/%m/%Y", month_ref=1,
include0=TRUE, expandRange0Observation=TRUE)
##############################################################################
# Example of A and S parameters to say that only half of a beach was monitored
##############################################################################
refdate <- as.Date("2001-01-01")
data_Gratiot <- add_phenology(Gratiot, name="Complete1",
reference=refdate, format="%d/%m/%Y")
S.default = 10
# Let Complete1 be of length 2 and Complete0.5 be of length 1
length.Complete1 <- 2
length.Complete0.5 <- 1
A.default = log(1/(length.Complete0.5/length.Complete1)-1)/(-S.default*4)
# For day 0, the detection probability is
1/(1+exp(-(4*S.default)*(A.default-0)))
data_Gratiot <- add_phenology(previous=data_Gratiot,
add=Gratiot,
name="Complete0.5",
A.default = A.default,
S.default = S.default,
reference=refdate,
format="%d/%m/%Y")
parg <- c(par_init(data_Gratiot, fixed.parameters=c(Min=0, Flat=0)), PMin=0.1)
result_Gratiot <- fit_phenology(data=data_Gratiot, fitted.parameters=parg,
fixed.parameters=c(Flat=0))
result_Gratiot$par
# it shows that Max_Complete1 is half of Max_Complete0.5; all is ok
summary(result_Gratiot)$synthesis
}
Run the code above in your browser using DataLab