data<-read.csv("G:\\My Drive\\document for each subject\\2nd semester\\931434_forest_wildlife_management\\Inclass Activity\\67\\Deer to R.csv", header=TRUE)Deer analysis
การวิเคราะห์ข้อมูลที่ได้จากเกมกวางกับทรัพยากรแบบจริงจัง ^^
1. การนำเข้าข้อมูล
-ข้อมูลจากเกมที่พวกเราเล่น
data Deer Foods Water Cover
1 6 2 2 2
2 6 1 1 1
3 6 0 2 1
4 4 0 2 1
5 6 2 1 2
6 8 1 2 1
7 4 0 1 1
8 6 4 0 2
9 6 0 3 1
10 6 2 2 0
11 8 3 1 0
12 4 2 0 0
13 8 1 3 2
14 4 1 0 1
15 8 3 1 2
16 4 1 0 1
17 6 4 1 1
18 2 1 1 2
19 4 2 0 0
20 4 4 2 0
21 8 1 2 3
22 4 1 0 1
23 8 3 2 1
24 4 2 0 0
25 8 1 2 3
26 4 2 0 0
27 8 2 3 1
28 4 0 1 1
29 8 2 3 1
30 4 1 0 1
2. เปิดใช้งาน Packages ที่จำเป็นต้องใช้
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(car)Loading required package: carData
Attaching package: 'car'
The following object is masked from 'package:dplyr':
recode
library(ggplot2)3. สร้างกราฟแสดงความสัมพันธ์ของประชากรกวางกับปัจจัยต่างๆ (วิเคราะห์ทีละปัจจัย)
-ประชากรกวางกับจำนวนแหล่งอาหาร
data %>% ggplot(aes(x=Foods, y=Deer)) +
geom_point(color = "#B3C8CF") +
geom_smooth(method = "lm", color = "#295F98", se = FALSE) +
ggtitle("Relationship between foods and deer numbers")+
theme(
axis.line = element_line(color = "#B7B7B7"),
panel.background = element_blank())`geom_smooth()` using formula = 'y ~ x'
LM1<-lm(Deer~Foods, data=data)
summary(LM1)
Call:
lm(formula = Deer ~ Foods, data = data)
Residuals:
Min 1Q Median 3Q Max
-3.4451 -1.4451 -0.1448 1.8552 2.5549
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.0952 0.5677 8.975 9.89e-10 ***
Foods 0.3499 0.2827 1.238 0.226
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.809 on 28 degrees of freedom
Multiple R-squared: 0.05188, Adjusted R-squared: 0.01802
F-statistic: 1.532 on 1 and 28 DF, p-value: 0.2261
-ประชากรกวางกับจำนวนแหล่งน้ำ
data %>% ggplot(aes(x=Water, y=Deer)) +
geom_point(color = "#B3C8CF") +
geom_smooth(method = "lm", color = "#295F98", se = FALSE) +
ggtitle("Relationship between water and deer numbers")+
theme(
axis.line = element_line(color = "#B7B7B7"),
panel.background = element_blank())`geom_smooth()` using formula = 'y ~ x'
LM2<-lm(Deer~Water, data=data)
summary(LM2)
Call:
lm(formula = Deer ~ Water, data = data)
Residuals:
Min 1Q Median 3Q Max
-3.3766 -0.4644 -0.2887 0.6234 2.6234
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.2887 0.4198 10.217 5.98e-11 ***
Water 1.0879 0.2570 4.232 0.000225 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.451 on 28 degrees of freedom
Multiple R-squared: 0.3901, Adjusted R-squared: 0.3684
F-statistic: 17.91 on 1 and 28 DF, p-value: 0.0002248
-ประชากรกวางกับจำนวนที่หลบภัย
data %>% ggplot(aes(x=Cover, y=Deer)) +
geom_point(color = "#B3C8CF") +
geom_smooth(method = "lm", color = "#295F98", se = FALSE) +
ggtitle("Relationship between cover and deer numbers")+
theme(
axis.line = element_line(color = "#B7B7B7"),
panel.background = element_blank())`geom_smooth()` using formula = 'y ~ x'
LM3<-lm(Deer~Cover, data=data)
summary(LM3)
Call:
lm(formula = Deer ~ Cover, data = data)
Residuals:
Min 1Q Median 3Q Max
-4.4058 -1.3792 -0.4058 1.1208 3.2367
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.7633 0.5207 9.148 6.62e-10 ***
Cover 0.8213 0.3777 2.174 0.0383 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.719 on 28 degrees of freedom
Multiple R-squared: 0.1444, Adjusted R-squared: 0.1139
F-statistic: 4.727 on 1 and 28 DF, p-value: 0.03831
4. สร้างสมการความสัมพันธ์ของประชากรกวางกับทรัพยากรต่างๆ (แบบทีละหลายปัจจัย)
-ประชากรกวางกับจำนวนที่หลบภัย แหล่งอาหาร และแหล่งน้ำ
LM4<-lm(Deer~Cover+Foods+Water, data=data)
summary(LM4)
Call:
lm(formula = Deer ~ Cover + Foods + Water, data = data)
Residuals:
Min 1Q Median 3Q Max
-3.5708 -0.3687 0.0799 0.4898 2.5083
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.8019 0.5999 4.671 8.02e-05 ***
Cover 0.5888 0.2960 1.989 0.057334 .
Foods 0.5492 0.2040 2.692 0.012257 *
Water 1.0422 0.2375 4.387 0.000169 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.281 on 26 degrees of freedom
Multiple R-squared: 0.5587, Adjusted R-squared: 0.5078
F-statistic: 10.97 on 3 and 26 DF, p-value: 7.734e-05
-ประชากรกวางกับจำนวนแหล่งอาหาร และแหล่งน้ำ
LM5<-lm(Deer~Foods+Water, data=data)
summary(LM5)
Call:
lm(formula = Deer ~ Foods + Water, data = data)
Residuals:
Min 1Q Median 3Q Max
-3.6915 -0.5427 0.1238 0.6371 1.9691
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.3821 0.5522 6.125 1.52e-06 ***
Foods 0.4941 0.2129 2.321 0.0281 *
Water 1.1664 0.2414 4.832 4.78e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.349 on 27 degrees of freedom
Multiple R-squared: 0.4916, Adjusted R-squared: 0.4539
F-statistic: 13.05 on 2 and 27 DF, p-value: 0.0001082
5. ทดสอบความแตกต่างของ models ที่ 4 และ 5
anova(LM4, LM5, test="Chisq")Analysis of Variance Table
Model 1: Deer ~ Cover + Foods + Water
Model 2: Deer ~ Foods + Water
Res.Df RSS Df Sum of Sq Pr(>Chi)
1 26 42.658
2 27 49.148 -1 -6.49 0.04671 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1