How can I fit a model to predict the Pearson correlation coefficient between x and y as a function of z? All three variables are continuous.
The best I can come up with is to bin z and calculate the correlation separately within each bin. It seems there must be a better way to do this that preserves z as a continuous variable.
A concrete example: I'm interested in how mean annual rainfall correlates between two locations as a function of the distance between those locations. I have a dataset of sites with measured rainfall and know the distance between all pairs of sites.