You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于R中Pearson r相关系数贝叶斯估计似然函数准确性的咨询

Hey there! Let's break down how to verify your likelihood function for Bayesian estimation of Pearson $r$ using Fisher's r-to-z transformation in R. I notice you didn't share your actual code snippet, but I can walk you through what a correct implementation should look like, and you can cross-reference it with your own work.

Key Background for the Likelihood

First, a quick recap: Fisher's r-to-z transform converts a sample Pearson correlation $r$ to a value $z$ where:
z = 0.5 * log((1 + r)/(1 - r))
This transformed $z$ follows an approximate normal distribution, with mean $\zeta$ (the population-level transformed correlation) and standard error SE = 1/sqrt(n - 3)—where $n$ is your sample size. This normality is what makes the likelihood straightforward to define.

Correct Likelihood Implementations in R

There are two common ways to parameterize this likelihood: either directly in terms of the transformed population parameter $\zeta$, or in terms of the original Pearson $r$. Here's what each should look like:

1. Parameterized for $\zeta$ (Transformed Correlation)

If you're working with $\zeta$ as your parameter of interest, the likelihood is just the normal density of your observed transformed $z$ value, centered at $\zeta$:

# Replace these with your actual data values
r_obs <- 0.35  # Your sample Pearson correlation
n <- 40        # Your sample size

# Compute observed z-transform and standard error
z_obs <- 0.5 * log((1 + r_obs)/(1 - r_obs))
se_z <- 1 / sqrt(n - 3)

# Likelihood function for population zeta (ζ)
likelihood_zeta <- function(zeta) {
  dnorm(z_obs, mean = zeta, sd = se_z)
}

2. Parameterized for $r$ (Original Correlation)

If you want to work directly with the original $r$ (instead of $\zeta$), you need to include a Jacobian adjustment—this accounts for the change in variables when converting between $r$ and $\zeta$. The Jacobian for this transform is 1 - r^2, so you multiply the normal density by this term:

# Reuse observed values from above
r_obs <- 0.35
n <- 40
z_obs <- 0.5 * log((1 + r_obs)/(1 - r_obs))
se_z <- 1 / sqrt(n - 3)

# Likelihood function for population r
likelihood_r <- function(r) {
  # Convert r to population zeta
  zeta <- 0.5 * log((1 + r)/(1 - r))
  # Normal density * Jacobian adjustment
  dnorm(z_obs, mean = zeta, sd = se_z) * (1 - r^2)
}
How to Check Your Code

To confirm your likelihood function is accurate:

  • Double-check the Fisher transform formula—make sure you're using (1 + r)/(1 - r) inside the log, not the reverse.
  • If you're parameterizing in $r$, don't skip the Jacobian term! This is a super common mistake that will throw off your posterior.
  • Verify the standard error: it's always 1/sqrt(n - 3)—the "-3" comes from the degrees of freedom lost when estimating the mean and variance for the correlation.
  • Remember Bayes' theorem as you noted: the posterior is proportional to prior(x) * likelihood(x), so your likelihood needs to correctly reflect the sampling distribution of your observed $r$ (after transformation).

内容的提问来源于stack exchange,提问作者rnorouzian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:11:41