1.Chinese poem

Use a markdown template to generate a web page like this famous Chinese poem.

人生若只如初見,何事秋風悲畫扇。

等閒變卻故人心,卻道故人心易變!

驪山語罷清宵半,淚雨霖鈴終不怨。

何如薄倖錦衣郎,比翼連枝當日願!

2.1.Grade school admission, Lab report

Data

Read in the data from the website.

dta <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")

Keep only gpa and gre variables

Create new data object.

dta <- dta[, c("gpa", "gre")] 

Plot before analysis

plot(dta, xlab = "GRE", ylab = "GPA")
grid()

Analysis

options(digits = 4, show.signif.stars = FALSE)
summary(m0 <- lm(gpa ~ gre, data = dta))
## 
## Call:
## lm(formula = gpa ~ gre, data = dta)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.0867 -0.2244 -0.0002  0.2481  0.7618 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.645898   0.091310    29.0  < 2e-16
## gre         0.001266   0.000152     8.3  1.6e-15
## 
## Residual standard error: 0.352 on 398 degrees of freedom
## Multiple R-squared:  0.148,  Adjusted R-squared:  0.146 
## F-statistic: 68.9 on 1 and 398 DF,  p-value: 1.6e-15

由上表分析可知GPA對GRE有預測力,GPA分數每上升一,GRE會增加0.0013。R2=0.148

anova(m0)
## Analysis of Variance Table
## 
## Response: gpa
##            Df Sum Sq Mean Sq F value  Pr(>F)
## gre         1    8.5    8.53      69 1.6e-15
## Residuals 398   49.3    0.12

Model figure

plot(dta$gpa~dta$gre, type = "p", xlab = "GRE", ylab = "GPA")
abline(m0, lty = 2)
grid()

Plot for residuals

檢查殘差分配有沒有規律

plot(resid(m0) ~ fitted(m0), xlab = "Fitted values", 
     ylab = "Residuals", ylim = c(-3.5, 3.5))
grid()
abline(h = 0, lty = 2)

驗證殘差是否符合常態分布

qqnorm(resid(m0))
qqline(resid(m0))
grid()

End