Nghiên cứu về yếu tố ảnh hưởng điểm học Nhóm nghiên cứu muốn đánh giá xem mức độ thường xuyên làm bài tập ở nhà ảnh hưởng như thế nào đến điểm thi toán. Thông tin thu nhận từ 260 học sinh của 10 trường. Giới thiệu tập tin số liệu imm10.csv:
- id: mã số học sinh tham gia nghiên cứu
- schnum: mã số trường
- math: điểm thi toán
- homework: mức độ thường xuyên làm bài tập ở nhà, tính bằng điểm dao động từ 0 đến 5
- white: người da trắng
- sex: giới tính (1= Nam, 2= Nữ)
- Các yếu tố ảnh hưởng khác: ses, sex, sctype, sctr, scsize, urban, region (không sử dụng trong bài tập này)

  1. Điểm thi toán và tình hình làm bài tập có khác nhau giữa các trường không?
school= read.csv("C:/Users/ADMIN/OneDrive/Statistical courses/Ton Duc Thang_Jan2020/TDTU Datasets for 2020 Workshop/imm10.csv")
head (school)
##   school id   ses    meanses homework white parented public ratio percmin
## 1   7472  3 -0.13 -0.4826087        1     1        2      1    19       0
## 2   7472  8 -0.39 -0.4826087        0     1        2      1    19       0
## 3   7472 13 -0.80 -0.4826087        0     1        2      1    19       0
## 4   7472 17 -0.72 -0.4826087        1     1        2      1    19       0
## 5   7472 27 -0.74 -0.4826087        2     1        2      1    19       0
## 6   7472 28 -0.58 -0.4826087        1     1        2      1    19       0
##   math sex race sctype cstr scsize urban region schnum
## 1   48   2    4      1    2      3     2      2      1
## 2   48   1    4      1    2      3     2      2      1
## 3   53   1    4      1    2      3     2      2      1
## 4   42   1    4      1    2      3     2      2      1
## 5   43   2    4      1    2      3     2      2      1
## 6   57   2    4      1    2      3     2      2      1
library(dplyr)
school %>%
  group_by(school) %>%
  summarise_at(vars(math, homework), funs(n(), mean(., na.rm=TRUE)))
## # A tibble: 10 x 5
##    school math_n homework_n math_mean homework_mean
##     <int>  <int>      <int>     <dbl>         <dbl>
##  1   7472     23         23      45.7         1.39 
##  2   7829     20         20      42.2         2.35 
##  3   7930     24         24      53.2         1.83 
##  4  24725     22         22      43.5         1.64 
##  5  25456     22         22      49.9         0.864
##  6  25642     20         20      46.4         1.15 
##  7  62821     67         67      62.8         3.30 
##  8  68448     21         21      49.7         2.10 
##  9  68493     21         21      46.3         1.33 
## 10  72292     20         20      47.8         1.6
  1. Bạn muốn đánh giá ảnh hưởng của làm bài tập ở nhà lên điểm thi toán dưới giả định là học sinh tham gia nghiên cứu độc lập với nhau (~ không có khác biệt giữa học sinh các trường): 2.1 Làm bài tập ở nhà ảnh hưởng như thế nào đến điểm thi toán?
m21= glm(math~ homework, data= school)
summary(m21)
## 
## Call:
## glm(formula = math ~ homework, data = school)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -28.9331   -6.6457    0.3543    7.0669   20.9261  
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  44.0739     0.9886   44.58   <2e-16 ***
## homework      3.5719     0.3882    9.20   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 93.73176)
## 
##     Null deviance: 32117  on 259  degrees of freedom
## Residual deviance: 24183  on 258  degrees of freedom
## AIC: 1922.4
## 
## Number of Fisher Scoring iterations: 2

2.2 Ở những học sinh có cùng chủng tộc và giới tính thì làm bài tập ở nhà ảnh hưởng như thế nào đến điểm thi toán?

m22= glm(math~ homework+ white+ sex, data= school)
summary(m22)
## 
## Call:
## glm(formula = math ~ homework + white + sex, data = school)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -29.9001   -6.8987    0.4681    6.5870   24.6075  
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  41.0711     2.1777  18.860  < 2e-16 ***
## homework      3.4830     0.3764   9.254  < 2e-16 ***
## white         5.7711     1.3060   4.419 1.47e-05 ***
## sex          -0.6786     1.1630  -0.584     0.56    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 87.58894)
## 
##     Null deviance: 32117  on 259  degrees of freedom
## Residual deviance: 22423  on 256  degrees of freedom
## AIC: 1906.7
## 
## Number of Fisher Scoring iterations: 2

