last_year <- c(33, 36, 71, 48, 19, 69, 48)
current_year <- c(33, 39, 63, 51, 23, 77, 45)
n <- 2
cumsum_last_year <- cumsum(last_year)
r <- c(0.54463226, 0.15389852)
sample_units <- sapply(r, function(r_val) {
which(cumsum_last_year >= r_val * sum(last_year))[1]
})
cat("抽取的样本单元:", sample_units, "\n")
sample_current <- current_year[sample_units]
sample_last <- last_year[sample_units]
ht_estimate <- sum(sample_current / (sample_last / sum(last_year)))
cat("HT估计值 Ŷ_HT:", ht_estimate, "\n")
weights <- sum(last_year) / sample_last
contribution <- (sample_current / sample_last - ht_estimate / sum(last_year))^2
variance <- sum(contribution * weights) / (n - 1)
std_dev_hat <- sqrt(variance)
cat("标准差的估计值:", std_dev_hat, "\n")
mse_estimate <- variance
cat("均方偏差(MSE):", mse_estimate, "\n")