xx <- rep(1:10,rep(10,10)) yy <- 3 + 2*xx + rnorm(length(xx)) plot(xx,yy) my.fit <- lm(yy~xx) abline(my.fit) system("pwd") system("ls") system("ls -l") system("cd /Users/baileraj/Documents/Bailer") # note case sensitivity ... system("pwd") objects() save.image("/Users/baileraj/Documents/Bailer/R-class-test.Rdata") # quit but don’t save image # Restart R ... objects() load("/Users/baileraj/Documents/Bailer/R-class-test.Rdata") objects() # can also save history file and load history file – savehistory/loadhistory # Packages ... # to get a new package ... # .... CRAN website (under “Packages”) # ... MENU control Packages > Install packages(s) [ then you select the package – e.g. Rcmdr ] # ... ... ... “dependencies=TRUE” often useful since this also installs other packages that are needed # need to load the package after it is downloaded - “library” function or menu selection Packages > Load packages # WARNING ... It can take a while to download packages, especially those with lots of dependencies ... > names(my.fit) [1] "coefficients" "residuals" "effects" "rank" "fitted.values" "assign" "qr" [8] "df.residual" "xlevels" "call" "terms" "model" > summary(my.fit) Call: lm(formula = yy ~ xx) Residuals: Min 1Q Median 3Q Max -1.93168 -0.64988 0.00717 0.68510 1.68425 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.13884 0.19131 16.41 <2e-16 *** xx 1.95831 0.03083 63.52 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.8856 on 98 degrees of freedom Multiple R-squared: 0.9763, Adjusted R-squared: 0.976 F-statistic: 4034 on 1 and 98 DF, p-value: < 2.2e-16 > anova(my.fit) Analysis of Variance Table Response: yy Df Sum Sq Mean Sq F value Pr(>F) xx 1 3163.9 3163.9 4034.1 < 2.2e-16 *** Residuals 98 76.9 0.8 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > summary(yy) Min. 1st Qu. Median Mean 3rd Qu. Max. 3.511 9.414 13.460 13.910 18.530 24.330 > summary(xx) Min. 1st Qu. Median Mean 3rd Qu. Max. 1.0 3.0 5.5 5.5 8.0 10.0 > summary(my.fit) Call: lm(formula = yy ~ xx) Residuals: Min 1Q Median 3Q Max -1.93168 -0.64988 0.00717 0.68510 1.68425 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.13884 0.19131 16.41 <2e-16 *** xx 1.95831 0.03083 63.52 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.8856 on 98 degrees of freedom Multiple R-squared: 0.9763, Adjusted R-squared: 0.976 F-statistic: 4034 on 1 and 98 DF, p-value: < 2.2e-16