fitchisq {qpcR}R Documentation

The chi-square goodness-of-fit

Description

Calculates χ2\chi^2, reduced χν2\chi_{\nu}^2 and the χ2\chi^2 fit probability for objects of class pcrfit, lm, glm, nls or any other object with a call component that includes formula and data. The function checks for replicated data (i.e. multiple same predictor values). If replicates are not given, the function needs error values, otherwise NA's are returned.

Usage

fitchisq(object, error = NULL)

Arguments

object

a single model of class 'pcrfit', a 'replist' or any fitted model of the above.

error

in case of a model without replicates, a single error for all response values or a vector of errors for each response value.

Details

The variance of a fit s2s^2 is also characterized by the statistic χ2\chi^2 defined as followed:

χ2i=1n(yif(xi))2σi2\chi^2 \equiv \sum_{i=1}^n \frac{(y_i - f(x_i))^2}{\sigma_i^2}

The relationship between s2s^2 and χ2\chi^2 can be seen most easily by comparison with the reduced χ2\chi^2:

χν2=χ2ν=s2σi2\chi_\nu^2 = \frac{\chi^2}{\nu} = \frac{s^2}{\langle \sigma_i^2 \rangle}

whereas ν\nu = degrees of freedom (N - p), and σi2\langle \sigma_i^2 \rangle is the weighted average of the individual variances. If the fitting function is a good approximation to the parent function, the value of the reduced chi-square should be approximately unity, χν2=1\chi_\nu^2 = 1. If the fitting function is not appropriate for describing the data, the deviations will be larger and the estimated variance will be too large, yielding a value greater than 1. A value less than 1 can be a consequence of the fact that there exists an uncertainty in the determination of s2s^2, and the observed values of χν2\chi_\nu^2 will fluctuate from experiment to experiment. To assign significance to the χ2\chi^2 value, we can use the integral probability

Pχ(χ2;ν)=χ2Pχ(x2,ν)dx2P_\chi(\chi^2;\nu) = \int_{\chi^2}^\infty P_\chi(x^2, \nu)dx^2

which describes the probability that a random set of n data points sampled from the parent distribution would yield a value of χ2\chi^2 equal to or greater than the calculated one. This is calculated by 1pchisq(χ2,ν)1 - pchisq(\chi^2, \nu).

Value

A list with the following items:

chi2

the χ2\chi^2 value.

chi2.red

the reduced χν2\chi_\nu^2.

p.value

the fit probability as described above.

Author(s)

Andrej-Nikolai Spiess

References

Data Reduction and Error Analysis for the Physical Sciences.
Bevington PR & Robinson DK.
McGraw-Hill, New York (2003).

Applied Regression Analysis.
Draper NR & Smith H.
Wiley, New York, 1998.

Examples

## Using replicates by making a 'replist'.
ml1 <- modlist(reps, fluo = 2:5)
rl1 <- replist(ml1, group = c(1, 1, 1, 1))
fitchisq(rl1[[1]])

## Using single model with added error.
m1 <- pcrfit(reps, 1, 2, l5)
fitchisq(m1, 0.1)

[Package qpcR version 1.4-1 Index]