R
-
- 2007
:
, ..,
..,
..
- , . R, , . - .
4
1. R 5
2. 7
2.1. 7
2.2. 7
2.3. 8
3. 9
3.1. 2 ( ). 10
3.2. ( ). 13
3.3. ( , ). 14
3.4. ( ). 17
4. 19
5. 22
5.1. . 22
5.2. 23
6. 25
. 28
, R.
R , (1996, J.Comput. . Stat., 5: 299-314).R ; :
,
, , ,
, , ,
,
, .
R - S AT&T . S S-PLUS MathSoft (.http://www.splus.mathsoft.com ). R S (, , Gentleman Ihaka (1996) R-FAQ ( ) (http://cran.r-project.org/doc/FAQ/R-FAQ.html).
|
|
R : , C ( Fortran77) .
R , (, jpg, png, bmp, eps, wmf Windows, ps, bmp, pictex Unix).
. (P- values, ..) .
R , , . , .
R
base . , R. . , , :
URL: http://cran.rproject.org/src/contrib/PACKAGES.html.
base :
lm ;
glm ;
aov, anova ;
stats , glm , , , . nlme, mgcv .
, x y , y x:
> x <-1:5
> y <-rnorm (5)
> lm (y~x)
Call:
lm (formula = y ~ x)
Coefficients(:):
Intercept x
0.2252 0.1809
lm (y~x) :
> mymodel<-lm (y~x)
R , summary() ( ...), residuals() , predict()- , coef() .
> summary(mymodel)
lm(formula = y ~ x)
Residuals:
1 2 3 4 5
1.0070 -1.0711 -0.2299 -0.3550 0.6490
Coefficients (:):
Estimate Std. Error t value Pr(>|t|)( . t value P value (> |t |))
(Intercept) 0.2252 1.0062 0.224 0.837
x 0.1809 0.3034 0.596 0.593
Residual standard error(): 0.9594 on 3 degrees of freedom
Multiple R-Squared ( R2): 0.1059, Adjusted R-squared ( R2): -0.1921
F-statistic: 0.3555 on 1 and 3 degrees of freedom( 1 3 ), p-value: 0.593
> residuals (mymodel)
1 2 3 4 5
1.0070047 -1.0710587 -0.2299374 -0.3549681 0.6489594
> predict(mymodel)
1 2 3 4 5
0.4061329 0.5870257 0.7679186 0.9488115 1.1297044
> coef(mymodel)
(Intercept) x
0.2252400 0.1808929
, :
|
|
> a <-coef (mymodel) [1]
> b <-coef (mymodel) [2]
> newdata <-c (11, 13, 18)
> a+ b*newdata
[1] 2.215062 2.576847 3.481312
, names (); , R.
> names (mymodel)
[1] "coef" "residuals" "effects" "rank"
[5] "fitted.values" "assign" "qr" "df.residual"
[9] "xlevels" "call" "terms" "model"
> names(summary (mymodel))
[1] "call" "terms" "residuals" "coef"
[5] "sigma" "df" "r.squared" "adj.r.squared"
[9] "fstatistic" "cov.unscaled"
:
> summary(mymodel) ["r.squared"]
$r.squared
[1] 0.09504547
R. . y ~ , y ‑ , .
, .
a+b ‑ b
a:b ‑ b
a*b ‑ a+b+a:b
poly(a,n) ‑ n
^n ‑ n, (a+b+c) ^2 a+b+c+a:b+a:c+b:c
b%in%a‑ b ( a+a:b)
a-b ‑ b, : (a+b+c) ^n-a:b a+b+c+a:c+b:c, y~x-1 (. y~x+0, 0+y~x)
, R . , y~x1+x2 y = b1x1 +b2x2 + a. , i(): y~I(x1+x2) y = b (x1 + x2) + a.
xcp . 1, 2, ,n n ,
mean(x,...)
x | , data.frame. |
> x<-c(3.6,7.8,9.6,5.7,8.9)
> mean(x)
7.12 ( )