Memuat
Memuat
Autoregression AR(p) for Medicine and Clinical Data
0 views
Model the blood glucose series with AR(p) autoregression and examine the supporting role of carbohydrate intake and insulin dose. Autoregression AR(p) models the current value as a linear combination of its p previous values. It suits stationary time series whose values depend on their own history.

Model the blood glucose series with AR(p) autoregression and examine the supporting role of carbohydrate intake and insulin dose.
| Role | Variable | Unit |
|---|---|---|
| Main | Blood glucose | mg/dL |
| Supporting 1 | Carbohydrate intake | g |
| Supporting 2 | Insulin dose | unit |
The AR(1) model forecasts Blood glucose 12 periods ahead with RMSE 19.440 and MAPE 7.98%. The order was chosen by AIC.
Computed from illustrative synthetic data, not from a real study.
Autoregression AR(p) models the current value as a linear combination of its p previous values. It suits stationary time series whose values depend on their own history.
Report the selected order, coefficients, and forecast error on test data. Include residual autocorrelation results to show the model is adequate.
A short starting script with this project's variable names. The delivered version is adapted to your data and fully commented.
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng(12)
n = 300
e = rng.normal(0, 1, n)
blood_glucose = np.zeros(n)
for i in range(2, n):
blood_glucose[i] = 0.6 * blood_glucose[i - 1] - 0.3 * blood_glucose[i - 2] + e[i]
carbohydrate_intake = np.arange(n)
train, test = blood_glucose[:270], blood_glucose[270:]
pmax = 6
def lagmat(y, p, start):
X = np.column_stack([y[start - k - 1:len(y) - k - 1] for k in range(p)])
return np.column_stack([np.ones(len(X)), X]), y[start:]
best = None
for p in range(1, pmax + 1):
X, t = lagmat(train, p, pmax)
beta = np.linalg.lstsq(X, t, rcond=None)[0]
sse = ((t - X @ beta) ** 2).sum()
aic = len(t) * np.log(sse / len(t)) + 2 * (p + 1)
print("p =", p, "AIC =", round(aic, 2))
if best is None or aic < best[0]:
best = (aic, p, beta)
_, p, beta = best
print("Selected p:", p, "coef:", beta.round(3))
hist = list(train)
fc = []
for _ in range(len(test)):
nxt = beta[0] + sum(beta[k + 1] * hist[-k - 1] for k in range(p))
fc.append(nxt); hist.append(nxt)
print("Forecast RMSE:", round(np.sqrt(np.mean((test - np.array(fc)) ** 2)), 3))
plt.plot(carbohydrate_intake[250:], blood_glucose[250:], label="Data")
plt.plot(carbohydrate_intake[270:], fc, "r", label="AR forecast")
plt.legend()
plt.show()Choose how much help you need. Each higher package includes everything in the lower ones. Prices exclude 11% VAT.
Package 1
US$25
excl. 11% VAT
Duration: 5 working days
Output: Python files + result figures
Deliverables
Package 2 · most chosen
US$69
excl. 11% VAT
Duration: 9 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$147
excl. 11% VAT
Duration: 14-17 working days
Output: Code + analysis + guidance until ready to present
Includes all of Packages 1 & 2, plus
Yes. Autoregression AR(p) is commonly used at this level in Medicine and Clinical Data. We adapt the analysis to your research question, your own data and your supervisor's requirements.
No. The sheet is computed from illustrative synthetic data so you can see the kind of output Python gives. For your order we run the same method on your own data.
That is the point of the packages. Every script is commented, and Package 3 includes two coaching sessions plus practice questions so you can explain the method and the results at your seminar and defence.
Each project has three packages: Package 1 (code and explanation) US$25, Package 2 (your data analysis and interpretation) US$69 and Package 3 (full guidance) US$147, excluding 11% VAT. Larger datasets, extra methods or tight deadlines adjust the quote after a short consultation.
The result sheet uses illustrative synthetic data. Python is a trademark of the Python Software Foundation.
Back to Python portfolio