File: dixon_test.rkcommands.R

package info (click to toggle)
rkward 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 45,628 kB
  • sloc: cpp: 50,489; xml: 9,596; javascript: 6,401; python: 21; makefile: 13
file content (60 lines) | stat: -rw-r--r-- 2,011 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
local({
## Prepare
require(outliers)
## Compute
vars <- rk.list (women[["weight"]], women[["height"]])
results <- data.frame ("Variable Name"=I(names (vars)), check.names=FALSE)
for (i in 1:length (vars)) {
	var <- vars[[i]]

	results[i, 'Length'] <- length (var)
	results[i, 'NAs'] <- sum (is.na(var))

	var <- na.omit (var) 	# omit NAs for all further calculations

	results[i, "Error"] <- tryCatch ({
		# This is the core of the calculation
		t <- dixon.test (var, type = 0, opposite = FALSE, two.sided = TRUE)
		results[i, "Dixon Q-statistic"] <- t$statistic["Q"]
		results[i, "p-value"] <- t$p.value
		results[i, "Alternative Hypothesis"]<- rk.describe.alternative (t)
		results[i, "Mean"] <- mean (var)
		results[i, "Standard Deviation"] <- sd (var)
		results[i, "Median"] <- median (var)
		results[i, "Minimum"] <- min (var)
		results[i, "Maximum"] <- max (var)
		NA				# no error
	}, error=function (e) e$message)	# catch any errors
}
if (all (is.na (results$"Error"))) results$"Error" <- NULL
## Print result
rk.header ("Dixon test for outlier", parameters=list("Variant of test"="0 (Automatic)",
	"Opposite"="no",
	"two-sided"="yes"))
rk.results (results)
})
local({
## Prepare
require(outliers)
## Compute
vars <- rk.list (women[["weight"]], women[["height"]])
results <- data.frame ("Variable Name"=I(names (vars)), check.names=FALSE)
for (i in 1:length (vars)) {
	var <- na.omit (vars[[i]])

	results[i, "Error"] <- tryCatch ({
		# This is the core of the calculation
		t <- dixon.test (var, type = 0, opposite = TRUE, two.sided = FALSE)
		results[i, "Dixon Q-statistic"] <- t$statistic["Q"]
		results[i, "p-value"] <- t$p.value
		results[i, "Alternative Hypothesis"]<- rk.describe.alternative (t)
		NA				# no error
	}, error=function (e) e$message)	# catch any errors
}
if (all (is.na (results$"Error"))) results$"Error" <- NULL
## Print result
rk.header ("Dixon test for outlier", parameters=list("Variant of test"="0 (Automatic)",
	"Opposite"="yes",
	"two-sided"="no"))
rk.results (results)
})