# R Programming/Nonparametric Methods

R Programming
* R Basics
** Introduction
** Sample Session
** Manage your workspace
** Settings and Installation
** Documentation
** Control Structures
** Working with functions
** Debugging
** Using C or Fortran
** Utilities
** Estimation utilities
** Packages
* Data Management
** Data types
** Working with data frames
** Importing and exporting data
** Text Processing
** Times and Dates
* Graphics
** Grammar of graphics
* Publication quality output
* Descriptive Statistics
* Mathematics
** Optimization
** Probability Distributions
** Random Number Generation
* Statistical Core Methods
** Maximum Likelihood
** Method of Moments
** Bayesian Methods
** Bootstrap
** Multiple Imputation
** Nonparametric Methods
* Regression Models
** Linear Models
** Quantile Regression
** Binomial Models
** Multinomial Models
** Tobit And Selection Models
** Count Data Models
** Duration Analysis
* Time Series
* Factor Analysis
* Classification
** Ordination
** Clustering
* Network Analysis
* High Performance Computing
** Profiling R code
** Parallel computing with R
* Appendix
** Sources
** Index
This page deals with a set of non-parametric methods including the estimation of a cumulative distribution function (CDF), the estimation of probability density function (PDF) with histograms and kernel methods and the estimation of flexible regression models such as local regressions and generalized additive models.
For an introduction to nonparametric methods you can have a look at the following books or handout :
* Nonparametric Econometrics: A Primer by Jeffrey S. Racine.
* Li and Racine's handbook, Nonparametric econometrics.
* Larry Wasserman All of Nonparamatric Statistics

## Empirical distribution function

* The easiest way to estimate the empirical CDF uses the rank and the length functions.
* ecdf computes the empirical cumulative distribution function.
* ecdf.ksCI (sfsmisc) plots the empirical distribution function with confidence intervals.

## Density Estimation
### Histogram

* hist is the standard function for drawing histograms. If you store the histogram as an object the estimated parameters are returned in this object.
It is also possible to choose the break points.
* n.bins (car package) includes several methods to compute the number of bins for an histogram.
* histogram (lattice)
* truehist (MASS)
* hist.scott (MASS) plot a histogram with automatic bin width selection, using the Scott or Freedman–Diaconis formulae.
* histogram package.

### Kernel Density Estimation

* density estimates the kernel density of a vector.
** Choose the bandwidth selection method with bw.
** Check the sensitivity of the bandwidth choice using adjust. The default is one. It is good practice to look at adjust=.5 and adjust=2.
** Choose the kernel function with kernel : "gaussian", "epanechnikov", "rectangular", "triangular", "biweight", "cosine", "optcosine".
* tkdensity (sfsmisc) is a nice function which allow to dynamically choose the kernel and the bandwidth with a handy graphical user interface. This is a good way to check the sensitivity of the bandwidth and/or kernel choice on the density estimation.
* kde2d (MASS) estimates a bivariate kernel density.

#### Examples
## Local Regression

* loess is the standard function for local linear regression.
* lowess is similar to loess but does not have a standard syntax for regression y ~ x .This is the ancestor of loess (with different defaults!).
* ksmooth (stats) computes the Nadaraya–Watson kernel regression estimate.
* locpoly (KernSmooth package)
* npreg (np package)
* locpol computes local polynomial estimators
* locfit local regression, likelihood and density estimation

### Examples
## Generalized additive semiparametric models (GAM)

* gam (gam)
* gam (mgcv)

## References

* ↑ Jeffrey S. Racine Nonparametric Econometrics: A Primer http://socserv.mcmaster.ca/racine/ECO0301.pdf and at the R code examples http://socserv.mcmaster.ca/racine/primer_code.zip
* ↑ Qi Li, Jeffrey S. Racine, Nonparametric econometrics, Princeton University Press - 2007
* ↑ Wasserman, Larry, "All of nonparametric statistics", Springer (2007) (ISBN: 0387251456)