Sie sind auf Seite 1von 3

R version 3.0.

1 (2013-05-16) -- "Good Sport"


Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin10.8.0 (64-bit)
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.
[R.app GUI 1.61 (6492) x86_64-apple-darwin10.8.0]
[History restored from /Users/aditimemani/.Rapp.history]
> nutrient_levels <- scan()
1: 0 0 0 0 0 20 20 20 20 20 40 40 40 40 40 60 60 60 60 60 80 80 80 80 80 100
100 100 100 100
31:
Read 30 items
> weight_changes <- scan()
1: 52.403 45.864 57.943 54.797 42.174 64.029 54.034 72.921 50.591 64.948
78.585 63.586 63.056 68.515 58.302 77.775 81.211 80.923 87.942 91.031 89.788
105.386 90.079 103.182 91.756 117.913 103.146 105.366 86.177 94.694
31:
Read 30 items
> datal <- data.frame (nutrient_levels,weight_changes)
> (measurements <- data.frame (nutrient_levels,weight_changes))
nutrient_levels weight_changes
1
0
52.403
2
0
45.864
3
0
57.943
4
0
54.797
5
0
42.174
6
20
64.029
7
20
54.034
8
20
72.921
9
20
50.591
10
20
64.948

11
40
78.585
12
40
63.586
13
40
63.056
14
40
68.515
15
40
58.302
16
60
77.775
17
60
81.211
18
60
80.923
19
60
87.942
20
60
91.031
21
80
89.788
22
80
105.386
23
80
90.079
24
80
103.182
25
80
91.756
26
100
117.913
27
100
103.146
28
100
105.366
29
100
86.177
30
100
94.694
> plot(nutrient_levels, weight_changes)
> cor(nutrient_levels, weight_changes)
[1] 0.9186592
> res = lm(weight_changes~nutrient_levels)
> abline(res)
>
> res
Call:
lm(formula = weight_changes ~ nutrient_levels)
Coefficients:
(Intercept)
49.7694

nutrient_levels
0.5367

> (mean_X <- mean(nutrient_levels))


[1] 50
> (mean_Y <- mean(weight_changes))
[1] 76.6039
> (n <- length(nutrient_levels))
[1] 30
> (SS_XX <- (n-1)*var(nutrient_levels))
[1] 35000
> (SS_YY <- (n-1)*var(weight_changes))
[1] 11945.58
> (SS_XY <- (n-1)*cov(nutrient_levels,weight_changes))
[1] 18784.17

> (b1 <- SS_XY/SS_XX)


[1] 0.5366906
> yhat <- b0 + b1*nutrient_levels
Error: object 'b0' not found
> (b0 <- mean_Y-b1*mean_X)
[1] 49.76937
> yhat <- b0 + b1*nutrient_levels
> e <- weight_changes - yhat
> (SSE <- sum(e^2))
[1] 1864.289
> (MSE <- SSE/(n-2))
[1] 66.58176
> (s_b1 <- sqrt(MSE/SS_XX))
[1] 0.04361578
> (t_stat <- b1/s_b1)
[1] 12.30496
> (t_rule <- qt(.95,28))
[1] 1.701131
> (ci_b1 <- c(b1-qt(.975,n-2)*s_b1,b1+qt(.975,n-2)*s_b1))
[1] 0.4473477 0.6260334
> (SSTO <- SS_YY)
[1] 11945.58
> (SSR <- SSTO - SSE)
[1] 10081.29
> (R_square <- SSR/SSTO)
[1] 0.8439348
> cor(nutrient_levels, weight_changes)
[1] 0.9186592
> anova(nutrient_levels)
Error in UseMethod("anova") :
no applicable method for 'anova' applied to an object of class "c('double',
'numeric')"
> anova(res)
Analysis of Variance Table
Response: weight_changes
Df Sum Sq Mean Sq F value
Pr(>F)
nutrient_levels 1 10081.3 10081.3 151.41 8.222e-13 ***
Residuals
28 1864.3
66.6
--Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
>

Das könnte Ihnen auch gefallen