一、緒論

1.背景:有31個砍伐的黑櫻桃樹,測量它們木材的的長度、高度和體積。

2.問題/動機:我們給定3棵樹(我們假設的),它們的高度分別為40、60、80,想找出它們的高度跟體積,然後去發現它們之間的關係,想了解如果一棵樹體積越大它的寬是不是越大,高度也是不是越大,它們是成正比關係。

3.結果簡述:發現並不是每顆樹都是體積越大,高度越大,也有體積大,但高度小,但是整體而言,高度跟體積是成正比的,長度跟高度也是呈正比的。

二、結果

1.資料介紹:利用R package 裡的一些code以及老師上課使用的code語法。

2.程式碼:

先叫出R package

attach(trees)
The following objects are masked from trees (pos = 3):

    Girth, Height, Volume

The following objects are masked from trees (pos = 4):

    Girth, Height, Volume

The following objects are masked from trees (pos = 5):

    Girth, Height, Volume

The following objects are masked from trees (pos = 7):

    Girth, Height, Volume

The following objects are masked from trees (pos = 8):

    Girth, Height, Volume

The following objects are masked from trees (pos = 9):

    Girth, Height, Volume

The following objects are masked from trees (pos = 10):

    Girth, Height, Volume

The following objects are masked from trees (pos = 11):

    Girth, Height, Volume

The following objects are masked from trees (pos = 12):

    Girth, Height, Volume

The following objects are masked from trees (pos = 13):

    Girth, Height, Volume

The following objects are masked from trees (pos = 14):

    Girth, Height, Volume

The following objects are masked from trees (pos = 15):

    Girth, Height, Volume

The following objects are masked from trees (pos = 16):

    Girth, Height, Volume

The following objects are masked from trees (pos = 17):

    Girth, Height, Volume
names(trees)   # list varibles of trees
[1] "Girth"  "Height" "Volume"
plot(trees) 

summary(trees)
     Girth           Height       Volume     
 Min.   : 8.30   Min.   :63   Min.   :10.20  
 1st Qu.:11.05   1st Qu.:72   1st Qu.:19.40  
 Median :12.90   Median :76   Median :24.20  
 Mean   :13.25   Mean   :76   Mean   :30.17  
 3rd Qu.:15.25   3rd Qu.:80   3rd Qu.:37.30  
 Max.   :20.60   Max.   :87   Max.   :77.00  
head(trees)# view first few lines of the dataset
dim(trees)# get data dimensions
[1] 31  3
str(trees)# display an internal structure of an R object
'data.frame':   31 obs. of  3 variables:
 $ Girth : num  8.3 8.6 8.8 10.5 10.7 10.8 11 11 11.1 11.2 ...
 $ Height: num  70 65 63 72 81 83 66 75 80 75 ...
 $ Volume: num  10.3 10.3 10.2 16.4 18.8 19.7 15.6 18.2 22.6 19.9 ...

Girth~Height的線性圖

attach(trees)
The following objects are masked from trees (pos = 3):

    Girth, Height, Volume

The following objects are masked from trees (pos = 4):

    Girth, Height, Volume

The following objects are masked from trees (pos = 5):

    Girth, Height, Volume

The following objects are masked from trees (pos = 6):

    Girth, Height, Volume

The following objects are masked from trees (pos = 8):

    Girth, Height, Volume

The following objects are masked from trees (pos = 9):

    Girth, Height, Volume

The following objects are masked from trees (pos = 10):

    Girth, Height, Volume

The following objects are masked from trees (pos = 11):

    Girth, Height, Volume

The following objects are masked from trees (pos = 12):

    Girth, Height, Volume

The following objects are masked from trees (pos = 13):

    Girth, Height, Volume

The following objects are masked from trees (pos = 14):

    Girth, Height, Volume

The following objects are masked from trees (pos = 15):

    Girth, Height, Volume

The following objects are masked from trees (pos = 16):

    Girth, Height, Volume

The following objects are masked from trees (pos = 17):

    Girth, Height, Volume

The following objects are masked from trees (pos = 18):

    Girth, Height, Volume
fm1 <- lm(Girth~Height)
summary(fm1)

