Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Goodness of fit functions in R

Tags:

What functions do you use in R to fit a curve to your data and test how well that curve fits? What results are considered good?

like image 752
medriscoll Avatar asked Jul 25 '09 02:07

medriscoll


People also ask

What is goodness of fit with example?

Goodness-of-Fit is a statistical hypothesis test used to see how closely observed data mirrors expected data. Goodness-of-Fit tests can help determine if a sample follows a normal distribution, if categorical variables are related, or if random samples are from the same distribution.

What is chi-square test goodness of fit?

The chi-square goodness of fit test is a hypothesis test. It allows you to draw conclusions about the distribution of a population based on a sample. Using the chi-square goodness of fit test, you can test whether the goodness of fit is “good enough” to conclude that the population follows the distribution.


2 Answers

Just the first part of that question can fill entire books. Just some quick choices:

  • lm() for standard linear models
  • glm() for generalised linear models (eg for logistic regression)
  • rlm() from package MASS for robust linear models
  • lmrob() from package robustbase for robust linear models
  • loess() for non-linear / non-parametric models

Then there are domain-specific models as e.g. time series, micro-econometrics, mixed-effects and much more. Several of the Task Views as e.g. Econometrics discuss this in more detail. As for goodness of fit, that is also something one can spend easily an entire book discussing.

like image 93
Dirk Eddelbuettel Avatar answered Oct 24 '22 02:10

Dirk Eddelbuettel


The workhorses of canonical curve fitting in R are lm(), glm() and nls(). To me, goodness-of-fit is a subproblem in the larger problem of model selection. Infact, using goodness-of-fit incorrectly (e.g., via stepwise regression) can give rise to seriously misspecified model (see Harrell's book on "Regression Modeling Strategies"). Rather than discussing the issue from scratch, I recommend Harrell's book for lm and glm. Venables and Ripley's bible is terse, but still worth a reading. "Extending the Linear Model with R" by Faraway is comprehensive and readable. nls is not covered in these sources, but "Nonlinear Regression with R" by Ritz & Streibig fills the gap and is very hands-on.

like image 37
gappy Avatar answered Oct 24 '22 01:10

gappy