* orgmode and anova
@ 2016-04-21 19:09 Uwe Brauer
2016-04-22 1:56 ` Kyle Andrews
0 siblings, 1 reply; 3+ messages in thread
From: Uwe Brauer @ 2016-04-21 19:09 UTC (permalink / raw)
To: emacs-orgmode
Hello
Using Kubuntu I just installed R and the following code works nicely
#+tblname: delsee
| airmass | zenith_seeing | delivered_seeing |
|---------+---------------+------------------|
| 1.3 | 0.95 | 1.1119612 |
| 1.3 | 1.0 | 1.1704854 |
| 1.3 | 1.1 | 1.2875340 |
| 1.3 | 1.2 | 1.4045825 |
#+TBLFM: $3=$2*($1**0.6)
#+begin_src R :results output :var delsee=delsee
summary(delsee)
#+end_src
Does somebody know whether I could do an ANOVA, comparing these columns
(which does not make much sense, but this is not the point.
Any help is strongly appreciated.
thanks
Uwe Brauer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: orgmode and anova
2016-04-21 19:09 orgmode and anova Uwe Brauer
@ 2016-04-22 1:56 ` Kyle Andrews
2016-04-22 8:07 ` Uwe Brauer
0 siblings, 1 reply; 3+ messages in thread
From: Kyle Andrews @ 2016-04-22 1:56 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1526 bytes --]
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.
On Thu, Apr 21, 2016, 15:10 Uwe Brauer <oub@mat.ucm.es> wrote:
> Hello
>
> Using Kubuntu I just installed R and the following code works nicely
>
> #+tblname: delsee
> | airmass | zenith_seeing | delivered_seeing |
> |---------+---------------+------------------|
> | 1.3 | 0.95 | 1.1119612 |
> | 1.3 | 1.0 | 1.1704854 |
> | 1.3 | 1.1 | 1.2875340 |
> | 1.3 | 1.2 | 1.4045825 |
> #+TBLFM: $3=$2*($1**0.6)
>
>
> #+begin_src R :results output :var delsee=delsee
> summary(delsee)
> #+end_src
>
>
> Does somebody know whether I could do an ANOVA, comparing these columns
> (which does not make much sense, but this is not the point.
>
> Any help is strongly appreciated.
>
> thanks
>
> Uwe Brauer
>
>
>
[-- Attachment #2: Type: text/html, Size: 2027 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: orgmode and anova
2016-04-22 1:56 ` Kyle Andrews
@ 2016-04-22 8:07 ` Uwe Brauer
0 siblings, 0 replies; 3+ messages in thread
From: Uwe Brauer @ 2016-04-22 8:07 UTC (permalink / raw)
To: emacs-orgmode
>>> "Kyle" == Kyle Andrews <kyle.c.andrews@gmail.com> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-22 8:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-21 19:09 orgmode and anova Uwe Brauer
2016-04-22 1:56 ` Kyle Andrews
2016-04-22 8:07 ` Uwe Brauer
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).