Call:
lm(formula = Girth ~ Height)

Residuals:
    Min      1Q  Median      3Q     Max 
-4.2386 -1.9205 -0.0714  2.7450  4.5384 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept) -6.18839    5.96020  -1.038  0.30772   
Height       0.25575    0.07816   3.272  0.00276 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.728 on 29 degrees of freedom
Multiple R-squared:  0.2697,    Adjusted R-squared:  0.2445 
F-statistic: 10.71 on 1 and 29 DF,  p-value: 0.002758
plot(Girth~Height)
abline(fm1)

找出長度跟高度的線性關係以及求出長度

a=40
y=0.25575*a-6.18839
y
[1] 4.04161
b=60
y=0.25575*b-6.18839
y
[1] 9.15661
c=80
y=0.25575*c-6.18839
y
[1] 14.27161

Volume~Height的線性圖

attach(trees)
The following objects are masked from trees (pos = 3):

    Girth, Height, Volume

The following objects are masked from trees (pos = 4):

    Girth, Height, Volume

The following objects are masked from trees (pos = 5):

    Girth, Height, Volume

The following objects are masked from trees (pos = 6):

    Girth, Height, Volume

The following objects are masked from trees (pos = 7):

    Girth, Height, Volume

The following objects are masked from trees (pos = 9):

    Girth, Height, Volume

The following objects are masked from trees (pos = 10):

    Girth, Height, Volume

The following objects are masked from trees (pos = 11):

    Girth, Height, Volume

The following objects are masked from trees (pos = 12):

    Girth, Height, Volume

The following objects are masked from trees (pos = 13):

    Girth, Height, Volume

The following objects are masked from trees (pos = 14):

    Girth, Height, Volume

The following objects are masked from trees (pos = 15):

    Girth, Height, Volume

The following objects are masked from trees (pos = 16):

    Girth, Height, Volume

The following objects are masked from trees (pos = 17):

    Girth, Height, Volume

The following objects are masked from trees (pos = 18):

    Girth, Height, Volume

The following objects are masked from trees (pos = 19):

    Girth, Height, Volume
fm2 <- lm(Volume~Height)
summary(fm2)

Call:
lm(formula = Volume ~ Height)

Residuals:
    Min      1Q  Median      3Q     Max 
-21.274  -9.894  -2.894  12.068  29.852 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -87.1236    29.2731  -2.976 0.005835 ** 
Height        1.5433     0.3839   4.021 0.000378 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 13.4 on 29 degrees of freedom
Multiple R-squared:  0.3579,    Adjusted R-squared:  0.3358 
F-statistic: 16.16 on 1 and 29 DF,  p-value: 0.0003784
plot(Volume ~ Height)
abline(fm2)

找出體積跟高度的線性關係以及求出體積

a=40
y=1.5433*a-87.1236
y
[1] -25.3916
b=60
y=1.5433*b-87.1236
y
[1] 5.4744
c=80
y=1.5433*c-87.1236
y
[1] 36.3404

三、結論與討論:

發現並不是每顆樹都是體積越大,高度越大,也有體積大,但高度小,但是整體而言,高度跟體積是成正比的,長度跟高度也是呈正比的,我們假設的三棵樹高度分別為40、60、80,它們長度分別為4.04161、9.15661、14.27161,體積分別為 -25.3916、5.4744、36.3404,我們發現40高度這棵樹的體積為負數,體積不為負數,所以此數據錯誤,我們覺得可能因為這31棵樹裡面沒有高度較小樹的數據,所以產生錯誤,產生數據不normal,如果可以的話,這31棵樹應該要normal,不要太平均的高度、長度以及體積,這樣數據才有機會normal,以trees的數據來說,我們總而言之,樹的高度跟長度、體積是會呈正比發展的。

