R语言基础.pptVIP

  • 51
  • 0
  • 约6.82千字
  • 约 54页
  • 2016-08-23 发布于河南
  • 举报
R语言基础

统计软件和R语言 内容提要 1. 统计软件种类 SPSS SAS R软件: 为什么用R 3.相关研究方向 1.3 R里面有什么? 2. R快速入门 2.2 产生向量 向量的运算 2.3 多维数组或矩阵 矩阵下标 矩阵的运算 矩阵的运算 练习: 2.4 R程序控制流 2.4 R程序控制流 练习1: 3. R统计分析和图形 一些常用的数学和统计函数 最大值max(), 最小值min(), 均值mean(), 标准差sd(), 方差var(), 相关系数cor(), 求和sum(), 积prod(), 中位数 median(), 分位数quantile(), 累加cumsum(), 秩rank()… 统计分布的函数: pnorm(), dnorm(), qnorm(),rnorm() … (p, d, q, r+分布名称分别构成:分布函数值、密度函数 值、分位数、随机数,如pf()表示F分布函数值,runif()表 示产生均匀分布的随机数) 多用帮助! ?mean mean(x, trim = 0, na.rm = FALSE, ...) trim: the fraction (0 to 0.5) of observations to be trimmed from each end of x before the mean is computed. x = runif(100); y = 0.2*x + 0.1*rnorm(100) fit = lm(y ~ x) summary(fit) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -0.222887 -0.054245 -0.008861 0.060522 0.262948 3.1 例子:linear regression Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0.006232 0.020035 -0.311 0.756 x 0.212069 0.036036 5.885 5.56e-08 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 0.09378 on 98 degrees of freedom Multiple R-Squared: 0.2611, Adjusted R-squared: 0.2536 F-statistic: 34.63 on 1 and 98 DF, p-value: 5.565e-08 plot(x, y); abline(fit) y.res-resid(fit) ; y.fit-predict(fit) plot(y.res~y.fit) qqnorm(y.res) fit = lm(y ~ x + I(x^2)) # 高次的回归,注意I() summary(fit) Call: lm(formula = y ~ x + I(x^2)) Residuals: Min 1Q Median 3Q Max -0.8841 -0.7138 -0.1118 0.7174 1.1166 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0.11633 0.02707 -4.298 1.81e-05 *** x -0.02557 0.02311 -1.106 0.26867 I(x^2) 0.13428 0.04528 2.966 0.00306 ** Residual standard error: 0.7169 on 1997 degrees of freedom Multiple R-Squared: 0.00502, Adjusted R-squared: 0.004024 F-statistic: 5.038 on 2 an

文档评论(0)

1亿VIP精品文档

相关文档