Learn R Programming

npregfast (version 1.2.0)

frfast: Fitting nonparametric models

Description

This function is used to fit nonparametric models by using local polynomial kernel smoothers. These models can include or not factor-by-curve interactions. Additionally, a parametric model (allometric model) can be estimated (or not).

Usage

frfast(formula, data = data, model = "np", h0 = -1, h = -1, nh = 30,
  weights = NULL, kernel = "epanech", p = 3, kbin = 100, nboot = 500,
  rankl = NULL, ranku = NULL, seed = NULL)

Arguments

formula
An object of class formula: a sympbolic description of the model to be fitted. The details of model specification are given under 'Details'.
data
A data frame or matrix containing the model response variable and covariates required by the formula.
model
Type model used: model = "np" nonparametric regression model with local polynomial kernel smoothers, model = "allo" the allometric model.
h0
The kernel bandwidth smoothing parameter for the global effect (see references for more details at the estimation). Large values of the bandwidth lead to smoothed estimates; smaller values of the bandwidth lead lo undersmoothed estimates. By default, cro
h
The kernel bandwidth smoothing parameter for the partial effects.
nh
Integer number of equally-spaced bandwidth in which the h is discretised, to speed up computation.
weights
Prior weights on the data.
kernel
A character string specifying the desired kernel. Defaults to kernel = "epanech", where the Epanechnikov density function kernel will be used. Also, several types of kernel functons can be used: triangular and Gaussian density function, w
p
Polynomial degree to be used. Its value must be the value of derivative + 1. The default value is 3, returning the estimation, first and second derivative.
kbin
Number of binning nodes over which the function is to be estimated.
nboot
Number of bootstrap repeats. Defaults to 500 bootstrap repeats. The wild bootstrap is used when model = "np" and the simple bootstrap when model = "allo".
rankl
Number or vector specifying the minimum value for the interval at which to search the x value which maximizes the estimate, first or second derivative (for each level). The default is the minimum data value.
ranku
Number or vector specifying the maximum value for the interval at which to search the x value which maximizes the estimate, first or second derivative (for each level). The default is the maximum data value.
seed
Seed to be used in the bootstrap procedure.

Value

  • An object is returned with the following elements:
  • xVector of values of the grid points at which model is to be estimate.
  • pMatrix of values of the grid points at which to compute the estimate, their first and second derivative.
  • plLower values of 95% confidence interval for the estimate, their first and second derivative.
  • puUpper values of 95% confidence interval for the estimate, their first and second derivative.
  • diffDifferences between the estimation values of a couple of levels (i. e. level 2 - level 1). The same procedure for their first and second derivative.
  • difflLower values of 95% confidence interval for the differences between the estimation values of a couple of levels. It is performed for their first and second derivative.
  • diffuUpper values of 95% confidence interval for the differences between the estimation values of a couple of levels. It is performed for their first and second derivative.
  • nbootNumber of bootstrap repeats.
  • nSample size.
  • dpDegree of polynomial to be used.
  • h0The kernel bandwidth smoothing parameter for the global effect.
  • hThe kernel bandwidth smoothing parameter for the partial effects.
  • fmodFactor's level for each data.
  • xdataOriginal x values.
  • ydataOriginal y values.
  • wWeights on the data.
  • kbinNumber of binning nodes over which the function is to be estimated.
  • nfNumber of levels.
  • maxValue of covariate x which maximizes the estimate, first or second derivative.
  • maxuUpper value of 95% confidence interval for the value max.
  • maxlLower value of 95% confidence interval for the value max.
  • diffmaxDifferences between the estimation of max for a couple of levels (i. e. level 2 - level 1). The same procedure for their first and second derivative.
  • diffmaxuUpper value of 95% confidence interval for the value diffmax.
  • diffmaxlLower value of 95% confidence interval for the value diffmax.
  • repbootMatrix of values of the grid points at which to compute the estimate, their first and second derivative for each bootstrap repeat.
  • ranklMaximum value for the interval at which to search the x value which maximizes the estimate, first or second derivative (for each level). The default is the maximum data value.
  • rankuMinimum value for the interval at which to search the x value which maximizes the estimate, first or second derivative (for each level). The default is the minimum data value.
  • nmodelType model used: nmodel = 1 the nonparametric model, nmodel = 2 the allometric model.
  • labelLabels of the variables in the model.
  • numlabelNumber of labels.
  • kernelA character specifying the derised kernel.
  • aEstimated coefficient in the case of fitting an allometric model.
  • alLower value of 95% confidence interval for the value of a.
  • auUpper value of 95% confidence interval for the value of a.
  • bEstimated coefficient in the case of fitting an allometric model.
  • blLower value of 95% confidence interval for the value of b.
  • buUpper value of 95% confidence interval for the value of b.
  • nameName of the variables in the model.
  • formulaA sympbolic description of the model to be fitted.
  • nhInteger number of equally-spaced bandwidth on which the h is discretised.
  • r2Coefficient of determination (in the case of the allometric model).

Details

The models fitted by frfast function are specified in a compact symbolic form. The ~ operator is basic in the formation of such models. An expression of the form y ~ model is interpreted as a specification that the response y is modelled by a predictor specified symbolically by model. The possible terms consist of a variable name or a variable name and a factor name separated by : operator. Such a term is interpreted as the interaction of the continuous variable and the factor.

References

Sestelo, M. (2013). Development and computational implementation of estimation and inference methods in flexible regression models. Applications in Biology, Engineering and Environment. PhD Thesis, Department of Statistics and O.R. University of Vigo.

Examples

Run this code
library(npregfast)
data(barnacle)

# Nonparametric regression without interactions
fit <- frfast(DW ~ RC, data = barnacle, nboot = 100) 
fit
summary(fit)

# Change the number of binning nodes and bootstrap replicates
fit <- frfast(DW ~ RC, data = barnacle, kbin = 200, nboot = 100)

# Nonparametric regression with interactions
fit2 <- frfast(DW ~ RC : F, data = barnacle, nboot = 100)
fit2
summary(fit2)


# Allometric model
fit3 <- frfast(DW ~ RC, data = barnacle, model = "allo", nboot = 100)
summary(fit3)

# fit4 <- frfast(DW ~ RC : F, data = barnacle, model = "allo", nboot = 100)
# summary(fit4)

Run the code above in your browser using DataLab