~l3on/ubuntu/precise/rkward/rebuild1

« back to all changes in this revision

Viewing changes to rkward/plugins/20descriptive/code.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
 
        }
4
 
        
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");
10
 
 
11
 
?>
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); ?>)) {
15
 
        i = i+1
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)))))
27
 
}<?
28
 
        }
29
 
        
30
 
        function printout () {
31
 
?>
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>")
46
 
cat ("</tr>")
47
 
 
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>")
59
 
        cat ("</tr>")
60
 
}
61
 
cat ("</table>")
62
 
<?
63
 
        }
64
 
        
65
 
        function cleanup () {
66
 
?>rm (rk.temp.options)
67
 
rm (rk.temp.results)
68
 
<?
69
 
        }
70
 
?>