NonLinear_Beta: R6 Class for NonLinear_Beta modeling of crop responses

NonLinear_BetaR Documentation

R6 Class for NonLinear_Beta modeling of crop responses

Description

R6 class using non-linear regression (NonLinear_Beta) to model a crop response model with the experimental variable and remotely sensed covariate data. The model used in this class is a modified form of the sigmoidal 'Beta' function developed in the Yin et al. 2003 paper titled 'A Flexible Sigmoid Function of Determinate Growth'. This modified version uses the experimental input rate rather than time with a response of yield or protein rather than growth. Additionally, we added a term called 'Alpha' corresponding to the response when the experimental input was zero. This differs from the default where the function starts at zero.

This class is initialized with a named list of traning (named 'trn') and validation (named 'val') datasets, the response variable, the experimental variable, and the means of the centered data.

The initialization creates a data frame ('parm_df') containing the parameter names, function component and id, the mean and standard deviation, and whether it meets the criteria to be omitted from the model, making it a 'bad_parm'. The criteria for this is over 30% of data for a given year missing for a parameter or a standard deviation of zero, indicating singularity.

The process then creates a formula for a final model with all parameters that are not considered 'bad'. This is used to fit the final model that is returned to the user for use in the simulation to predict the response under varying rates of the experimental variable. This process is iterative and fits each model component at a time, using default coefficient estimates and updating as each component is fit and new coefficients are generated.

The 'saveDiagnostics' method include residuals vs. fitted, normal QQ- plots, etc. The fitting process also prepares data for validation plots in the 'ModClass' R6 class. This includes predicting observations in the validation dataset, making a unique id using the year and fieldname, uncentering data, and identifying a field name to use for plotting that reflects all fields in the dataset.

Public fields

dat

Named list of traning (named 'trn') and validation (named 'val') datasets with the response, experimental, and remotely sensed variables.

respvar

Character, the response variable of interest.

expvar

Character, the experimental variable of interest.

covars

Character vector of covariates to use for training the model.

m

Fitted non-linear logistic model.

form

Final non-linear logistic formula.

parm_df

Data frame of parameter names, the function component and ID, and a column named 'bad_parms' to indicate whether to include in the model formula. Also includes columns for the mean and standard deviation of each parameter.

fieldname

Unique name for the field(s) analyzed. If multiple fields are used they are separated by an ampersand, otherwise the singular field name is used. This is used for plottting.

mod_type

Name of the model of this class, used for plotting.

Methods

Public methods


Method new()

The initialization creates a data frame ('parm_df') containing the parameter names, the function component and id, the mean and standard deviation, and whether it meets the criteria to be omitted from the model, making it a 'bad_parm'. The criteria for this is over 30% of data for a given year missing for a parameter or a standard deviation of zero, indicating singularity. Removes data missing from covariates.

Usage
NonLinear_Beta$new(dat, respvar, expvar, covars)
Arguments
dat

Named list of traning (named 'trn') and validation (named 'val') datasets with the response, experimental, and remotely sensed variables.

respvar

Character, the response variable of interest.

expvar

Character, the experimental variable of interest.

covars

Character vector of covariates to use for training the model.

Returns

A instantiated 'NonLinear_Beta' object.


Method fitMod()

Method for fitting the non-linear beta model to response variables using experimental and covariate data.

The process first identifies parameters that will cause errors in the model fitting method, then creates some initial coefficient estimates to use for fitting an initial model. The estimates are based off of the mean to reduce the weight of large parameter values on the estimates. Then the alpha and beta components are estimated with these initial values and the means of each parameter. The intercepts of alpha and beta are derived from the 1st and 3rd quantiles of the response while delta1 and delta2 are derived from the 1st and 3rd quantiles of the experimental input.

The model is fit iteratively one parameter at a time using error handling where if a parameter causes convergence to fail it is omitted. In theory, a final model could result that only includes the alpha and beta intercepts, the deltas, and the experimental variable.

The fitting process also prepares data for validation plots in the 'ModClass' R6 class. This includes predicting observations in the validation dataset, making a unique id using the year and fieldname, uncentering data, and identifying a field name to use for plotting that reflects all fields in the dataset.

Usage
NonLinear_Beta$fitMod()
Arguments
None

Put parameters here

Returns

A fitted beta function model.


Method predResps()

Method for predicting response variables using data and a model.

Usage
NonLinear_Beta$predResps(dat, m)
Arguments
dat

Data for predicting response variables for.

m

The fitted model to use for predicting the response variable for each observation in 'dat'.

Returns

Vector of predicted values for each location in 'dat'.


Method saveDiagnostics()

Method for saving diagnostic plots of the fitted model. These include residual vs. fitted values, normal QQ plots, etc.

Usage
NonLinear_Beta$saveDiagnostics(out_path, SAVE)
Arguments
out_path

The path to the folder in which to store and save outputs from the model fitting process

SAVE

Whether to save diagnostic plots.

Returns

Diagnostic plots.


Method clone()

The objects of this class are cloneable with this method.

Usage
NonLinear_Beta$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

ModClass for the class that calls the ModClass interface, GAM, RF, and BayesLinear for alternative model classes.


paulhegedus/OFPE documentation built on Nov. 23, 2022, 5:09 a.m.