import numpy as np
import pandas as pd
import statsmodels.formula.api as sm
# https://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.OLSResults.get_prediction.html
time = [2, 4, 6, 8, 10]
y = [1.922, 1.443, 1.065, 0.703, 0.369]
data = pd.DataFrame({"time": time, "y": y})
result = sm.ols(formula='y ~ time', data=data)
result_fitted = result.fit()
prediction = result_fitted.get_prediction(pd.DataFrame({"time": [2]})) # timeの値が2の場合
prediction.summary_frame()
mean | mean_se | mean_ci_lower | mean_ci_upper | obs_ci_lower | obs_ci_upper | |
---|---|---|---|---|---|---|
0 | 1.8696 | 0.038355 | 1.747537 | 1.991663 | 1.670271 | 2.068929 |