R 中的 Wikipedia 浏览量:统计类文章四年间失去了超过一半的读者
Wikipedia 是许多人第一次接触标准差、p 值和 t 检验的地方。我想知道,在如今可以把「什么是 p 值」输入聊天机器人、或者在搜索页顶部直接得到答案的时代,人们是否还会这样做。Wikimedia 会逐月公布每篇文章的人类访问次数,所以这个问题有直接的答案:这些页面现在的人类读者不到四年前的一半,而且它们失去读者的速度比 Wikipedia 的其他部分更快。
如何把 Wikipedia 浏览量数据导入 R?
用 httr2 向 Wikimedia REST API 发起请求:每篇文章一次请求,返回月度(或每日)浏览量计数,格式为 JSON;你需要设置 agent = "user",这样爬虫和机器人就被排除在外。旧教程使用的 pageviews 包已于 2025 年 7 月 16 日从 CRAN 归档,因此没有可安装的封装包。下面这段代码在 R 4.6.1 上配合 httr2 1.3.0 可独立运行:
library(httr2)
library(tidyverse)
pageviews <- function(article, agent = "user") {
request("https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access") |>
req_url_path_append(agent, gsub(" ", "_", article), "monthly", "2015090100", "2026083100") |>
req_user_agent("pageviews example in R ([email protected])") |> # Wikimedia asks for a contact
req_retry(max_tries = 5) |> # waits out HTTP 429s
req_perform() |>
resp_body_json(simplifyVector = TRUE) |>
pluck("items") |>
as_tibble() |>
transmute(article, agent, month = as.Date(timestamp, "%Y%m%d"), views)
}
pageviews("Standard deviation") |> tail(3)
## # A tibble: 3 × 4
## article agent month views
## <chr> <chr> <date> <int>
## 1 Standard_deviation user 2026-06-01 51656
## 2 Standard_deviation user 2026-07-01 46126
## 3 Standard_deviation user 2026-08-01 48141
Wikimedia 的 User-Agent 政策要求脚本通过联系方式表明自身身份,因此需要 req_user_agent()。我并行发起十个请求时遇到了 HTTP 429「Too Many Requests」,所以请一次只抓取一篇文章;当 API 施加限制时,req_retry() 会退避并重试。
统计类页面与 Wikipedia 其他部分的对比
我列出了 45 篇覆盖入门统计学课程的文章,从 Arithmetic mean 到 Mann-Whitney U test,只保留 2015 年以来标题未发生变化的条目(原因见下文)。作为对照,我加入了十篇学校数学与科学文章、十篇大众兴趣文章,以及整个英文 Wikipedia 的总计。对照组规模小且是手工挑选的,所以请把它们当作背景参考来解读。
stats_pages <- c(
"Arithmetic mean", "Median", "Mode (statistics)", "Standard deviation", "Variance",
"Standard error", "Normal distribution", "Binomial distribution", "Poisson distribution",
"Central limit theorem", "Confidence interval", "P-value", "Student's t-test",
"Chi-squared test", "Analysis of variance", "Linear regression", "Regression analysis",
"Logistic regression", "Bayes' theorem", "Law of large numbers", "Sampling (statistics)",
"Statistical significance", "Interquartile range", "Box plot", "Histogram", "Standard score",
"Type I and type II errors", "Probability distribution", "Percentile", "Quartile",
"Coefficient of variation", "Skewness", "Kurtosis", "Outlier", "Simple linear regression",
"Ordinary least squares", "Covariance", "Probability density function", "Expected value",
"Statistics", "Descriptive statistics", "Mann–Whitney U test", "Wilcoxon signed-rank test",
"Spearman's rank correlation coefficient", "Sample size determination")
science_pages <- c(
"Pythagorean theorem", "Derivative", "Integral", "Logarithm", "Prime number",
"Photosynthesis", "Mitochondrion", "Newton's laws of motion", "Periodic table", "Cell (biology)")
general_pages <- c(
"World War II", "Albert Einstein", "United States", "Roman Empire", "The Beatles",
"Leonardo da Vinci", "Moon", "India", "William Shakespeare", "Olympic Games")
pages <- bind_rows(
tibble(set = "Statistics (45)", article = stats_pages),
tibble(set = "Maths and science (10)", article = science_pages),
tibble(set = "General interest (10)", article = general_pages))
views <- pages |>
mutate(data = map(article, pageviews)) |>
select(set, data) |>
unnest(data)
# the same statistics pages, counted with every agent
stats_all_agents <- map(stats_pages, pageviews, agent = "all-agents") |>
list_rbind() |>
mutate(set = "Statistics (45)")
# all of English Wikipedia, one request per agent
wiki_total <- function(agent) {
request("https://wikimedia.org/api/rest_v1/metrics/pageviews/aggregate/en.wikipedia/all-access") |>
req_url_path_append(agent, "monthly", "2015090100", "2026083100") |>
req_user_agent("pageviews example in R ([email protected])") |>
req_retry(max_tries = 5) |>
req_perform() |>
resp_body_json(simplifyVector = TRUE) |>
pluck("items") |>
as_tibble() |>
transmute(set = "All of English Wikipedia", agent, month = as.Date(timestamp, "%Y%m%d"), views)
}
wiki <- map(c("user", "all-agents", "automated"), wiki_total) |> list_rbind()
参照页面随校历变化,因此我按学年(9 月至次年 8 月)逐月累加。2021-22 学年是 ChatGPT 于 2022 年 11 月 30 日发布之前结束的最后一个学年。
by_year <- bind_rows(views, stats_all_agents, wiki) |>
mutate(school_year = if_else(month(month) >= 9, year(month), year(month) - 1)) |>
group_by(set, agent, school_year) |>
summarise(views = sum(views), .groups = "drop")
# school years are labelled by the year they start: 2016 = 2016-17
change <- by_year |>
filter(school_year %in% c(2016, 2021, 2025)) |>
pivot_wider(names_from = school_year, values_from = views, names_prefix = "y") |>
mutate(from_2016_to_2021 = y2021 / y2016 - 1, from_2021_to_2025 = y2025 / y2021 - 1)
change |>
filter(agent == "user") |>
select(set, from_2016_to_2021, from_2021_to_2025) |>
mutate(across(where(is.numeric), \(x) scales::percent(x, accuracy = 1)))
## # A tibble: 4 × 3
## set from_2016_to_2021 from_2021_to_2025
## <chr> <chr> <chr>
## 1 All of English Wikipedia -9% -4%
## 2 General interest (10) -5% -23%
## 3 Maths and science (10) -26% -37%
## 4 Statistics (45) -30% -56%
文章标题:R 语言中的 Wikipedia 页面浏览量:统计学文章四年间流失超过 50% 的读者
正文:
这 45 篇统计学文章在 2021-22 年有 2610 万次人类浏览量,在 2025-26 年有 1150 万次,下降了 56%。45 篇文章无一例外全部下降,其中 37 篇降幅超过一半;降幅最小的是 Bayes 定理(27%),最大的是描述统计学(79%)。同一四年间,数学与科学类页面下降了 37%,大众兴趣类页面下降了 23%,而英文 Wikipedia 整体仅下降 4%。
dsp_colors <- c("#0066CC", "#E8862D", "#159A6C", "#7D5BD6",
"#D64580", "#2AA9B8", "#C9A227")
dsp_theme <- theme_minimal(base_size = 13) +
theme(plot.background = element_rect(fill = "#ECECEF", color = NA),
panel.background = element_rect(fill = "#ECECEF", color = NA),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_line(color = "grey78"),
axis.ticks = element_blank(),
plot.title = element_text(face = "bold"),
strip.text = element_text(face = "bold"))
indexed <- by_year |>
filter(agent == "user") |>
group_by(set) |>
mutate(index = 100 * views / views[school_year == 2016]) |>
ungroup()
ggplot(indexed, aes(school_year, index, color = set)) +
geom_vline(xintercept = 2021.5, linetype = "dashed", color = "grey50") +
annotate("text", x = 2021.6, y = 138, label = "ChatGPT released\nNov 2022",
hjust = 0, size = 3.4, color = "grey35", lineheight = 0.9) +
geom_line(linewidth = 1) +
geom_point(size = 1.8) +
geom_text(data = filter(indexed, school_year == 2025), aes(label = set),
hjust = 0, nudge_x = 0.2, size = 3.6) +
scale_color_manual(values = dsp_colors[c(4, 3, 2, 1)]) +
scale_x_continuous(breaks = seq(2015, 2025, 2),
labels = \(x) paste0(x, "-", substr(x + 1, 3, 4)),
expand = expansion(mult = c(0.02, 0.33))) +
scale_y_continuous(limits = c(0, NA)) +
labs(x = "School year (September to August)", y = "Human pageviews, 2016-17 = 100",
title = "Statistics pages lost readers fastest") +
dsp_theme +
theme(legend.position = "none")

