Read the file

library(haven)
PISA<- read_sav("PISA_tawian2022_trimmed_lab.sav")
View(PISA)

PVIMATH 平均數(mean)

mean(PISA$PV1MATH) 
## [1] 537.822

PV1MATH 標準差(sd)

sd(PISA$PV1MATH)
## [1] 109.7305

兩個組別的數學成績描述性統計

group1→女;group2→男

library(psych)
describeBy(PISA$PV1MATH, PISA$Gender) 
## 
##  Descriptive statistics by group 
## group: 1
##    vars    n   mean     sd median trimmed    mad    min    max  range  skew
## X1    1 2780 535.84 102.26 538.56  536.99 108.38 227.79 821.56 593.77 -0.11
##    kurtosis   se
## X1     -0.4 1.94
## ------------------------------------------------------------ 
## group: 2
##    vars    n   mean     sd median trimmed    mad    min    max  range skew
## X1    1 2819 539.78 116.62 546.54  541.26 125.62 219.06 917.38 698.32 -0.1
##    kurtosis  se
## X1    -0.51 2.2

兩個組別的樣本數

group1→女;group2→男
(Transform a numerical var into a factor)

PISA$Gender<-as.factor(PISA$Gender)
summary(PISA$Gender)
##    1    2 
## 2780 2819

Levene’s Test for homogeneity in variances (H0: Equal variance is assumed)

library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit

輸出F值和p值,用p值判斷

leveneTest(PISA$PV1MATH~ PISA$Gender, center="mean")
## Levene's Test for Homogeneity of Variance (center = "mean")
##         Df F value    Pr(>F)    
## group    1  59.342 1.557e-14 ***
##       5597                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Independent sample t-test (Welch two sample t-test) with equal variance not assumed (sig Levene’s Test)

Levene檢定顯著(變異數不相等),以 t-test檢測,var.equal = FALSE

t.test(PISA$PV1MATH~ PISA$Gender,var.equal=FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  PISA$PV1MATH by PISA$Gender
## t = -1.3461, df = 5521.6, p-value = 0.1783
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
##  -9.688443  1.799944
## sample estimates:
## mean in group 1 mean in group 2 
##        535.8361        539.7803