0

I have the following code, and it creates the plot perfectly but I want to have the beta, as well as the R2 for each graph.

g = sns.lmplot(data=corr, x="price", y="transactions", col="year", ci=95, fit_reg=True, col_wrap=3, scatter_kws={'linewidths':0.5,'edgecolor':'w'})
def annotate(data, **kws):
    r, p = sp.stats.pearsonr(corr['price'], corr['transactions'])
    ax  = plt.gca()
    ax.text(.05, .8, 'r={:.2f}, p={:.2g}'.format(r, p), transform=ax.transAxes)
g.map_dataframe(annotate)
plt.show()

but somehow the r2 and the p value are all the same across graphs, why?

Olive
  • 644
  • 4
  • 12
  • 1
    Yeah, that's what i thought to, i followed the second answer from this: https://stackoverflow.com/questions/25579227/seaborn-implot-with-equation-and-r2-text so not sure what i am doing wrong. – Olive Mar 22 '22 at 17:42
  • Typo: change `sp.stats.pearsonr(corr['price'], corr['transactions'])` to `sp.stats.pearsonr(data['price'], data['transactions'])` – BigBen Mar 22 '22 at 17:47
  • wow thanks! do you know how to add the beta to the stats?? – Olive Mar 22 '22 at 18:06

0 Answers0