OLS Fitting
ravix.ols() fits an ordinary least squares model using
an R-style formula string and returns a fitted model object.
Basic usage
import ravix
df = ravix.get_data("Betas.csv")
model = ravix.ols("AAPL ~ SPY", df)
model.summary()
Summary of OLS Regression Analysis:
======================================================
Coefficients:
------------------------------------------------------
Estimate Std. Error t-value p-value
Intercept 0.014223 0.011989 1.186 0.2437
SPY 1.2266 0.21591 5.681 2.24e-06 ***
Model Statistics:
------------------------------------------------------
Residual Std. Error: 0.069147
R-squared: 0.4870 AIC: -88.2432
Adj. R-squared: 0.4719 BIC: -85.0761
F-statistic: 32.2745 on 1 and 34 DF, p-value: 2.24e-06
======================================================
Formula syntax
| Formula | Meaning |
|---|---|
"y ~ x" |
Simple linear regression |
"y ~ x1 + x2" |
Multiple regression |
"y ~ x1 + x2 + x1:x2" |
Interaction only |
"y ~ x1 * x2" |
Main effects and interaction |
Accessing model attributes
The fitted object is a regression model object:
print("R-squared: ", round(model.rsquared, 4))
R-squared: 0.487
print("Adj. R-squared: ", round(model.rsquared_adj, 4))
Adj. R-squared: 0.4719
print(model.params)
Intercept 0.014223
SPY 1.226589
dtype: float64
model.params # Series — coefficient estimates
model.resid # Series — residuals
model.fittedvalues # Series — fitted values
model.rsquared # float — R²
model.rsquared_adj # float — Adjusted R²
model.pvalues # Series — coefficient p-values
model.bse # Series — coefficient standard errors
Confidence and prediction intervals
model.conf_int(alpha=0.05)
0 1
Intercept -0.010142 0.038588
SPY 0.787811 1.665368
import pandas as pd
new_df = pd.DataFrame({"SPY": [0.005, 0.010, 0.015]})
ravix.intervals(model, new_df, interval="confidence")
Prediction Lower Bound Upper Bound
0 0.020356 -0.003498 0.044209
1 0.026489 0.002952 0.050025
2 0.032622 0.009201 0.056043
ravix.intervals(model, new_df, interval="prediction")
Prediction Lower Bound Upper Bound
0 0.020356 -0.122179 0.162890
1 0.026489 -0.115993 0.168971
2 0.032622 -0.109841 0.175085
Logistic Regression
# Get data
df = ravix.get_data("loan_default.csv")
df = df[df.columns[1:]]
# Logistic
logreg = ravix.logistic("Loan_Default ~ Age + Marital_Status + Dependents", df)
# Model Summary
logreg.summary()
Summary of Logistic Regression Analysis:
==========================================================
Coefficients (Log-Odds):
----------------------------------------------------------
Estimate Std. Error t-value p-value
Intercept -1.9135 0.51144 -3.741 0.0002 ***
Age -0.0081359 0.010230 -0.795 0.4265
Marital_Statu... 0.12677 0.32743 0.387 0.6986
Marital_Statu... 0.42844 0.56198 0.762 0.4458
Marital_Statu... -0.060775 0.33662 -0.181 0.8567
Marital_Statu... 0.68904 0.62056 1.110 0.2668
Dependents -0.056555 0.090777 -0.623 0.5333
Model Statistics:
----------------------------------------------------------
Log-Likelihood: -395.0289 AIC: 804.0579
Pseudo R-squared: 0.002323 BIC: -7992.44
==========================================================
Poisson Regression
# Get data
df = ravix.get_data("video_engagement.csv")
# Poisson
pois = ravix.poisson("Likes ~ .", df)
# Model summary
pois.summary()
Summary of Poisson Regression Analysis:
======================================================
Coefficients (Log-Rate):
------------------------------------------------------
Estimate Std. Error t-value p-value
Intercept 10.235 0.0008990 11384.796 < 2e-16 ***
Promoter_B -2.1581 0.0010739 -2009.636 < 2e-16 ***
Age 0.0048345 2.408e-06 2007.940 < 2e-16 ***
Sentiment 0.0045228 0.0008673 5.215 1.84e-07 ***
Model Statistics:
------------------------------------------------------
Log-Likelihood: -188742.02 AIC: 377492.04
Deviance: 375545.73 BIC: 374772.12
Null Deviance: 12989055.39
Pseudo R-squared: 1
Degrees of Freedom: 3 (Model), 153 (Residual)
======================================================
Textbook reference: OLS fitting is covered in Chapters 3–9 of Applied Linear Regression for Business Analytics with Python.