R version 2.6.1 (2007-11-26) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(arm) Loading required package: MASS Loading required package: Matrix Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from package:stats : xtabs Loading required package: lme4 Loading required package: R2WinBUGS Loading required package: coda arm (Version 1.1-1, built: 2008-1-13) Working directory is D:/Program Files/R/R-2.6.1 options( digits = 2 ) Loading required package: car Loading required package: foreign Warning messages: 1: In namespaceImportFrom(self, asNamespace(ns)) : replacing previous import: cov2cor 2: In namespaceImportFrom(self, asNamespace(ns)) : replacing previous import: xtabs 3: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called 'car' > acorn=read.table(file.choose(),header=T) > acorn Species Region Range Acorn_size Tree_Height 1 Quercus_alba_L. Atlantic 24196 1.4 27.0 2 Quercus_bicolor_Willd. Atlantic 7900 3.4 21.0 3 Quercus_macrocarpa_Michx. Atlantic 23038 9.1 25.0 4 Quercus_prinoides_Willd. Atlantic 17042 1.6 3.0 5 Quercus_Prinus_L. Atlantic 7646 10.5 24.0 6 Quercus_stellata_Wang. Atlantic 19938 2.5 17.0 7 Quercus_virginiana_Mill Atlantic 7985 0.9 15.0 8 Quercus_Michauxii_Nutt. Atlantic 8897 6.8 0.3 9 Quercus_lyrata_Walt. Atlantic 8982 1.8 24.0 10 Quercus_Laceyi_Small. Atlantic 233 0.3 11.0 11 Quercus_Chapmanii_Sarg. Atlantic 1598 0.9 15.0 12 Quercus_Durandii_Buckl. Atlantic 1745 0.8 23.0 13 Quercus_Muehlenbergii_Engelm Atlantic 17042 2.0 24.0 14 Quercus_ilicifolia_Wang. Atlantic 4082 1.1 3.0 15 Quercus_incana_Bartr. Atlantic 3775 0.6 13.0 16 Quercus_falcata_Michx. Atlantic 13688 1.8 30.0 17 Quercus_laevis_Walt. Atlantic 3978 4.8 9.0 18 Quercus_laurifolia_Michx. Atlantic 5328 1.1 27.0 19 Quercus_marilandica_Muenchh. Atlantic 18480 3.6 9.0 20 Quercus_nigra_L. Atlantic 10161 1.1 24.0 21 Quercus_palustris_Muenchh. Atlantic 8643 1.1 23.0 22 Quercus_Phellos_L. Atlantic 9920 3.6 27.0 23 Quercus_rubra_L. Atlantic 28389 8.1 24.0 24 Quercus_velutina_Lam. Atlantic 21067 3.6 23.0 25 Quercus_imbricaria_Michx. Atlantic 14870 1.8 18.0 26 Quercus_myrtifolia_Willd. Atlantic 2540 0.4 9.0 27 Quercus_texana_Buckl. Atlantic 829 1.1 9.0 28 Quercus_coccinea_Muenchh. Atlantic 8992 1.2 4.0 29 Quercus_Douglasii_Hook._Arn California 559 4.1 18.0 30 Quercus_dumosa_Nutt. California 433 1.6 6.0 31 Quercus_Engelmannii_Greene California 259 2.0 17.0 32 Quercus_Garryana_Hook. California 1061 5.5 20.0 33 Quercus_lobata_Nee California 870 5.9 30.0 34 Quercus_agrifolia_Nee. California 803 2.6 23.0 35 Quercus_Kelloggii_Newb. California 826 6.0 26.0 36 Quercus_Wislizenii_A._DC. California 699 1.0 21.0 37 Quercus_chrysolepis_Liebm. California 690 17.1 15.0 38 Quercus_vaccinifolia_Engelm. California 223 0.4 1.0 39 Quercus_tomentella_Engelm California 13 7.1 18.0 > str(acorn) 'data.frame': 39 obs. of 5 variables: $ Species : Factor w/ 39 levels "Quercus_agrifolia_Nee.",..: 2 3 22 30 31 33 38 24 21 17 ... $ Region : Factor w/ 2 levels "Atlantic","California": 1 1 1 1 1 1 1 1 1 1 ... $ Range : int 24196 7900 23038 17042 7646 19938 7985 8897 8982 233 ... $ Acorn_size : num 1.4 3.4 9.1 1.6 10.5 2.5 0.9 6.8 1.8 0.3 ... $ Tree_Height: num 27 21 25 3 24 17 15 0.3 24 11 ... > sapply(split(Acorn_size,Region),mean) Error in split(Acorn_size, Region) : object "Acorn_size" not found > attach(acorn) > sapply(split(Acorn_size,Region),mean) Atlantic California 2.8 4.8 > sapply(split(Acorn_size,Region),sd) Atlantic California 2.7 4.7 > xyplot(Acorn_size,Region) Error in UseMethod("xyplot") : no applicable method for "xyplot" > xyplot(Acorn_size~Region) > xyplot(Acorn_size~Range) > xyplot(Acorn_size~Range) > xyplot(Acorn_size~Range,groups=Region) > xyplot(Acorn_size~Range,groups=Region, pch=c(1,3), key=list(space='top',columns=2,text=list(levels(Region)),points=list(col)=trellis.par.get('superpose.symbol')$col[1:2],pch=c(1,3)))) Error: unexpected '=' in "xyplot(Acorn_size~Range,groups=Region, pch=c(1,3), key=list(space='top',columns=2,text=list(levels(Region)),points=list(col)=" > xyplot(Acorn_size~Range,groups=Region, pch=c(1,3), key=list(space='top',columns=2,text=list(levels(Region)),points=list(col)=trellis.par.get('superpose.symbol')$col[1:2],pch=c(1,3)))xyplot(Acorn_size~Range, groups=Region, pch=c(1,3), key=list(space='top', columes=2, text=list(levels(Region)), points=list(col=trellis.par.get('superpose.symbol')$col[1:2], pch=c(1,3)) ) )) Error: unexpected '=' in "xyplot(Acorn_size~Range,groups=Region, pch=c(1,3), key=list(space='top',columns=2,text=list(levels(Region)),points=list(col)=" > xyplot(Acorn_size~Range, groups=Region, pch=c(1,3), key=list(space='top', columes=2, text=list(levels(Region)), points=list(col=trellis.par.get('superpose.symbol')$col[1:2], pch=c(1,3)) ) ) > xyplot(Acorn_size~Range,groups=Region,auto.key=T) > xyplot(Acorn_size~Range,groups=Region,auto.key=T) > xyplot(Acorn_size~Range,groups=Region,pch=c(1,3),auto.key=T) > xyplot(Acorn_size~Range,groups=Region) > xyplot(Acorn_size~Range,groups=Region,type=c('p','r')) > xyplot(Acorn_size~Range,groups=Region,type=c('p','l')) > xyplot(Acorn_size~Range,groups=Region,type=c('p','r')) > > detach(acorn) > lm1=lm(Acorn_size~grange, data=acorn[1:28,]) Error in eval(expr, envir, enclos) : object "grange" not found > lm1=lm(Acorn_size~Range, data=acorn[1:28,]) > display(lm1) lm(formula = Acorn_size ~ Range, data = acorn[1:28, ]) coef.est coef.se (Intercept) 1.15 0.82 Range 0.00 0.00 --- n = 28, k = 2 residual sd = 2.52, R-Squared = 0.18 > lm1=lm(Acorn_size~Range, data=acorn[Region=='Atlantic',]]) Error: unexpected ']' in "lm1=lm(Acorn_size~Range, data=acorn[Region=='Atlantic',]]" > > lm1=lm(Acorn_size~Range, data=acorn[Region=='Atlantic',]) Error in `[.data.frame`(acorn, Region == "Atlantic", ) : object "Region" not found > attach(acorn) > lm1=lm(Acorn_size~Range, data=acorn[Region=='Atlantic',]) > display(lm1) lm(formula = Acorn_size ~ Range, data = acorn[Region == "Atlantic", ]) coef.est coef.se (Intercept) 1.15 0.82 Range 0.00 0.00 --- n = 28, k = 2 residual sd = 2.52, R-Squared = 0.18 > summary(lm1) Call: lm(formula = Acorn_size ~ Range, data = acorn[Region == "Atlantic", ]) Residuals: Min 1Q Median 3Q Max -3.352 -1.400 -0.765 0.114 8.212 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.149423 0.819290 1.4 0.172 Range 0.000149 0.000062 2.4 0.024 * --- Signif. codes: 0 ?**?0.001 ?*?0.01 ??0.05 ??0.1 ??1 Residual standard error: 2.5 on 26 degrees of freedom Multiple R-Squared: 0.181, Adjusted R-squared: 0.15 F-statistic: 5.76 on 1 and 26 DF, p-value: 0.0238 > display(lm1,digit=5) lm(formula = Acorn_size ~ Range, data = acorn[Region == "Atlantic", ]) coef.est coef.se (Intercept) 1.14942 0.81929 Range 0.00015 0.00006 --- n = 28, k = 2 residual sd = 2.51871, R-Squared = 0.18 > lm2=lm(log(Acorn_size)~Range, data=acorn[Region=='Atlantic',]) > display(lm2) lm(formula = log(Acorn_size) ~ Range, data = acorn[Region == "Atlantic", ]) coef.est coef.se (Intercept) -0.10 0.25 Range 0.00 0.00 --- n = 28, k = 2 residual sd = 0.77, R-Squared = 0.32 > display(lm2,digit=6) lm(formula = log(Acorn_size) ~ Range, data = acorn[Region == "Atlantic", ]) coef.est coef.se (Intercept) -1.0e-01 2.5e-01 Range 6.6e-05 1.9e-05 --- n = 28, k = 2 residual sd = 0.765807, R-Squared = 0.32 > xyplot(log(Acorn_size)~Range, data=acorn[1:28,],type=c('p','r')) > xyplot(log(Acorn_size)~log(Range), data=acorn[1:28,],type=c('p','r')) > lm3=lm(log(Acorn_size)~log(Range), data=acorn[Region=='Atlantic',]) > display(lm3) lm(formula = log(Acorn_size) ~ log(Range), data = acorn[Region == "Atlantic", ]) coef.est coef.se (Intercept) -3.92 1.12 log(Range) 0.51 0.13 --- n = 28, k = 2 residual sd = 0.73, R-Squared = 0.39 > > lm4=lm(log(Acorn_size)~log(Range),data=acorn) > display standardGeneric for "display" defined from package "arm" function (object, ...) standardGeneric("display") Methods may be defined for arguments: object > display(lm4) lm(formula = log(Acorn_size) ~ log(Range), data = acorn) coef.est coef.se (Intercept) 0.40 0.76 log(Range) 0.04 0.09 --- n = 39, k = 2 residual sd = 0.98, R-Squared = 0.01 > xyplot(log(Acorn_size)~log(Range),data=acorn,type=c('p','r')) > lm4=lm(log(Acorn_size)~log(Range)+Region,data=acorn) > lm5=lm(log(Acorn_size)~log(Range)+Region,data=acorn) > display standardGeneric for "display" defined from package "arm" function (object, ...) standardGeneric("display") Methods may be defined for arguments: object > display(lm5) lm(formula = log(Acorn_size) ~ log(Range) + Region, data = acorn) coef.est coef.se (Intercept) -2.54 1.11 log(Range) 0.35 0.12 RegionCalifornia 1.56 0.47 --- n = 39, k = 3 residual sd = 0.87, R-Squared = 0.24 > xyplot(log(Acorn_size)~log(Range),groups=Region,data=acorn,type=c('p','r')) > xyplot(log(Acorn_size)~log(Range),groups=Region,data=acorn) > xyplot(log(Acorn_size)~log(Range),groups=Region,data=acorn,type=c('p','r')) > lm6=lm(log(Acorn_size)~log(Range)*Region,data=acorn) > display(lm6) lm(formula = log(Acorn_size) ~ log(Range) * Region, data = acorn) coef.est coef.se (Intercept) -3.92 1.30 log(Range) 0.51 0.14 RegionCalifornia 4.96 1.84 log(Range):RegionCalifornia -0.49 0.26 --- n = 39, k = 4 residual sd = 0.84, R-Squared = 0.31 > lm7=lm(log(Acorn_size)~log(Range)*Region,data=acorn[-39,]) > display(lm7 + ) lm(formula = log(Acorn_size) ~ log(Range) * Region, data = acorn[-39, ]) coef.est coef.se (Intercept) -3.92 1.17 log(Range) 0.51 0.13 RegionCalifornia -3.64 3.28 log(Range):RegionCalifornia 0.85 0.50 --- n = 38, k = 4 residual sd = 0.76, R-Squared = 0.43 > xyplot(log(Acorn_size)~log(Range),groups=Region,data=acorn[-39,],type=c('p','r')) > 0.51+0.85 [1] 1.4 > predict(lm7,data.frame(Region='California',Range=1000))) Error: unexpected ')' in "predict(lm7,data.frame(Region='California',Range=1000)))" > predict(lm7,data.frame(Region='California',Range=1000)) [1] 1.8 > predict(lm7,data.frame(Region='California',Range=10000)) [1] 4.9 > exp(predict(lm7,data.frame(Region='California',Range=1000))) [1] 6.2 >