2.3 Bạn nhận xét kết quả như thế nào?

  1. Lặp lại câu 2 dưới giả định là điểm toán và tình hình làm bài tập ở nhà khác nhau giữa các trường
library (lme4)
m3= lmer(math~ homework + (1 +homework | school), data= school)
summary(m3)
## Linear mixed model fit by REML ['lmerMod']
## Formula: math ~ homework + (1 + homework | school)
##    Data: school
## 
## REML criterion at convergence: 1764
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5111 -0.5357  0.0175  0.6121  2.5708 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  school   (Intercept) 69.32    8.326         
##           homework    22.46    4.739    -0.81
##  Residual             43.07    6.563         
## Number of obs: 260, groups:  school, 10
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)   44.771      2.744  16.316
## homework       2.040      1.554   1.313
## 
## Correlation of Fixed Effects:
##          (Intr)
## homework -0.804

Bạn nhận xét như thế nào về sự khác biệt với câu 2. Bạn sẽ trả lời câu hỏi nghiên cứu như thế nào?

  1. Bạn muốn đánh giá ảnh hưởng của làm bài tập ở nhà lên odds học sinh giỏi (định nghĩa làm điểm toán> 65) dưới giả định là học sinh tham gia nghiên cứu độc lập với nhau (~ không có khác biệt giữa học sinh các trường): 4.1 Làm bài tập ở nhà ảnh hưởng như thế nào đến odds học sinh giỏi?
school$good= ifelse(school$math>65, 1, 0)
m41= glm(good~ homework, family= binomial, data= school)
summary(m41)
## 
## Call:
## glm(formula = good ~ homework, family = binomial, data = school)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.8182  -0.3986  -0.2719  -0.2719   2.5755  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  -4.0662     0.4901  -8.297  < 2e-16 ***
## homework      0.7867     0.1334   5.898 3.68e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 197.86  on 259  degrees of freedom
## Residual deviance: 154.41  on 258  degrees of freedom
## AIC: 158.41
## 
## Number of Fisher Scoring iterations: 5

4.2 Ở những học sinh có cùng chủng tộc và giới tính thì làm bài tập ở nhà ảnh hưởng như thế nào đến odds học sinh giỏi?

m42= glm(good~ homework+ white+ sex, family= binomial, data= school)
summary(m41)
## 
## Call:
## glm(formula = good ~ homework, family = binomial, data = school)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.8182  -0.3986  -0.2719  -0.2719   2.5755  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  -4.0662     0.4901  -8.297  < 2e-16 ***
## homework      0.7867     0.1334   5.898 3.68e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 197.86  on 259  degrees of freedom
## Residual deviance: 154.41  on 258  degrees of freedom
## AIC: 158.41
## 
## Number of Fisher Scoring iterations: 5

4.3 Bạn nhận xét kết quả như thế nào?

  1. Lặp lại câu 4 dưới giả định là tình hình học toán và làm bài tập ở nhà khác nhau giữa các trường.
m5= glmer(good~ homework+ (1+ homework | school), family= binomial, data= school)
summary(m5)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: good ~ homework + (1 + homework | school)
##    Data: school
## 
##      AIC      BIC   logLik deviance df.resid 
##    153.1    170.9    -71.5    143.1      255 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.7224 -0.3176 -0.1039 -0.0505  3.7828 
## 
## Random effects:
##  Groups Name        Variance Std.Dev. Corr 
##  school (Intercept) 5.5129   2.3479        
##         homework    0.1217   0.3488   -1.00
## Number of obs: 260, groups:  school, 10
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  -5.8427     1.6107  -3.627 0.000286 ***
## homework      1.0102     0.3634   2.780 0.005435 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##          (Intr)
## homework -0.923
## convergence code: 0
## boundary (singular) fit: see ?isSingular

Bạn nhận xét như thế nào về sự khác biệt với câu 4. Bạn sẽ trả lời câu hỏi nghiên cứu như thế nào?