[go: up one dir, main page]

0% found this document useful (0 votes)
137 views1 page

Exercise - ANOVA - Fresco

This Python code is performing an analysis of variance (ANOVA) on a linear regression model predicting vehicle weight (wt) from miles per gallon (mpg) using automotive data from the mtcars dataset. It defines the model, fits it to the data, and prints the F-statistic from an ANOVA on the fitted linear regression model to test whether miles per gallon significantly predicts vehicle weight.

Uploaded by

Arpita Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views1 page

Exercise - ANOVA - Fresco

This Python code is performing an analysis of variance (ANOVA) on a linear regression model predicting vehicle weight (wt) from miles per gallon (mpg) using automotive data from the mtcars dataset. It defines the model, fits it to the data, and prints the F-statistic from an ANOVA on the fitted linear regression model to test whether miles per gallon significantly predicts vehicle weight.

Uploaded by

Arpita Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import statsmodels.

api as sm
import statsmodels.formula.api as smf
import numpy as np
from statsmodels.stats import anova
import patsy

mtcar_data = sm.datasets.get_rdataset('mtcars')
df = mtcar_data.data
wt = np.array(df.wt)
mpg = np.array(df.mpg)
data = {'wt':wt, 'mpg':mpg}
linear_model1 = smf.ols('wt~ mpg', data)
linear_result1 = linear_model1.fit()
anv = anova.anova_lm(linear_result1)
print(anv['F'][0])

You might also like