diff options
author | Aaron LI <aaronly.me@gmail.com> | 2016-03-31 10:57:34 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@gmail.com> | 2016-03-31 10:57:34 +0800 |
commit | c9c896dea2ba43551c4e10bd49666105449e9bd7 (patch) | |
tree | e94b73f17b2d776c2acd4c9549657f500c3dc7ce /r/chisq.R | |
parent | 2b6cb9b655a53d43b32a8a211287c82f4f59999a (diff) | |
download | atoolbox-c9c896dea2ba43551c4e10bd49666105449e9bd7.tar.bz2 |
add all scripts/tools
Diffstat (limited to 'r/chisq.R')
-rw-r--r-- | r/chisq.R | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/r/chisq.R b/r/chisq.R new file mode 100644 index 0000000..41f851f --- /dev/null +++ b/r/chisq.R @@ -0,0 +1,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: # |