统计学页面在 2022 年之前就已在下滑:2016-17 年至 2021-22 年间下降了 30%,而大众兴趣类页面同期仅下降 5%。变化的是速度。那五年的流失折算下来约为每年 7%;此后四年平均每年下降 19%,而最近一年最为陡峭,从 2025 年 9 月到 2026 年 8 月的每个月都比上年同月低 27% 到 42%。
在 Wikipedia API 中应该用 “user” 还是 “all-agents”?
如果你想要的是真人,就用 user。API 将流量分为 user、spider(自称爬虫的抓取程序)和 automated(被 Wikimedia 的检测机制捕获的机器人),而 all-agents 是这三者的总和。已归档的 pageviews 包默认使用 user_type = "all",它会向 API 发送 all-agents,因此基于该包编写的代码会把机器人也计算在内,除非有人改掉了这个参数。
在这些数据上,这个选择会改变答案:
change |>
filter(set %in% c("Statistics (45)", "All of English Wikipedia")) |>
select(set, agent, from_2021_to_2025) |>
mutate(from_2021_to_2025 = scales::percent(from_2021_to_2025, accuracy = 1))
## # A tibble: 5 × 3
## set agent from_2021_to_2025
## <chr> <chr> <chr>
## 1 All of English Wikipedia all-agents 9%
## 2 All of English Wikipedia automated 162%
## 3 All of English Wikipedia user -4%
## 4 Statistics (45) all-agents -47%
## 5 Statistics (45) user -56%
文章标题:R 中的 Wikipedia 页面浏览量:统计类文章四年间流失超过 50% 的读者
正文: 按全代理口径统计,英文 Wikipedia 在 2021-22 至 2025-26 年间增长了 9%;按真人口径统计,它缩水了 4%。差异来自自动化流量,其年浏览量从 83 亿增至 218 亿。对于统计类页面,正负号依然成立,但跌幅从 56% 收窄至 47%。这些标签是 Wikimedia 的分类,且随其机器人检测能力的提升而变动,因此应把 user 视为他们当前的最佳估计,而非对真人的普查。
重命名文章会打断页面浏览量序列
API 统计的是你所请求的确切标题的浏览量。当文章被重命名后,读者会转向新标题,旧标题只剩下零散的链接,因此单一标题的序列会在一侧呈现断崖、另一侧呈现跳升。这就是我的清单中缺少三个页面的原因:Correlation(2021 年前名为 "Correlation and dependence")、Pearson correlation coefficient(2017 年 1 月重命名)和 Statistical hypothesis test(2024 年重命名)。
correlation <- map(c("Correlation", "Correlation and dependence"), pageviews) |>
list_rbind() |>
mutate(school_year = if_else(month(month) >= 9, year(month), year(month) - 1)) |>
filter(school_year %in% c(2016, 2025)) |>
group_by(school_year) |>
summarise(new_title_only = sum(views[article == "Correlation"]),
both_titles = sum(views))
correlation
## # A tibble: 2 × 3
## school_year new_title_only both_titles
## <dbl> <int> <int>
## 1 2016 117019 778810
## 2 2025 181875 197149
仅看其当前标题,Correlation 将是本文中唯一一个增长的统计类页面,自 2016-17 以来增长了 55%。把旧标题加回来后,它下降了 75%,与其余页面一致。在信任一个长序列之前,先找出浏览量出现三倍或以上跳升或骤降的月份,并查看该文章的移动日志。
这些数字说明了什么,又没有说明什么
Wikipedia 核心统计文章的真人访问量从 2016-17 的 3750 万降至 2025-26 的 1150 万,不到原来的三分之一,且自 2022 年以来,其下降速度超过任何对比集合。页面浏览量无法说明原因。从时间上看,这符合读者从 AI 助手以及搜索结果中的 AI 摘要获取定义和示例的趋势,而更早的下滑则符合搜索引擎在结果页直接回答简短问题的趋势,但浏览量并不记录读者转而去了哪里。这也不意味着学习统计学的人变少了,只意味着在 Wikipedia 上学习的人变少了。
发表评论 取消回复
本站使用 Akismet 减少垃圾评论。你的评论数据将被处理以用于此目的。
Loess 的更多文章
- 在 R 中绘制医院荒漠地图4.4K 次浏览
- 如何在 R 中一次读取多个 CSV 文件4.3K 次浏览
- 如何在 R 中绘制食物荒漠地图4.1K 次浏览
- 当组方差不等时如何在 R 中运行 Welch ANOVA3.8K 次浏览
更多「获取数据」栏目文章
- 如何在 R 中同时导入多个 .csv 文件并创建数据框102.7K 次浏览
- 使用 Tabulizer 包在 R 中从 PDF 提取表格100.2K 次浏览
- 将数据从 R 导出为 TXT、CSV、SPSS 或 Stata94.4K 次浏览
- 将数据导入 R:从 SPSS、Stata、SAS、CSV 或 TXT 导入数据70.7K 次浏览