<jupyter_start><jupyter_text>We are going to do some basic data analysis using Python, Pandas, and statsmodel. So first we need to load these libraries:<jupyter_code>import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Lets look at sediment flux grouped by climate zone. We will load in a different data set:<jupyter_code>dfm = pd.read_csv('./data/milliman-farnsworth-database.csv',na_values=('<1','#VALUE!'))<jupyter_output><empty_output><jupyter_text>Rename Area so it is easier to use...<jupyter_code>dfm['Area'] = dfm['Area, km^2']<jupyter_output><empty_output><jupyter_text>Plot sediment flux as a function of catchment area<jupyter_code>plt.loglog(dfm.Area, dfm.Length, marker='o', linestyle='', ms=2)
plt.xlabel("Catchment area (km$^2$)")
plt.ylabel("Catchment Length (km)")
plt.show()<jupyter_output><empty_output><jupyter_text>Lets plot the scatter grouped by climate<jupyter_code>groups = dfm.groupby('Climate_T')
for Climate_T, group in groups:
    plt.loglog(group.Length, group.Area, marker='o', linestyle='', ms=2, label=Climate_T)
plt.legend(('Arctic','Subarctic','Subtropical','Temperate','Tropical'))
plt.xlabel("Catchment area (km$^2$)")
plt.ylabel("Water flux (km$^3$yr$^{-1}$)")
plt.show()<jupyter_output><empty_output><jupyter_text>Get linear regression and overlay plot<jupyter_code>for Climate_T, group in groups:
    plt.loglog(group.Length, group.Area, marker='o', linestyle='', ms=2, label=Climate_T)
plt.legend(('Arctic','Subarctic','Subtropical','Temperate','Tropical'))
plt.ylabel("Area (km$^{2}$)")
plt.xlabel("Length (km)")

X = np.log10(dfm['Length'])
y = np.log10(dfm['Area'])
model = sm.OLS(y,sm.add_constant(X),missing='drop').fit()
xx = np.arange(1e1,1e4)
yy = np.power(10,model.params[0])*np.power(xx,model.params[1])
plt.plot(xx,yy)
plt.show()<jupyter_output><empty_output><jupyter_text>model summary to get slope of regression<jupyter_code>model.summary()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16583912611717974, 'fraction_numerical': 0.010923535253227408, 'mean_word_length': 8.549763033175356, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '29391', 'license': 'MIT', 'n_tokens_mistral': 786, 'n_tokens_neox': 746, 'n_words': 146, 'path': 'length-area.ipynb', 'repo_name': 'johnjarmitage/erosion-and-regressions', 'size': '2014'}