LS0tDQp0aXRsZTogIkZpbmFsIHByb2plY3QgIg0Kb3V0cHV0OiBodG1sX25vdGVib29rDQotLS0NCiMj5LiA44CB57eS6KuWDQojIyMxLuiDjOaZrzrmnIkzMeWAi+egjeS8kOeahOm7kearu+ahg+aoue+8jOa4rOmHj+Wug+WAkeacqOadkOeahOeahOmVt+W6puOAgemrmOW6puWSjOmrlOepjeOAgg0KIyMjMi7llY/poYwv5YuV5qmfOuaIkeWAkee1puWumjPmo7XmqLko5oiR5YCR5YGH6Kit55qEKe+8jOWug+WAkeeahOmrmOW6puWIhuWIpeeCujQw44CBNjDjgIE4MO+8jOaDs+aJvuWHuuWug+WAkeeahOmrmOW6pui3n+mrlOepje+8jOeEtuW+jOWOu+eZvOePvuWug+WAkeS5i+mWk+eahOmXnOS/gu+8jOaDs+S6huino+WmguaenOS4gOajteaouemrlOepjei2iuWkp+Wug+eahOWvrOaYr+S4jeaYr+i2iuWkp++8jOmrmOW6puS5n+aYr+S4jeaYr+i2iuWkp++8jOWug+WAkeaYr+aIkOato+avlOmXnOS/guOAgg0KIyMjMy7ntZDmnpznsKHov7A655m854++5Lim5LiN5piv5q+P6aGG5qi56YO95piv6auU56mN6LaK5aSn77yM6auY5bqm6LaK5aSn77yM5Lmf5pyJ6auU56mN5aSn77yM5L2G6auY5bqm5bCP77yM5L2G5piv5pW06auU6ICM6KiA77yM6auY5bqm6Lef6auU56mN5piv5oiQ5q2j5q+U55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bTIgPC0gbG0oVm9sdW1lfkhlaWdodCkNCnN1bW1hcnkoZm0yKQ0KcGxvdChWb2x1bWUgfiBIZWlnaHQpDQphYmxpbmUoZm0yKQ0KYGBgDQojI+aJvuWHuumrlOepjei3n+mrmOW6pueahOe3muaAp+mXnOS/guS7peWPiuaxguWHuumrlOepjQ0KYGBge3J9DQphPTQwDQp5PTEuNTQzMyphLTg3LjEyMzYNCnkNCmI9NjANCnk9MS41NDMzKmItODcuMTIzNg0KeQ0KYz04MA0KeT0xLjU0MzMqYy04Ny4xMjM2DQp5DQpgYGANCg0KDQojI+S4ieOAgee1kOirluiIh+iojuirljoNCiMjI+eZvOePvuS4puS4jeaYr+avj+mhhuaouemDveaYr+mrlOepjei2iuWkp++8jOmrmOW6pui2iuWkp++8jOS5n+aciemrlOepjeWkp++8jOS9humrmOW6puWwj++8jOS9huaYr+aVtOmrlOiAjOiogO+8jOmrmOW6pui3n+mrlOepjeaYr+aIkOato+avlOeahO+8jOmVt+W6pui3n+mrmOW6puS5n+aYr+WRiOato+avlOeahO+8jOaIkeWAkeWBh+ioreeahOS4ieajteaouemrmOW6puWIhuWIpeeCujQw44CBNjDjgIE4MO+8jOWug+WAkemVt+W6puWIhuWIpeeCujQuMDQxNjHjgIE5LjE1NjYx44CBMTQuMjcxNjHvvIzpq5TnqY3liIbliKXngrogLTI1LjM5MTbjgIE1LjQ3NDTjgIEzNi4zNDA077yM5oiR5YCR55m854++NDDpq5jluqbpgJnmo7XmqLnnmoTpq5TnqY3ngrrosqDmlbjvvIzpq5TnqY3kuI3ngrrosqDmlbjvvIzmiYDku6XmraTmlbjmk5rpjK/oqqTvvIzmiJHlgJHoprrlvpflj6/og73lm6DngrrpgJkzMeajteaoueijoemdouaykuaciemrmOW6pui8g+Wwj+aoueeahOaVuOaTmu+8jOaJgOS7peeUoueUn+mMr+iqpO+8jOeUoueUn+aVuOaTmuS4jW5vcm1hbO+8jOWmguaenOWPr+S7peeahOipse+8jOmAmTMx5qO15qi55oe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