简体   繁体   中英

Seaborn Pairplot Pearsons P statistic

I've been working through an assignment of data analysis as a novice at python/seaborn/scipy.stats/matplotlib.pyplot etc

Seaborn Correlation Coefficient on PairGrid this link which has helped me to present a relationship between my variables via a pearsons R score. However since the output of the Pearsons test also should have ap value in order to indicate statistical significance I am looking at a way to add the P value to the annotation on my plot.

g = sns.pairplot(unoutlieddata, vars=['bia', 'DW', 'HW', 'jackson', 'girths'], kind="reg")

def corrfunc(x, y, **kws):
    r, _ = sps.pearsonr(x, y)
    ax = plt.gca()
    ax.annotate("r = {:.2f}".format(r),
                xy=(.1, .9), xycoords=ax.transAxes)

g.map(corrfunc)
sns.plt.show()

Shown is my code in the format of the link provided. sps=scipy.stats. unoutlied data is a dataframe which has been filtered to remove outliers

Any ideas would be Fantastic

Regards

Not sure if anyone will ever see this but after speaking to someone who knows a bit more the answer was as follows

Code

import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import pearsonr

def corrfunc(x, y, **kws):
    (r, p) = pearsonr(x, y)
    ax = plt.gca()
    ax.annotate("r = {:.2f} ".format(r),
                xy=(.1, .9), xycoords=ax.transAxes)
    ax.annotate("p = {:.3f}".format(p),
                xy=(.4, .9), xycoords=ax.transAxes)

df = sns.load_dataset("iris")
df = df[df["species"] == "setosa"]
graph = sns.pairplot(df)
graph.map(corrfunc)
plt.show()

Result

seaborn pairplot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM