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

Exercise ANOVA Anotherone - Fresco

This Python code uses the mtcars dataset from R to build a linear regression model with the log of miles per gallon (mpg) as the response variable and the log of weight (wt) as the predictor variable. It prints the analysis of variance (ANOVA) table for the linear model and the F-statistic for the log of weight term from the table.

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)
120 views1 page

Exercise ANOVA Anotherone - Fresco

This Python code uses the mtcars dataset from R to build a linear regression model with the log of miles per gallon (mpg) as the response variable and the log of weight (wt) as the predictor variable. It prints the analysis of variance (ANOVA) table for the linear model and the F-statistic for the log of weight term from the table.

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 numpy as np
import pandas as pd
import statsmodels.formula.api as smf
from statsmodels.stats import anova

mtcars = sm.datasets.get_rdataset("mtcars", "datasets", cache=True).data


df = pd.DataFrame(mtcars)
model = smf.ols(formula='np.log(mpg) ~ np.log(wt)', data=mtcars).fit()
print(anova.anova_lm(model))
print(anova.anova_lm(model).F["np.log(wt)"])

You might also like