标签:
第一章 概率统计的基本知识
第二章 R软件的使用
第三章 数据描述性分析
第四章 参数估计
第五章 假设检验
第六章 回归分析
第七章 方差分析
第八章 应用多元分析(I)
第九章 应用多元分析(II)
第十章 计算机模拟
2.1 求均值和方差
> X1 <- c(35,40,40,42,37,45,43,37,44,42,41,39) > mean(X1) [1] 40.41667 > sd(X1) [1] 3.028901 > X2 <- c(60,74,64,71,72,68,78,66,70,65,73,75) > mean(X2) [1] 69.66667 > sd(X2) [1] 5.210712
2.2 绘制双变量散点图和单变量直方图
> X1 <- c(35,40,40,42,37,45,43,37,44,42,41,39) > X2 <- c(60,74,64,71,72,68,78,66,70,65,73,75) > plot(X1, X2) > hist(X1) > hist(X2)
2.3 对身高和体重作线性回归分析
> rt <- read.table("exam0203.txt", head=TRUE);rt Name Sex Age Height Weight 1 Alice F 13 56.5 84.0 2 Becka F 13 65.3 98.0 3 Gail F 14 64.3 90.0 4 Karen F 12 56.3 77.0 5 Kathy F 12 59.8 84.5 6 Mary F 15 66.5 112.0 7 Sandy F 11 51.3 50.5 8 Sharon F 15 62.5 112.5 9 Tammy F 14 62.8 102.5 10 Alfred M 14 69.0 112.5 11 Duke M 14 63.5 102.5 12 Guido M 15 67.0 133.0 13 James M 12 57.3 83.0 14 Jeffrey M 13 62.5 84.0 15 John M 12 59.0 99.5 16 Philip M 16 72.0 150.0 17 Robert M 12 64.8 128.0 18 Thomas M 11 57.5 85.0 19 William M 15 66.5 112.0 > lm.sol <- lm(Weight~Height, data=rt) > summary(lm.sol) Call: lm(formula = Weight ~ Height, data = rt) Residuals: Min 1Q Median 3Q Max -17.6807 -6.0642 0.5115 9.2846 18.3698 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -143.0269 32.2746 -4.432 0.000366 *** Height 3.8990 0.5161 7.555 7.89e-07 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 11.23 on 17 degrees of freedom Multiple R-squared: 0.7705, Adjusted R-squared: 0.757 F-statistic: 57.08 on 1 and 17 DF, p-value: 7.887e-07
source("MyFile.R")
load("MyWorkSpace.RData")
save.image("MyWorkSpace.RData")
标签:
原文地址:http://www.cnblogs.com/leezx/p/5679834.html