分析目的

本報告使用 PISA 2022 台灣資料,以 Pearson 積差相關係數與散佈圖探討兩組變項的線性關係:

  1. 社會經濟地位 ESCS 與數學成就 PV1MATH
  2. 年齡 AGE 與社會經濟地位 ESCS

讀取資料與描述統計

# 載入讀取 SPSS 檔案與繪圖所需套件
library(haven)
library(ggplot2)

# 讀入 PISA 2022 台灣資料
data <- read_sav("PISA_tawian2022_trimmed_lab.sav")

# 取出分析變項,並把 SPSS 標籤欄位轉成一般數值
escs <- as.numeric(data$ESCS)
math <- as.numeric(data$PV1MATH)
age <- as.numeric(data$AGE)

# 描述統計:了解各變項的範圍與缺失值
summary(data.frame(ESCS = escs, PV1MATH = math, AGE = age))
##       ESCS            PV1MATH           AGE       
##  Min.   :-3.8421   Min.   :219.1   Min.   :15.33  
##  1st Qu.:-0.9395   1st Qu.:460.4   1st Qu.:15.58  
##  Median :-0.2368   Median :541.6   Median :15.83  
##  Mean   :-0.2701   Mean   :537.8   Mean   :15.81  
##  3rd Qu.: 0.4393   3rd Qu.:618.8   3rd Qu.:16.08  
##  Max.   : 4.2070   Max.   :917.4   Max.   :16.33
# AGE 實際上有幾種不同的值(PISA 以月為單位記錄年齡)
length(unique(age))
## [1] 13

三個變項皆為連續變項,且沒有缺失值,有效樣本 n = 5599。AGE 的範圍只有 15.33~16.33 歲,以月為單位共 13 種不同的值。

第一組:ESCS 與 PV1MATH

# cor.test() 計算 Pearson 相關係數,並檢定 r 是否顯著不等於 0
test1 <- cor.test(escs, math, method = "pearson")
test1
## 
##  Pearson's product-moment correlation
## 
## data:  escs and math
## t = 31.952, df = 5597, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.3703870 0.4146987
## sample estimates:
##       cor 
## 0.3927708
# 四捨五入到小數第二位
round(test1$estimate, 2)
##  cor 
## 0.39
# 散佈圖:X 軸為 ESCS、Y 軸為 PV1MATH;點設半透明避免重疊,紅線為最適直線
ggplot(data.frame(ESCS = escs, PV1MATH = math), aes(x = ESCS, y = PV1MATH)) +
  geom_point(alpha = 0.2, color = "steelblue") +
  geom_smooth(method = "lm", se = FALSE, color = "red") +
  labs(title = sprintf("ESCS vs PV1MATH (r = %.2f)", test1$estimate),
       x = "ESCS", y = "PV1MATH") +
  theme_minimal()

r = 0.39,為中度正相關,p < .001。點雲由左下往右上分布,但分散程度大。

第二組:AGE 與 ESCS

# 計算 AGE 與 ESCS 的 Pearson 相關係數與顯著性檢定
test2 <- cor.test(age, escs, method = "pearson")
test2
## 
##  Pearson's product-moment correlation
## 
## data:  age and escs
## t = -0.33172, df = 5597, p-value = 0.7401
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.03062489  0.02176306
## sample estimates:
##          cor 
## -0.004433958
# 四捨五入到小數第二位
round(test2$estimate, 2)
## cor 
##   0
# 散佈圖:X 軸為 AGE、Y 軸為 ESCS
ggplot(data.frame(AGE = age, ESCS = escs), aes(x = AGE, y = ESCS)) +
  geom_point(alpha = 0.2, color = "darkgreen") +
  geom_smooth(method = "lm", se = FALSE, color = "red") +
  labs(title = sprintf("AGE vs ESCS (r = %.2f)", test2$estimate),
       x = "AGE", y = "ESCS") +
  theme_minimal()

r = -0.00(約 -0.004),p = .74,兩者幾乎沒有線性相關,迴歸線接近水平。

結論