aboutsummaryrefslogtreecommitdiffstats
path: root/r/chisq.R
blob: 41f851f395d3f12ccab106431c325c8734abde22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding: utf-8 -*-
#
# Calculate the chi-squared values between the given data and model values.
#

calc.chisq <- function(value, error=NULL, model=NULL) {
    if (is.data.frame(value)) {
        df <- value
        value <- df$value
        error <- df$error
        model <- df$model
    }
    chisq <- (value - model)^2
    if (! is.null(error)) {
        weights <- error ^ (-2)
        chisq <- chisq * weights
    }
    return(sum(chisq))
}

#  vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=r: #