This function performs the updated nonlinear least squares (NLS) regression method for the cosine model (see Chazin et al. 2019).
Usage
sineFit(data, amplitude = NULL, intercept = NULL, method = c("OLS", "initial"))Arguments
- data
A data frame that contains the data for one individual. There should be two columns with names 'distance' and 'oxygen'.
- amplitude
Initial value for the amplitude parameter for the
method="initial"method.- intercept
Initial value for the intercept parameter for the
method="initial"method.- method
A character string giving the initialization for the nonlinear least squares regression. This must be either
method="initial"ormethod="OLS". Default ismethod="OLS"method.method="initial"performs the nonlinear least squares (NLS) regression method for the cosine model without initializing parameter selections. It begins with the given initial values for amplitude and intercept.method="OLS"uses the least squares estimates (see Chazin et al. 2019) as the initial parameter selection.
Value
A fitted model object from the nls function in R:
- m
an 'nlsModel' object incorporating the model.
- convInfo
a list with convergence information
- data
the expression that was passed to 'nls' as the data argument. The actual data values are present in the environment of the 'm' component.
- call
the matched call with several components, notably 'algorithm'
- dataClasses
the '"dataClasses"' attribute (if any) of the '"terms"' attribute of the model frame.
- control
the control 'list' used
References
Florent Baty, Christian Ritz, Sandrine Charles, Martin Brutsche, Jean-Pierre Flandrois, Marie-Laure Delignette-Muller (2015). A Toolbox for Nonlinear Regression in R: The Package nlstools. Journal of Statistical Software, 66(5), 1-21. URL http://www.jstatsoft.org/v66/i05/.
Examples
armenia_split = split(armenia,f = armenia$ID)
amp = seq(1,10,by=0.5)
int = seq(-25,0,by=0.5)
sineFit(armenia_split[[2]],amp[3],int[4],method = "initial")
#> Nonlinear regression model
#> model: oxygen ~ intercept + amplitude * cos(frequency * distance + phase)
#> data: data
#> intercept amplitude phase frequency
#> -5.7143 5.9191 -0.1394 0.1776
#> residual sum-of-squares: 1.049
#>
#> Number of iterations to convergence: 8
#> Achieved convergence tolerance: 1.249e-06
sineFit(armenia_split[[1]],method = "OLS")
#> Nonlinear regression model
#> model: oxygen ~ intercept + amplitude * cos(frequency * distance + phase)
#> data: data
#> intercept amplitude phase frequency
#> -4.2485 5.2653 0.7701 0.1657
#> residual sum-of-squares: 1.371
#>
#> Number of iterations to convergence: 6
#> Achieved convergence tolerance: 2.068e-06