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

两组含可变数据量的空间平均时间序列配对差异T检验咨询

Weighted Paired t-Test for Daily Means with Unequal Sample Sizes

Great question! Since you’re working with paired daily means from two 30-day experiments (same time period, matched days), the core paired test framework still makes sense—but we can’t ignore the varying daily sample sizes (especially days with very few observations). Ordinary paired t-tests treat each daily mean as equally reliable, which isn’t fair when some means are based on way more data than others. Here’s a step-by-step solution:

1. First, Validate the Pairing & Clean Your Data

  • Keep the pairing intact: Each day’s mean from Experiment A is directly matched to the same day’s mean from Experiment B—this is the foundation of a paired test, so don’t break this structure.
  • Drop low-quality days: If a day has extremely few observations (e.g., n < 2 for either experiment), its mean is too unreliable to include. Filter these out first (you’ll still have a paired dataset for the remaining days).

2. Use a Weighted Paired t-Test

The key is to weight each daily mean difference by the reliability of that day’s estimates. Since the variance of a sample mean is inversely proportional to its sample size, we weight each difference by a value that reflects how much data went into calculating both means that day.

Step-by-Step Calculation

Let’s define for each day (i):

  • (d_i = \text{Mean}_A(i) - \text{Mean}_B(i)) (the difference between the two experiments’ daily means)
  • (n_{A,i}) = number of observations for Experiment A on day (i)
  • (n_{B,i}) = number of observations for Experiment B on day (i)

a. Calculate Weights

Since you mentioned (n_{A,i}) and (n_{B,i}) are "extremely close" most days, you can simplify weights to (w_i = n_{A,i}) (or (n_{B,i}), or their average). For full rigor, use the weight that accounts for both sample sizes:

w_i = (n_{A,i} * n_{B,i}) / (n_{A,i} + n_{B,i})

This weight is proportional to the inverse of the variance of (d_i) (assuming the underlying population variance of your meteorological variable is the same across both experiments).

b. Compute Weighted Mean Difference

The weighted average of your daily differences gives a more reliable estimate of the true overall difference:

d̄_w = (Σ(w_i * d_i)) / (Σw_i)

c. Compute Weighted Variance of Differences

This measures the spread of the weighted differences, adjusted for degrees of freedom (number of valid days minus 1):

s_{dw}^2 = [Σ(w_i * (d_i - d̄_w)^2)] / (k - 1)

where (k) = number of valid days (after filtering out low-sample days).

d. Calculate the t-Statistic & p-Value

The t-statistic follows a t-distribution with (k-1) degrees of freedom:

t = d̄_w / (s_{dw} / sqrt(Σw_i))

You can look up the p-value using a t-distribution table, or use statistical software to compute it directly.

3. Software Example (R)

If you’re using R, here’s how to implement this with a sample dataset:

# Sample data frame (replace with your actual data)
df <- data.frame(
  day = 1:30,
  meanA = rnorm(30, 10, 2),
  meanB = rnorm(30, 9.8, 2),
  nA = sample(5:20, 30, replace = TRUE),
  nB = sample(5:20, 30, replace = TRUE)
)

# Calculate daily differences
df$d <- df$meanA - df$meanB

# Calculate rigorous weights
df$w <- (df$nA * df$nB) / (df$nA + df$nB)

# Filter out days with tiny weights (e.g., n < 2 for either group)
df_filtered <- df[df$nA >= 2 & df$nB >= 2, ]

# Compute weighted mean difference
weighted_mean_d <- weighted.mean(df_filtered$d, df_filtered$w)

# Compute weighted variance
weighted_var_d <- sum(df_filtered$w * (df_filtered$d - weighted_mean_d)^2) / (nrow(df_filtered) - 1)

# Compute t-statistic and p-value
t_stat <- weighted_mean_d / (sqrt(weighted_var_d) / sqrt(sum(df_filtered$w)))
p_value <- 2 * pt(-abs(t_stat), df = nrow(df_filtered) - 1)

# Print results
cat("Weighted Mean Difference:", round(weighted_mean_d, 3), "\n")
cat("t-Statistic:", round(t_stat, 3), "\n")
cat("p-Value:", round(p_value, 4), "\n")

4. What If Normality Fails?

If your weighted differences don’t follow a normal distribution (check with a Q-Q plot or Shapiro-Wilk test), use a weighted Wilcoxon signed-rank test instead. This non-parametric alternative doesn’t require normality and can also account for sample size weights.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:51:39