fit_phenology: Fit the phenology parameters to timeseries of counts.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/fit_phenology.R

Description

Function of the package phenology to fit parameters to timeseries.
To fit data, the syntax is :
Result <- fit_phenology(data=dataset, fitted.parameters=par, fixed.parameters=pfixed, trace=1, zero_counts=TRUE, hessian=TRUE)
or if no parameter is fixed :
Result <- fit_phenology(data=dataset, fitted.parameters=par)
Add trace=1 [default] to have information on the fit progression or trace=0 to hide information on the fit progression.
zero_counts = c(TRUE, TRUE, FALSE) indicates whether the zeros have been recorded for each of these timeseries. Defaut is TRUE for all.
hessian = FALSE does not estimate Hessian matrix and SE of parameters.
If the parameter Theta is fixed to +Inf, a Poissonian model of daily nest distribution is implemented.
Special section about cofactors:
cofactors must be a data.frame with a column Date and a column for each cofactor
add.cofactors are the names of the column of parameter cofactors to use as a cofactor;
The model is then: parameter[add.cofactors] * cofactor[, add.cofactors]
If the name of the parameter is paste0(add.cofactors, "multi"), then the model is:
parameter[paste0(add.cofactors, "multi")] * cofactor[, add.cofactors] * (number of nests without cofactor)

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
fit_phenology(
  data = file.choose(),
  fitted.parameters = NULL,
  fixed.parameters = NULL,
  tol = 1e-06,
  zero_counts = TRUE,
  store.intermediate = FALSE,
  file.intermediate = "Intermediate.rda",
  parallel = TRUE,
  hessian = TRUE,
  silent = FALSE,
  growlnotify = TRUE,
  cofactors = NULL,
  add.cofactors = NULL,
  zero = 1e-09,
  lower = 0,
  upper = Inf,
  control = list(trace = 1, REPORT = 1, maxit = 1000),
  method = c("Nelder-Mead", "L-BFGS-B")
)

Arguments

data

A dataset generated by add_format

fitted.parameters

Set of parameters to be fitted

fixed.parameters

Set of fixed parameters

tol

Tolerance of recurrence for dSnbinom() used for convolution of negative binomial distribution

zero_counts

example c(TRUE, TRUE, FALSE) indicates whether the zeros have been recorded for each of these timeseries. Defaut is TRUE for all.

store.intermediate

TRUE or FALSE to save the intermediates

file.intermediate

Name of the file where to save the intermediates as a list

parallel

If FALSE, no parallel computing is done to evaluate likelihood

hessian

If FALSE does not estimate se of parameters

silent

If TRUE does not show any message

growlnotify

If FALSE, does not send growl notification (only in MacOSX)

cofactors

data.frame with a column Date and a column for each cofactor

add.cofactors

Names of the column of parameter cofactors to use as a cofactor

zero

If the theoretical nest number is under this value, this value wll be used

lower

Lower bound for each parameter

upper

Upper bound for each parameter

control

List for control parameters for optim

method

Method used by optim. Several can be setup.

Details

fit_phenology fits parameters to timeseries.

Value

Return a list of with data and result

Author(s)

Marc Girondot

See Also

Other Phenology model: AutoFitPhenology(), BE_to_LBLE(), Gratiot, LBLE_to_BE(), LBLE_to_L(), L_to_LBLE(), MarineTurtles_2002, MinBMinE_to_Min(), adapt_parameters(), add_SE(), add_phenology(), extract_result(), likelihood_phenology(), logLik.phenology(), map_Gratiot, map_phenology(), par_init(), phenology2fitRMU(), phenology_MHmcmc_p(), phenology_MHmcmc(), phenology(), plot.phenologymap(), plot.phenology(), plot_delta(), plot_phi(), print.phenologymap(), print.phenologyout(), print.phenology(), remove_site(), result_Gratiot1, result_Gratiot2, result_Gratiot_Flat, result_Gratiot_mcmc, result_Gratiot, summary.phenologymap(), summary.phenologyout(), summary.phenology()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
## Not run: 
library(phenology)
# Read a file with data
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)
# or
output <- summary(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")
# I keep only High tide level
td2 <- td[td$Tide=="High Tide", ]
# I get the date
td3 <- cbind(td2, Date=as.Date(td2$Date.Time))
td4 <- td3[(as.POSIXlt(td3$Date.Time)$hou<10) | (as.POSIXlt(td3$Date.Time)$hou>15), ]
td5 <- aggregate(x=td4[, c("Date", "Date.Time", "Level")], 
                 by=list(Date=td4[, "Date"]), FUN=max)[, 2:4]
with(td5, plot(Date.Time, Level, type="l"))
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)

parg <- par_init(data_Gratiot, fixed.parameters=NULL, add.cofactors="Levelmulti")
result_Gratiot_CF2 <- fit_phenology(data=data_Gratiot, 
		fitted.parameters=parg, fixed.parameters=NULL, cofactors=td6, 
		add.cofactors="Level")
compare_AIC(WithoutCF=result_Gratiot, WithCF2=result_Gratiot_CF2)
plot(result_Gratiot_CF2)

# 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="Complete1",
                              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_Complete1=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)

## End(Not run)

phenology documentation built on Oct. 23, 2020, 7:22 p.m.