Sei sulla pagina 1di 11

> ## importing all the data

>
> source("C:\\Users\\Stark\\Desktop\\table1.txt")
Error in source("C:\\Users\\Stark\\Desktop\\table1.txt") :
C:\Users\Stark\Desktop\table1.txt:1:17: unexpected symbol
1: observation

^
> pesawat = read.table("C:\\Users\\Stark\\Desktop\\table1.txt" , header = TRUE)
> pesawat
observation y x1 x2 x3 x4 x5 x6
1

1 4540 2140 20640 30250 205 1732 99

2 4315 2016 20280 30010 195 1697 100

3 4095 1905 19860 29780 184 1662 97

4 3650 1675 18980 29330 164 1598 97

5 3200 1474 18100 28960 144 1541 97

6 4833 2239 20740 30083 216 1709 87

7 4617 2120 20305 29831 206 1669 87

8 4340 1990 19961 29604 196 1640 87

9 3820 1702 18916 29088 171 1572 85

10

10 3368 1487 18012 28675 149 1522 85

11

11 4445 2107 20520 30120 195 1740 101

12

12 4188 1973 20130 29920 190 1711 100

13

13 3981 1864 19780 29720 180 1682 100

14

14 3622 1674 19020 29370 161 1630 100

15

15 3125 1440 18030 28940 139 1572 101

16

16 4560 2165 20680 30160 208 1704 98

17

17 4340 2048 20340 29960 199 1679 96

18

18 4115 1916 19860 29710 187 1642 94

19

19 3630 1658 18950 29250 164 1576 94

20

20 3210 1489 18700 28890 145 1528 94

21

21 4330 2062 20500 30190 193 1748 101

22

22 4119 1929 20050 29960 183 1713 100

23

23 3891 1815 19680 29770 173 1684 100

24

24 3467 1595 18890 29360 153 1624 99

25

25 3045 1400 17870 28960 134 1569 100

26

26 4411 2047 20540 30160 193 1746 99

27

27 4203 1935 20160 29940 184 1714 99

28

28 3968 1807 19750 29760 173 1679 99

29

29 3531 1591 18890 29350 153 1621 99

30

30 3074 1388 17870 28910 133 1561 99

31

31 4350 2071 20460 30180 198 1729 100

32

32 4128 1944 20010 29940 186 1692 101

33

33 3940 1831 19640 29750 178 1667 101

34

34 3480 1612 18710 29360 156 1609 101

35

35 3064 1410 17780 28900 136 1552 101

36

36 4402 2066 20520 30170 197 1758 100

37

37 4180 1954 20150 29950 188 1729 99

38

38 3973 1835 19750 29740 178 1690 99

39

39 3530 1616 18850 29320 156 1616 99

40

40 3080 1407 17910 28910 137 1569 100

>
> ## simplify for only required data that had been given
>
> mirage = c("y","x1","x5")
> sukhoi = pesawat[mirage]
> sukhoi
y x1 x5
1 4540 2140 1732
2 4315 2016 1697
3 4095 1905 1662
4 3650 1675 1598
5 3200 1474 1541
6 4833 2239 1709
7 4617 2120 1669
8 4340 1990 1640
9 3820 1702 1572
10 3368 1487 1522
11 4445 2107 1740
12 4188 1973 1711
13 3981 1864 1682
14 3622 1674 1630
15 3125 1440 1572

16 4560 2165 1704


17 4340 2048 1679
18 4115 1916 1642
19 3630 1658 1576
20 3210 1489 1528
21 4330 2062 1748
22 4119 1929 1713
23 3891 1815 1684
24 3467 1595 1624
25 3045 1400 1569
26 4411 2047 1746
27 4203 1935 1714
28 3968 1807 1679
29 3531 1591 1621
30 3074 1388 1561
31 4350 2071 1729
32 4128 1944 1692
33 3940 1831 1667
34 3480 1612 1609
35 3064 1410 1552
36 4402 2066 1758
37 4180 1954 1729
38 3973 1835 1690
39 3530 1616 1616

40 3080 1407 1569


