#Plot dataset
plt.figure("Regular plot")
plt.title("Regular plot")
plt.scatter(x=bmgr_download_speeds["Date"],y=bmgr_download_speeds["Download Speed (Mbps)"],c="r",label="BMGR-E")
plt.scatter(x=pm_download_speeds["Date"],y=pm_download_speeds["Download Speed (Mbps)"],c="b",label="Point Mugu")
plt.xticks(rotation=90)
plt.legend()
plt.figure("Logarithmic plot")
plt.title("Logarithmic plot")
plt.scatter(x=bmgr_download_speeds["Date"],y=np.log10(bmgr_download_speeds["Download Speed (Mbps)"]),c="r",label="BMGR-E")
plt.scatter(x=pm_download_speeds["Date"],y=np.log10(pm_download_speeds["Download Speed (Mbps)"]),c="b",label="Point Mugu")
plt.xticks(rotation=90)
plt.legend()
# stats f_oneway functions takes the groups as input and returns ANOVA F and p value
fvalue, pvalue = stats.f_oneway(a[a["Location"]=="BMGR-E"]["Download Speed (Mbps)"], a[a["Location"]=="Point Mugu"]["Download Speed (Mbps)"])
print(fvalue, pvalue)
# get ANOVA table as R like output
import statsmodels.api as sm
from statsmodels.formula.api import ols
# # Ordinary Least Squares (OLS) model
c = a.copy()
c.reset_index(inplace=True)
c.columns = ['index', 'Location', 'DownloadSpeed']
print(c.head())
model = ols('DownloadSpeed ~ C(Location)', data=c).fit()
print(model.summary())
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table
# Create the data schema
two_way_df = download_speeds[["Location","Station ID","Download Speed (Mbps)"]]
two_way_df.reset_index(inplace=True)
two_way_df.columns = ['index', 'Location', "StationID", 'DownloadSpeed']
# Print first 5 lines of the data schema
print(two_way_df.head())
# Plot the data
sns.boxplot(x="StationID", y="DownloadSpeed", hue="Location", data=two_way_df, palette="Set3")
# Ordinary Least Squares (OLS) model
model = ols('DownloadSpeed ~ C(Location) / C(StationID)', data=two_way_df).fit()
print(model.summary())
# ANOVA - Anova table for one or more fitted linear models.
# URL:
# https://www.statsmodels.org/dev/generated/statsmodels.stats.anova.anova_lm.html
anova_table = sm.stats.anova_lm(model, typ=2)
# Main Variable: Site/Location
# Nested: Field Session/TripNumber
# Print results
anova_table
# Create the data schema
two_way_df = download_speeds[["Location","Trip Number","Download Speed (Mbps)"]]
two_way_df.reset_index(inplace=True)
two_way_df.columns = ['index', 'Location', "TripNumber", 'DownloadSpeed']
# Print first 5 lines of the data schema
print(two_way_df.head())
# Plot the data
sns.boxplot(x="TripNumber", y="DownloadSpeed", hue="Location", data=two_way_df, palette="Set3")
# Ordinary Least Squares (OLS) model
model = ols('DownloadSpeed ~ C(Location) / C(TripNumber)', data=two_way_df).fit()
print(model.summary())
# ANOVA - Anova table for one or more fitted linear models.
# URL:
# https://www.statsmodels.org/dev/generated/statsmodels.stats.anova.anova_lm.html
anova_table = sm.stats.anova_lm(model, typ=2)
# Main Variable: Camera trap ID/StationID
# Nested: Field Session/TripNumber
# Print results
anova_table
# Create the data schema
two_way_df = download_speeds[["Station ID","Trip Number","Download Speed (Mbps)"]]
two_way_df.reset_index(inplace=True)
two_way_df.columns = ['index', 'StationID', "TripNumber", 'DownloadSpeed']
# Print first 5 lines of the data schema
print(two_way_df.head())
# Ordinary Least Squares (OLS) model
model = ols('DownloadSpeed ~ C(StationID) / C(TripNumber)', data=two_way_df).fit()
print(model.summary())
# ANOVA - Anova table for one or more fitted linear models.
# URL:
# https://www.statsmodels.org/dev/generated/statsmodels.stats.anova.anova_lm.html
anova_table = sm.stats.anova_lm(model, typ=2)
# Main Variable: Site/Location
# Nested Variable: Camera trap ID/StationID
# Print results
anova_table
# Create the data schema
two_way_df = download_speeds[["Location","Trip Number","Station ID","Download Speed (Mbps)"]]
two_way_df.reset_index(inplace=True)
two_way_df.columns = ['index', 'Location', "TripNumber", "StationID", 'DownloadSpeed']
# Print first 5 lines of the data schema
print(two_way_df.head())
# Ordinary Least Squares (OLS) model
model = ols('DownloadSpeed ~ C(Location) / C(TripNumber) / C(StationID)', data=two_way_df).fit()
print(model.summary())
# ANOVA - Anova table for one or more fitted linear models.
# URL:
# https://www.statsmodels.org/dev/generated/statsmodels.stats.anova.anova_lm.html
anova_table = sm.stats.anova_lm(model, typ=2)
# Main Variable: Site/Location
# Nested Variable: Camera trap ID/StationID & Station ID
# Print results
anova_table