A demonstration of the MESS.plotting.plot_simulations_hist
routine, which plots histograms for sets of simulations grouped by community_assembly_model
. Very useful for getting a sense of how your parameters impact the summary statistics.
%load_ext autoreload
%autoreload 2
%matplotlib inline
import matplotlib.pyplot as plt
from IPython.display import display,SVG
from scipy.stats import entropy
import MESS
import numpy as np
import pandas as pd
import collections
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
The autoreload extension is already loaded. To reload it, use: %reload_ext autoreload
Here we'll select only the sumstats relevant to the abundance and trait axes. Select only simulations of lambda 0.85 +/- 0.1, and do not normalize the Hill numbers.
simfile = "/home/isaac/Continuosity/MESS/analysis/figure5-sims/SIMOUT.txt"
_ = MESS.plotting.plot_simulations_hist(simfile, verbose=True, normalize_hills=True,\
figsize=(20, 20), select=0.75, tol=.1,\
feature_set=MESS.stats.feature_sets()["abundance+pi+trait"])
Removed invariant targets. Retained: ['S', 'abund_h1', 'abund_h2', 'abund_h3', 'abund_h4', 'pi_h1', 'pi_h2', 'pi_h3', 'pi_h4', 'mean_pi', 'std_pi', 'skewness_pi', 'kurtosis_pi', 'median_pi', 'iqr_pi', 'SGD_0', 'SGD_1', 'SGD_2', 'SGD_3', 'SGD_4', 'SGD_5', 'SGD_6', 'SGD_7', 'SGD_8', 'SGD_9', 'abundance_pi_cor', 'trait_h1', 'trait_h2', 'trait_h3', 'trait_h4', 'mean_local_traits', 'std_local_traits', 'skewness_local_traits', 'kurtosis_local_traits', 'median_local_traits', 'iqr_local_traits', 'mean_regional_traits', 'std_regional_traits', 'skewness_regional_traits', 'kurtosis_regional_traits', 'median_regional_traits', 'iqr_regional_traits', 'reg_loc_mean_trait_dif', 'reg_loc_std_trait_dif', 'reg_loc_skewness_trait_dif', 'reg_loc_kurtosis_trait_dif', 'reg_loc_median_trait_dif', 'reg_loc_iqr_trait_dif', 'abundance_trait_cor', 'pi_trait_cor'] Nsims neutral 354 filtering 352 competition 294
_ = MESS.plotting.plot_simulations_hist(simfile, verbose=True, normalize_hills=True, select=0.75, tol=0.1,\
nsims=10000, feature_set=["abund_h1"])
Removed invariant targets. Retained: ['abund_h1'] Nsims neutral 1617 filtering 1544 competition 1511
_ = MESS.plotting.plot_simulations_hist(simfile, verbose=True, normalize_hills=True, select=0.75, tol=0.05,\
nsims=10000, feature_set=["S"], bins=40)
Removed invariant targets. Retained: ['S'] Nsims neutral 815 filtering 772 competition 759
_ = MESS.plotting.plot_simulations_hist(simfile, verbose=True, normalize_hills=True,\
select=0.75, feature_set=["generation"])
Removed invariant targets. Retained: ['generation'] Nsims neutral 110 filtering 112 competition 103
_ = MESS.plotting.plot_simulations_hist(simfile, verbose=True, normalize_hills=True,\
feature_set=["extrate_calculated"])
Removed invariant targets. Retained: ['extrate_calculated'] Nsims neutral 333 filtering 347 competition 320
_ = MESS.plotting.plot_simulations_hist(simfile, verbose=True, normalize_hills=True,\
feature_set=["std_local_traits"])
Removed invariant targets. Retained: ['std_local_traits'] Nsims neutral 333 filtering 347 competition 320
_ = MESS.plotting.plot_simulations_hist(simfile, verbose=True, select=0.5, normalize_hills=False,\
feature_set=["mean_pi"])
Removed invariant targets. Retained: ['mean_pi'] Nsims neutral 137 filtering 117 competition 112
Testing plotting the bins of the SGD in a SFS style. I like it, but it really confuses people.
fig, ax = plt.subplots(figsize=(20, 10))
ax.legend(fontsize=20)
cols = {"neutral":"blue", "filtering":"orange", "competition":"red"}
for lab, df in dfs.items():
X = df.filter(regex="SGD*")
X = X.div(X.sum(axis=1), axis=0)
ax.plot(X.mean(), linewidth=3, label=lab, alpha=0.7, color=cols[lab])
ax.fill_between(range(0, 10), X.mean()+X.std(), X.mean()-X.std(), color=cols[lab], alpha=0.1)
ax.legend(fontsize=20)
<matplotlib.legend.Legend at 0x7fc0bd630b10>
fig, ax = plt.subplots(figsize=(20, 10))
width=1/4.
xs = np.array(xrange(0, 10))
X = neut_df.filter(regex="SGD*")
ax.bar(xs, X.div(X.sum(axis=1), axis=0).mean(), width=width, label="neutral", color="blue", alpha=0.8)
X = filt_df.filter(regex="SGD*")
ax.bar(xs+width, filt_df.filter(regex="SGD*").div(X.sum(axis=1), axis=0).mean(), width=width, label="filtering", color="orange", alpha=0.8)
X = comp_df.filter(regex="SGD*")
ax.bar(xs+2*width, comp_df.filter(regex="SGD*").div(X.sum(axis=1), axis=0).mean(), width=width, label="competition", color="red", alpha=0.8)
#for lab, df in dfs.items():
# X = df.filter(regex="SGD*")
# X = X.div(X.sum(axis=1), axis=0)
# ax.plot(X.mean(), linewidth=3, label=lab, alpha=0.7, color=cols[lab])
# ax.fill_between(range(0, 10), X.mean()+X.std(), X.mean()-X.std(), color=cols[lab], alpha=0.1)
ax.legend(fontsize=20)
<matplotlib.legend.Legend at 0x7fc0bcb3f850>