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?
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.
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.
Just the first part of that question can fill entire books. Just some quick choices:
lm()
for standard linear modelsglm()
for generalised linear models (eg for logistic regression)rlm()
from package MASS for robust linear modelslmrob()
from package robustbase for robust linear modelsloess()
for non-linear / non-parametric modelsThen 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With