如果我的模型是y〜log(x),我应该提供x或log(x)吗?

发布于 2025-02-13 04:56:32 字数 572 浏览 2 评论 0原文

我有一个安装lm

log_log_model = lm(log(price) ~ log(carat), data = diamonds)`

我想使用此模型预测Price的模型,但是我不确定是否应该输入log(carat)CARAT值为precadion()函数中的预测变量?

选择1

exp(predict(log_log_model, data.frame(carat = log(3)),
            interval = 'predict', level = 0.99))

选择2

exp(predict(log_log_model, data.frame(carat = 3),
    interval = 'predict', level = 0.99))

哪一个是正确的?

I have a fitted lm model

log_log_model = lm(log(price) ~ log(carat), data = diamonds)`

I want to predict price using this model, but I'm not sure if I should be entering log(carat) or carat value as predictor into the predict() function?

Choice 1

exp(predict(log_log_model, data.frame(carat = log(3)),
            interval = 'predict', level = 0.99))

Choice 2

exp(predict(log_log_model, data.frame(carat = 3),
    interval = 'predict', level = 0.99))

Which one is correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海少女心 2025-02-20 04:56:32

选择2是正确的。

要给您一些额外的信心,让我们检查一下设计矩阵时的样子。

## for diamonds dataset
library(ggplo2)

## log-log linear model
fit <- lm(log(price) ~ log(carat), data = diamonds)

## for prediction
newdat <- data.frame(data.frame(carat = 3))

## evaluate the design matrix for prediction
Xp <- model.matrix(delete.response(terms(fit)), data = newdat)
#  (Intercept) log(carat)
#1           1   1.098612

看到吗? carat = 3自动评估为log(carat)= log(3)

Choice 2 is correct.

To give you some extra bit of confidence, let's inspect what the design matrix looks like when we make prediction.

## for diamonds dataset
library(ggplo2)

## log-log linear model
fit <- lm(log(price) ~ log(carat), data = diamonds)

## for prediction
newdat <- data.frame(data.frame(carat = 3))

## evaluate the design matrix for prediction
Xp <- model.matrix(delete.response(terms(fit)), data = newdat)
#  (Intercept) log(carat)
#1           1   1.098612

See it? carat = 3 is automatically evaluated to log(carat) = log(3).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文