[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] orgmode and anova
From: |
Uwe Brauer |
Subject: |
Re: [O] orgmode and anova |
Date: |
Fri, 22 Apr 2016 08:07:22 +0000 |
User-agent: |
Gnus/5.130016 (Ma Gnus v0.16) Emacs/25.1.50 (gnu/linux) |
>>> "Kyle" == Kyle Andrews <address@hidden> writes:
> If you wanted to fit a linear regression model with R, you could do
> so with the lm function. Calling anova on the output of the
> regression would give you a regression anova table.
> model <- lm(delivered_seeing ~ zeenith_seeing, data = delsee)
> anova(model)
> You would need non-zero residuals for that to be useful of course.
> Otherwise, you need to stack your *_seeing columns into one column
> with another column saying which kind of seeing it was and then:
> model.aov <- aov(seeing ~ factor(kind), data = delsee2)
> You could do the stacking in a number of ways. My favorite is to use
> the gather function in the tidyr package.
> aov is just a wrapper around lm, so just take the same approach as
> before to get the ANOVA table. Hope that helps.
Yes to a certain extend. I was able to perform an anova just comparing
the means of three samples. I did this in the following way:
First the data in table form
#+tblname: myanova
| C1 | C2 | C3 |
|------+----+----|
| 19 | 20 | 16 |
| 22 | 21 | 15 |
| 20 | 33 | 18 |
| 18 | 27 | 26 |
| 25 | 40 | 17 |
Then the following command did precisely what I wanted
#+begin_src R :results output org wrap :exports results
a = c(19,22,20,18,25)
b = c(20,21,33,27,40)
c = c(16,15,18,26,17)
dati = c(a, b, c)
groups = factor(rep(letters[1:3], each = 5))
fit = lm(formula = dati ~ groups)
anova(fit)
#+end_src
I actually do not really understand precisely the meaning of
groups = factor(rep(letters[1:3], each = 5))
but I also do not care much
Now executing the code, resulted in
#+RESULTS:
#+BEGIN_SRC org
Analysis of Variance Table
Response: dati
Df Sum Sq Mean Sq F value Pr(>F)
groups 2 260.93 130.467 4.0061 0.04648 *
Residuals 12 390.80 32.567
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#+END_SRC
The only thing I was interested in was the F and the p valor.
However now comes the question. I don't want to write the data in vector
form as in
a = c(19,22,20,18,25)
I want to extract them from the table:
#+tblname: myanova
| C1 1 | C2 | C3 |
| 19 | 20 | 16 |
| 22 | 21 | 15 |
| 20 | 33 | 18 |
| 18 | 27 | 26 |
| 25 | 40 | 17 |
(Rationale: I have a huge table with 300 entries and I don't want to
transform each colum in question into a vector)
So this is more a orgmode than a R question: is there a way to extract
from a given table its columns and perform via R an anova??
(I could ask the same for matlab, for which I have to transform the
table into a matlab matrix, which again I want to avoid.)
By hope is there is a sort of generalisation of my first example:
#+tblname: myan1
| growth | sugar |
|--------+-------|
| 75 | 45 |
| 72 | 44 |
| 73 | 89 |
| 61 | 40 |
| 67 | 23 |
| 64 | 33 |
| 62 | 22 |
| 63 | 22 |
#+begin_src R :results output :var myan1=myan1
summary(myan1)
#+end_src
The command summary directly extracts the information from that table. I
hope that something similar is possible for the anova.
thanks
Uwe Brauer