2
function preprocess () {
5
function calculate () {
6
$vars = "substitute (" . str_replace ("\n", "), substitute (", trim (getRK_val ("x"))) . ")";
7
$trim = getRK_val ("trim"); //the fraction (0 to 0.5) of observations to be trimmed from each end of x before the mean is computed
8
$low = getRK_val ("low");
9
$high = getRK_val ("high");
12
rk.temp.options <- list (domean=<? getRK ("mean"); ?>, domedian=<? getRK ("median"); ?>, dorange=<? getRK ("range"); ?>, dosd=<? getRK ("sd"); ?>, dosum=<? getRK ("sum"); ?>, doprod=<? getRK ("prod"); ?>, domad=<? getRK ("mad"); ?>, dolength=<? getRK ("length"); ?>, donacount=<? getRK ("nacount"); ?>)
13
rk.temp.results <- list ()
14
i=0; for (var in list (<? echo ($vars); ?>)) {
16
rk.temp.results[[i]] <- list ()
17
rk.temp.results[[i]]$object <- rk.get.description (var, is.substitute=TRUE)
18
if (rk.temp.options$domean) try (rk.temp.results[[i]]$mean <- mean (eval (var), <?echo ($trim) ;?>, na.rm=TRUE))
19
if (rk.temp.options$domedian) try (rk.temp.results[[i]]$median <- median (eval (var), na.rm=TRUE))
20
if (rk.temp.options$dorange) try (rk.temp.results[[i]]$range <- range (eval (var), na.rm=TRUE))
21
if (rk.temp.options$dosd) try (rk.temp.results[[i]]$sd <- sd (eval (var), na.rm=TRUE))
22
if (rk.temp.options$dosum) try (rk.temp.results[[i]]$sum <- sum (eval (var), na.rm=TRUE))
23
if (rk.temp.options$doprod) try (rk.temp.results[[i]]$prod <- prod (eval (var), na.rm=TRUE))
24
if (rk.temp.options$domad) try (rk.temp.results[[i]]$mad <- mad (eval (var), <?echo ($low) ;?>, <?echo ($high) ;?>, na.rm=TRUE))
25
if (rk.temp.options$dolength) try (rk.temp.results[[i]]$length <- length (eval (var)))
26
if (rk.temp.options$donacount) try (rk.temp.results[[i]]$nacount <- length (which(is.na(eval (var)))))
30
function printout () {
32
cat ("<h1>Descriptive statistics</h1>")
33
cat ("<h2>Parmeters</h2>")
34
cat (paste ("<h3>Trim of mean", <?getRK ("trim") ;?>, "</h3>\n"))
35
if (rk.temp.options$domad) cat (paste ("<h3>Median Absolute Deviation:", "lo-median is", <?getRK ("low") ;?>, "and hi-median is", <? getRK ("high") ;?>,"</h3>\n"))
36
cat ("<table border=\"1\"><tr><td>Variable</td>")
37
if (rk.temp.options$domean) cat ("<td>mean</td>")
38
if (rk.temp.options$domedian) cat ("<td>median</td>")
39
if (rk.temp.options$dorange) cat ("<td>min</td><td>max</td>")
40
if (rk.temp.options$dosd) cat ("<td>standard deviation</td>")
41
if (rk.temp.options$dosum) cat ("<td>sum</td>")
42
if (rk.temp.options$doprod) cat ("<td>product</td>")
43
if (rk.temp.options$domad) cat ("<td>mad</td>")
44
if (rk.temp.options$dolength) cat ("<td>length of sample</td>")
45
if (rk.temp.options$donacount) cat ("<td>number of NAs</td>")
48
for (i in 1:length (rk.temp.results)) {
49
cat ("<tr><td>", rk.temp.results[[i]]$object, "</td>")
50
if (rk.temp.options$domean) cat ("<td>", rk.temp.results[[i]]$mean, "</td>")
51
if (rk.temp.options$domedian) cat ("<td>", rk.temp.results[[i]]$median, "</td>")
52
if (rk.temp.options$dorange) cat ("<td>", rk.temp.results[[i]]$range[1], "</td>", "<td>", rk.temp.results[[i]]$range[2], "</td>")
53
if (rk.temp.options$dosd) cat ("<td>", rk.temp.results[[i]]$sd, "</td>")
54
if (rk.temp.options$dosum) cat ("<td>", rk.temp.results[[i]]$sum, "</td>")
55
if (rk.temp.options$doprod) cat ("<td>", rk.temp.results[[i]]$prod, "</td>")
56
if (rk.temp.options$domad) cat ("<td>", rk.temp.results[[i]]$mad, "</td>")
57
if (rk.temp.options$dolength) cat ("<td>", rk.temp.results[[i]]$length, "</td>")
58
if (rk.temp.options$donacount) cat ("<td>", rk.temp.results[[i]]$nacount, "</td>")
66
?>rm (rk.temp.options)