>
> ## write in one line form
>
> y<c(4540,4315,4095,3650,3200,4833,4617,4340,3820,3368,4445,4188,3981,3622,3125,4560,4340,4115
,3630,3210,4330,4119,3891,3467,3045,4411,4203,3968,3531,3074,4350,4128,3940,3480,3064,4402,
4180,3973,3530,3080)
> x1<c(2140,2016,1905,1675,1474,2239,2120,1990,1702,1487,2107,1973,1864,1674,1440,2165,2048,1916
,1658,1489,2062,1929,1815,1595,1400,2047,1935,1807,1591,1388,2071,1944,1831,1612,1410,2066,
1954,1835,1616,1407)
> x5<c(1732,1697,1662,1598,1541,1709,1669,1640,1572,1522,1740,1711,1682,1630,1572,1704,1679,1642
,1576,1528,1748,1713,1684,1624,1569,1746,1714,1679,1621,1561,1729,1692,1667,1609,1522,1758,
1729,1690,1616,1569)
>
> ## DESCRIPTIVE STATISTIC
>
> ## Mean
> mean(y)
[1] 3904
> mean(x1)
[1] 1809.925
> mean(x5)
[1] 1651.15
>

> ## Variance
> var(y)
[1] 254667.6
> var(x1)
[1] 63479.05
> var(x5)
[1] 4922.849
>
> ## Standard Deviation
> sd(y)
[1] 504.646
> sd(x1)
[1] 251.9505
> sd(x5)
[1] 70.16302
>
> ## In summary
> colMeans(sukhoi)
y

x1

x5

3904.000 1809.925 1651.900


> sd(sukhoi)
y

x1

x5

504.64600 251.95048 68.89598


Warning message:

sd(<data.frame>) is deprecated.
Use sapply(*, sd) instead.
>
> ## Stem
> stem(y)

The decimal point is 2 digit(s) to the right of the |

30 | 56783
32 | 017
34 | 7833
36 | 235
38 | 294778
40 | 022389
42 | 023445
44 | 01546
46 | 2
48 | 3

> stem(x1)

The decimal point is 2 digit(s) to the right of the |

13 | 9

14 | 0114799
15 | 9
16 | 012678
17 | 0
18 | 12346
19 | 12344579
20 | 255677
21 | 1247
22 | 4

> stem(x5)

The decimal point is 1 digit(s) to the right of the |

152 | 228
154 | 1
156 | 199226
158 | 8
160 | 96
162 | 140
164 | 02
166 | 27999
168 | 24027
170 | 49134

172 | 992
174 | 0688

> boxplot(sukhoi)
> boxplot(y)
> boxplot(x1)
> boxplot(x5)
>
> ## Histogram
> hist(y)
> hist(x1)
> hist(x5)
>
> ## CORRELATION AND REGRESSION
> ## check the linearity of the data
> plot(sukhoi)
>
> ## fitting multiple linear regression
> regression = lm(y ~ x1 + x5 , data = sukhoi)
> regression

Call:
lm(formula = y ~ x1 + x5, data = sukhoi)

Coefficients:
(Intercept)

x1

1085.9051

2.1525

x5
-0.6524

> summary(regression)

Call:
lm(formula = y ~ x1 + x5, data = sukhoi)

Residuals:
Min

1Q Median

3Q

Max

-84.055 -31.774 -3.063 24.966 96.178

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1085.90511 302.33023 3.592 0.00095 ***
x1

2.15245 0.06722 32.023 < 2e-16 ***

x5

-0.65239 0.24581 -2.654 0.01165 *

--Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

Residual standard error: 47.38 on 37 degrees of freedom


Multiple R-squared: 0.9916,

Adjusted R-squared: 0.9912

F-statistic: 2194 on 2 and 37 DF, p-value: < 2.2e-16

>
> ## Analysis of Variance (ANOVA)
> ## One - Way ANOVA
> ## ANOVA Table
>
> anova(regression)
Analysis of Variance Table

Response: y
Df Sum Sq Mean Sq F value Pr(>F)
x1

1 9833160 9833160 4380.1520 < 2e-16 ***

x5

1 15814 15814 7.0442 0.01165 *

Residuals 37 83063 2245


--Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
>
> plot(regression)
Waiting to confirm page change...
Waiting to confirm page change...
Waiting to confirm page change...
Waiting to confirm page change...
>

Potrebbero piacerti anche