[R] Learning ANOVA

Stephen Liu satimis at yahoo.com
Sun Aug 15 16:58:23 CEST 2010


----- Original Message ----

From: David Winsemius <dwinsemius at comcast.net>
To: JesperHybel <jesperhybel at hotmail.com>
Cc: r-help at r-project.org
Sent: Sat, August 14, 2010 5:44:00 PM
Subject: Re: [R] Learning ANOVA


Hi David,

- snip -

>> JH > Also how to save InsectSprays.aov?  I think I can only save it as
>> InsectSprays.csv.  I can't find "write.aov" command.

>If you want to save an R object such as that returned by a function like aov, 
>there are several ways. The save() function will create a compacted form that 
>can then be read back into an R session with load(). >The dump() and dput() 
>functions will turn an object into an ASCII representation that can be saved as 
>a text file. If you only want to have the text that is produced when you "print" 
>it (and this is what you >implicitly get when to just call the function at the 
>console), then use sink() or capture.output().


Whether run;
> save(InsectSprays.aov, file="InsectSprays.rda") 
?

How to select the path and directory for saving the file?


To load the file;
> load(InsectSprays.rda)
?


I looked at ?dump and ?dput and couldn't resolve how to run them creating ASCII 
and text file.  Please help.  TIA


>> "InsectSprays.aov" is an object - in this case probably a list.

> Not "probably"; it is a list. Look at it with str if you have questions.

> str(InsectSprays)
'data.frame':    72 obs. of  2 variables:
 $ count: num  10 7 20 14 14 12 10 23 17 20 ...
 $ spray: Factor w/ 6 levels "A","B","C","D",..: 1 1 1 1 1 1 1 1 1 1 ...
> 
> 
> > test01 <- read.csv(file.choose(), header=TRUE)
Error: unexpected '>' in ">"
> test01 <- read.csv(file.choose(), header=TRUE)
Enter file name: /home/satimisub04dk01/InsectSpraysCopy.csv
> InsectSprays.aov <- aov(test01$count ~ test01$spray)
> 
> str(InsectSprays.aov)
List of 13
 $ coefficients : Named num [1:6] 14.5 0.833 -12.417 -9.583 -11 ...
  ..- attr(*, "names")= chr [1:6] "(Intercept)" "test01$sprayB" "test01$sprayC" 
"test01$sprayD" ...
 $ residuals    : Named num [1:72] -4.5 -7.5 5.5 -0.5 -0.5 ...
  ..- attr(*, "names")= chr [1:72] "1" "2" "3" "4" ...
 $ effects      : Named num [1:72] -80.6 22.1 -24.2 -19.9 -34.2 ...
  ..- attr(*, "names")= chr [1:72] "(Intercept)" "test01$sprayB" "test01$sprayC" 
"test01$sprayD" ...
 $ rank         : int 6
 $ fitted.values: Named num [1:72] 14.5 14.5 14.5 14.5 14.5 ...
  ..- attr(*, "names")= chr [1:72] "1" "2" "3" "4" ...
 $ assign       : int [1:6] 0 1 1 1 1 1
 $ qr           :List of 5
  ..$ qr   : num [1:72, 1:6] -8.485 0.118 0.118 0.118 0.118 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:72] "1" "2" "3" "4" ...
  .. .. ..$ : chr [1:6] "(Intercept)" "test01$sprayB" "test01$sprayC" 
"test01$sprayD" ...
  .. ..- attr(*, "assign")= int [1:6] 0 1 1 1 1 1
  .. ..- attr(*, "contrasts")=List of 1
  .. .. ..$ test01$spray: chr "contr.treatment"
  ..$ qraux: num [1:6] 1.12 1.05 1.06 1.07 1.09 ...
  ..$ pivot: int [1:6] 1 2 3 4 5 6
  ..$ tol  : num 1e-07
  ..$ rank : int 6
  ..- attr(*, "class")= chr "qr"
 $ df.residual  : int 66
 $ contrasts    :List of 1
  ..$ test01$spray: chr "contr.treatment"
 $ xlevels      :List of 1
  ..$ test01$spray: chr [1:6] "A" "B" "C" "D" ...
 $ call         : language aov(formula = test01$count ~ test01$spray)
 $ terms        :Classes 'terms', 'formula' length 3 test01$count ~ test01$spray
  .. ..- attr(*, "variables")= language list(test01$count, test01$spray)
  .. ..- attr(*, "factors")= int [1:2, 1] 0 1
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : chr [1:2] "test01$count" "test01$spray"
  .. .. .. ..$ : chr "test01$spray"
  .. ..- attr(*, "term.labels")= chr "test01$spray"
  .. ..- attr(*, "order")= int 1
  .. ..- attr(*, "intercept")= int 1
  .. ..- attr(*, "response")= int 1
  .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
  .. ..- attr(*, "predvars")= language list(test01$count, test01$spray)
  .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "factor"
  .. .. ..- attr(*, "names")= chr [1:2] "test01$count" "test01$spray"
 $ model        :'data.frame':    72 obs. of  2 variables:
  ..$ test01$count: int [1:72] 10 7 20 14 14 12 10 23 17 20 ...
  ..$ test01$spray: Factor w/ 6 levels "A","B","C","D",..: 1 1 1 1 1 1 1 1 1 1 
...
  ..- attr(*, "terms")=Classes 'terms', 'formula' length 3 test01$count ~ 
test01$spray
  .. .. ..- attr(*, "variables")= language list(test01$count, test01$spray)
  .. .. ..- attr(*, "factors")= int [1:2, 1] 0 1
  .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. ..$ : chr [1:2] "test01$count" "test01$spray"
  .. .. .. .. ..$ : chr "test01$spray"
  .. .. ..- attr(*, "term.labels")= chr "test01$spray"
  .. .. ..- attr(*, "order")= int 1
  .. .. ..- attr(*, "intercept")= int 1
  .. .. ..- attr(*, "response")= int 1
  .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
  .. .. ..- attr(*, "predvars")= language list(test01$count, test01$spray)
  .. .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "factor"
  .. .. .. ..- attr(*, "names")= chr [1:2] "test01$count" "test01$spray"
 - attr(*, "class")= chr [1:2] "aov" "lm"
- end -


The file is 'data.frame':    72 obs. of  2 variables:

obs = objects ???

How to read other data?  TIA


Other advice noted and thanks.


B.R.
Stephen L





More information about the R-help mailing list