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

如何基于ct值反向预测standard_conc_ngul?lm建模遇阻求助

问题背景

用标准数据构建了ct ~ log(standard_conc_ngul)的线性模型,R²达0.9857,拟合效果优异。但使用add_predictions()预测新数据的standard_conc_ngul时报错,原因是该函数默认预测模型的响应变量(ct),无法直接反推自变量。尝试反向建模standard_conc_ngul ~ exp(ct),R²仅0.1144,拟合效果极差。

正确预测方法

原模型的表达式为:
$$ct = \beta_0 + \beta_1 \times \log(\text{standard_conc_ngul})$$
将公式变形,反推出standard_conc_ngul的计算式:
$$\text{standard_conc_ngul} = \exp\left( \frac{ct - \beta_0}{\beta_1} \right)$$

1. 构建原模型

library(tidyverse)

# 加载模型数据
model_data <- structure(list(standard_conc_ngul = c(50, 50, 50, 5, 5, 0.5, 
0.5, 0.05, 0.05, 0.05, 0.005, 0.005), ct = c(16.263463973999, 
15.9799518585205, 15.8724918365479, 19.6285934448242, 19.5386505126953, 
21.3258514404297, 21.9189949035645, 23.639965057373, 23.511137008667, 
23.7562923431396, 25.9067344665527, 25.987663269043)), row.names = c(NA, 
-12L), class = c("tbl_df", "tbl", "data.frame"))

# 构建最优拟合模型
model <- lm(ct ~ log(standard_conc_ngul), data = model_data)
summary(model)

运行后可查看模型的截距$\beta_0$和系数$\beta_1$。

2. 反推计算新数据预测值

# 加载新数据
new_data <- structure(list(ct = c(36.4112663269043, 38.2640724182129, 32.7499198913574, 
34.9506607055664, 35.1940498352051, 33.6090316772461, 36.1515579223633, 
33.9076690673828, 30.9849720001221, 35.2763442993164, 35.5483360290527, 
28.1783123016357, 36.2575035095215, 37.1801261901855, 35.7146415710449, 
34.3365440368652, 35.3149261474609, 31.3500270843506, 36.0679473876953, 
28.4723072052002, 38.3946990966797, 33.8331108093262, 35.9874420166016, 
35.9941635131836, 34.1121406555176, 36.4313087463379, 33.7280616760254, 
31.6534538269043, 35.2425842285156, 37.5738525390625, 28.8860301971436, 
37.6940841674805, 33.6983222961426, 36.7991371154785, 35.6302680969238, 
33.453369140625, 29.2328281402588, 34.8536720275879, 36.5731735229492, 
26.4282283782959, 32.1904258728027, 36.5712852478027, 34.5956192016602, 
24.9539623260498, 33.6246643066406, 29.2099666595459, 35.8060531616211, 
38.0736312866211, 32.7279891967773, 37.5331420898438, 34.4548606872559, 
35.3194236755371, 38.7736511230469, 26.102840423584, 37.6750679016113, 
32.389274597168)), row.names = c(NA, -56L), class = c("tbl_df", 
"tbl", "data.frame"))

# 提取模型系数
b0 <- coef(model)[[1]]
b1 <- coef(model)[[2]]

# 计算预测值并添加到新数据中
new_data <- new_data %>%
  mutate(standard_conc_ngul_predicted = exp( (ct - b0)/b1 ))

# 查看前6行结果
head(new_data)

反向建模效果差的原因

线性模型要求响应变量服从正态分布且方差齐性。反向建模standard_conc_ngul ~ exp(ct)时,原模型的误差结构被反转,完全不符合线性回归的假设条件,因此拟合效果极差。而通过原模型公式反推,能保留原模型的优良拟合特性,得到准确的预测结果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 12:51:56