Perform linear regression analysis.
def linregress(
yobs:_Iterable,
factor:_Iterable[_Iterable],
intercept=True,
alpha=0.05)->simple_linregress|multiple_linregress:
"""
Performs simple/multiple linear regression
yobs: Dependent data
factor: independent data (must be 2D)
intercept: True if there is intercept
alpha: significance level
"""
class simple_linregress:
def compute(self)->list:
def summary(self)->linregressResult:
def residuals(self)->tuple:
class multiple_linregress:
def compute(self)->list:
def summary(self)->linregressResult:
def residuals(self)->tuple:
class linregressResult:
@property
def R2(self):
@property
def stderr(self):
@property
def pvalue(self):
@property
def fvalue(self):
@property
def intercept(self):
@property
def ANOVA(self):
@property
def coeffstat(self):
Do the following data (Data from: Larsen & Marx, An Introduction to Mathematical Statistics and Its Applications) support the suspicion that smoking contributes to CHD mortality?
Cigarette Consumption:
[3900, 3350, 3220, 3220, 2790, 2780, 2770, 2290, 2160, 1890, 1810, 1800, 1770,
1700, 1680, 1510, 1500, 1410, 1270, 1200, 1090]
Mortality per 100000:
[256.9, 211.6, 238.1, 211.8, 194.1, 124.5, 187.3,
110.5, 233.1, 150.3, 124.7, 41.2, 182.1, 118.1, 31.9, 114.3,
144.9, 59.7, 126.9, 43.9, 136.3]
factor = [3900, 3350, 3220, 3220, 2790, 2780, 2770,
2290, 2160, 1890, 1810, 1800, 1770,
1700, 1680, 1510, 1500, 1410, 1270, 1200, 1090]
response = [256.9, 211.6, 238.1, 211.8, 194.1, 124.5, 187.3,
110.5, 233.1, 150.3, 124.7, 41.2, 182.1, 118.1, 31.9, 114.3, 144.9,
59.7, 126.9, 43.9, 136.3]
slm = st.linregress(response, factor)
slp_inter = slm.compute()
print("Coefficients:", slp_inter)
summary = slm.summary()
print("p-value:", summary.pvalue)
"""
Coefficients: [0.0601, 15.771]
p-value: 0.0002
"""