~l3on/ubuntu/precise/rkward/rebuild1

« back to all changes in this revision

Viewing changes to rkward/plugins/analysis/outliers/grubbs_test.php

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Friedrichsmeier
  • Date: 2008-04-20 21:30:00 UTC
  • mfrom: (1.2.2 upstream) (3.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080420213000-fs4i8efmfc793bnn
new upstream release
closes: #475175
closes: #463348
closes: #475982

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?
 
2
function preprocess () { ?>
 
3
require(outliers)
 
4
<?
 
5
}
 
6
 
 
7
function calculate () {
 
8
        $vars = "substitute (" . str_replace ("\n", "), substitute (", trim (getRK_val ("x"))) . ")";
 
9
?>
 
10
 
 
11
vars <- list (<? echo ($vars); ?>)
 
12
results <- data.frame ('Variable Name'=rep (NA, length (vars)), check.names=FALSE)
 
13
for (i in 1:length(vars)) {
 
14
        results[i, 'Variable Name'] <- rk.get.description (vars[[i]], is.substitute=TRUE)
 
15
<?      if (getRK_val ("length")) { ?>
 
16
        var <- eval (vars[[i]], envir=globalenv ())
 
17
 
 
18
        results[i, 'Length'] <- length (var)
 
19
        results[i, 'NAs'] <- sum (is.na(var))
 
20
 
 
21
        var <- na.omit (var)    # omit NAs for all further calculations
 
22
<?      } else { ?>
 
23
        var <- na.omit (eval (vars[[i]], envir=globalenv ()))
 
24
<?      } ?>
 
25
 
 
26
        results[i, 'Error'] <- tryCatch ({
 
27
                # This is the core of the calculation
 
28
                t <- grubbs.test (var, type = <? getRK ("type"); ?>, opposite = <? getRK ("opposite"); ?>, two.sided = <? getRK ("two_sided"); ?>)
 
29
                results[i, 'G'] <- t$statistic["G"]
 
30
                results[i, 'U'] <- t$statistic["U"]
 
31
                results[i, 'p-value'] <- t$p.value
 
32
                results[i, 'Alternative Hypothesis']<- rk.describe.alternative (t)
 
33
<?      if (getRK_val ("descriptives")) { ?>
 
34
                results[i, 'Mean'] <- mean (var)
 
35
                results[i, 'Standard Deviation'] <- sd (var)
 
36
                results[i, 'Median'] <- median (var)
 
37
                results[i, 'Minimum'] <- min (var)
 
38
                results[i, 'Maximum'] <- max (var)
 
39
<?      } ?>
 
40
                NA                              # no error
 
41
        }, error=function (e) e$message)        # catch any errors
 
42
}
 
43
if (all (is.na (results$'Error'))) results$'Error' <- NULL
 
44
<?
 
45
}
 
46
 
 
47
function printout () {
 
48
?>
 
49
rk.header ("Grubbs tests for one or two outliers in data sample",
 
50
        parameters=list ("Type", "<? getRK ("type"); ?>", "Opposite", "<? getRK ("opposite"); ?>", "two-sided", "<? getRK ("two_sided"); ?>"))
 
51
rk.results (results)
 
52
<?
 
53
}
 
54
 
 
55
?>