Q1:
library(data.table)
exam <- fread('http://faculty.ndhu.edu.tw/~chtsao/ftp/stat2016.txt')
head(exam) # Take a quick look of first few cases
## V1 V2 V3
## 1: 2 5 36
## 2: 2 75 63
## 3: 2 37 38
## 4: 2 27 0
## 5: 2 16 14
## 6: 2 46 57
summary(exam)
## V1 V2 V3
## Min. :2.000 Min. : 0.00 Min. :-10.00
## 1st Qu.:2.000 1st Qu.: 25.50 1st Qu.: 13.50
## Median :2.000 Median : 46.00 Median : 31.00
## Mean :2.476 Mean : 46.52 Mean : 34.11
## 3rd Qu.:3.000 3rd Qu.: 67.50 3rd Qu.: 53.00
## Max. :5.000 Max. :110.00 Max. :100.00
is.data.frame(exam)
## [1] TRUE
colnames(exam)<-c("year","mid","final")
exam$year<-as.factor(exam$year)
summary(exam)
## year mid final
## 2:42 Min. : 0.00 Min. :-10.00
## 3:15 1st Qu.: 25.50 1st Qu.: 13.50
## 4: 3 Median : 46.00 Median : 31.00
## 5: 3 Mean : 46.52 Mean : 34.11
## 3rd Qu.: 67.50 3rd Qu.: 53.00
## Max. :110.00 Max. :100.00
attach(exam)
m2<-lm(final~mid)
summary(m2)
##
## Call:
## lm(formula = final ~ mid)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36.062 -12.562 -3.029 10.211 61.213
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.44481 5.14339 1.642 0.106
## mid 0.55168 0.09554 5.774 2.79e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.54 on 61 degrees of freedom
## Multiple R-squared: 0.3534, Adjusted R-squared: 0.3428
## F-statistic: 33.34 on 1 and 61 DF, p-value: 2.791e-07
par(mfrow=c(2,2));
plot(m2)

par(mfrow=c(1,1));
plot(final~mid)
abline(m2)

a=20 #代入四位學生成績
y=0.55168*a+8.44481 #y=ax+b 線性方程式
y
## [1] 19.47841
b=40
y=0.55168*b+8.44481
y
## [1] 30.51201
c=70
y=0.55168*c+8.44481
y
## [1] 47.06241
d=90
y=0.55168*d+8.44481
y
## [1] 58.09601
Q2:
A=0.5*mid+0.5*final+5 #suppose by ourself
sort(A,decreasing=TRUE) #遞減排列成績
## [1] 96.5 91.5 87.5 86.5 82.5 81.5 78.5 74.0 73.5 70.5 69.0 67.0 66.0 65.5
## [15] 65.5 64.0 61.5 61.0 60.5 58.5 56.5 54.0 53.0 52.0 50.5 48.5 47.5 47.0
## [29] 46.5 45.5 44.5 44.0 43.5 43.0 42.5 42.5 41.5 40.5 36.5 35.5 33.0 32.5
## [43] 32.5 30.5 30.0 27.5 27.0 26.5 25.5 25.5 24.0 22.0 22.0 22.0 20.0 18.5
## [57] 16.5 16.5 9.5 8.5 5.5 3.0 0.5
a=63*1/10 #把人數分割成1:3:3:3
a
## [1] 6.3
round(a) #大約值取四捨五入
## [1] 6
b=63*3/10
b
## [1] 18.9
round(b)
## [1] 19
c=63*3/10
c
## [1] 18.9
round(c)
## [1] 19
d=63*3/10
d
## [1] 18.9
round(d)
## [1] 19