Code
# 必要なライブラリを読み込み
library(ggplot2)Warning: package 'ggplot2' was built under R version 4.3.1
Code
# データの作成
data <- data.frame(
Time = c(10.06, 10.03, 10.02, 9.95, 9.93, 9.83, 9.93, 9.79, 9.92, 9.90, 9.86, 9.85, 9.84, 9.79, 9.78, 9.768, 9.766, 9.763, 9.762, 9.735, 9.72, 9.69, 9.58),
Athlete = c("Bob Hayes", "Jim Hines", "Charles Greene", "Jim Hines", "Calvin Smith", "Ben Johnson", "Carl Lewis", "Ben Johnson", "Carl Lewis", "Leroy Burrell", "Carl Lewis", "Leroy Burrell", "Donovan Bailey", "Maurice Greene", "Tim Montgomery", "Asafa Powell", "Justin Gatlin", "Asafa Powell", "Asafa Powell", "Asafa Powell", "Usain Bolt", "Usain Bolt", "Usain Bolt"),
Date = as.Date(c("1964-10-15", "1968-06-20", "1968-10-13", "1968-10-14", "1983-07-03", "1987-08-30", "1987-08-30", "1988-09-24", "1988-09-24", "1991-06-14", "1991-08-25", "1994-07-06", "1996-07-27", "1999-06-16", "2002-09-14", "2005-06-14", "2006-05-12", "2006-06-11", "2006-08-18", "2007-09-09", "2008-05-31", "2008-08-16", "2009-08-16"))
)
# 年を抽出
data$Year <- as.numeric(format(data$Date, "%Y"))
# 線形回帰モデルを作成
model <- lm(Time ~ Year, data = data)
# モデルの概要を表示
summary(model)
Call:
lm(formula = Time ~ Year, data = data)
Residuals:
Min 1Q Median 3Q Max
-0.13508 -0.00159 0.01077 0.02507 0.05096
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 24.6882289 1.3679160 18.05 2.89e-14 ***
Year -0.0074530 0.0006865 -10.86 4.51e-10 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.04667 on 21 degrees of freedom
Multiple R-squared: 0.8488, Adjusted R-squared: 0.8416
F-statistic: 117.9 on 1 and 21 DF, p-value: 4.508e-10
Code
# 予測タイムを計算(100年後)
future_year <- max(data$Year) + 100
future_time_pred <- predict(model, newdata = data.frame(Year = future_year))
# 散布図と回帰直線を描く
ggplot(data, aes(x = Date, y = Time)) +
geom_point(color = "blue") +
geom_smooth(method = "lm", color = "red", se = FALSE) +
labs(title = "100m Sprint Times Over Years with Regression Line",
x = "Date",
y = "Time (seconds)") +
theme_minimal()`geom_smooth()` using formula = 'y ~ x'
Code
# 回帰モデルの式と予測タイムを表示
model_equation <- paste("Time = ", round(coef(model)[2], 4), "* Year +", round(coef(model)[1], 4))
cat("Regression Model Equation:", model_equation, "\n")Regression Model Equation: Time = -0.0075 * Year + 24.6882
Code
cat("Predicted Time in 100 Years:", future_time_pred, "\n")Predicted Time in 100 Years: 8.969772