fitchisq {qpcR}R Documentation

The chi-square goodness-of-fit

Description

Calculates \chi^2, reduced \chi_{\nu}^2 and the \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 s^2 is also characterized by the statistic \chi^2 defined as followed:

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

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

\chi_\nu^2 = \frac{\chi^2}{\nu} = \frac{s^2}{\langle \sigma_i^2 \rangle}

whereas \nu = degrees of freedom (N - p), and \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, \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 s^2, and the observed values of \chi_\nu^2 will fluctuate from experiment to experiment. To assign significance to the \chi^2 value, we can use the integral probability

P_\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 \chi^2 equal to or greater than the calculated one. This is calculated by 1 - pchisq(\chi^2, \nu).

Value

A list with the following items:

chi2

the \chi^2 value.

chi2.red

the reduced \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]