简体   繁体   English

在 R 的指数方程中检索预测 function 使用的公式

[英]retrieve formula used by predict function in exponential equation in R

I can't figure out how to reconstruct the results nor the formula from the predict function of a linear model.我无法弄清楚如何从线性 model 的predict function 中重建结果或公式。 I get the same results also when using this data in ggplot geom_smooth(method='lm',formula,y ~ exp(x)).在 ggplot geom_smooth(method='lm',formula,y ~ exp(x)) 中使用此数据时,我也得到相同的结果。

Here's some sample data这是一些示例数据

x=c(1,10,100,1000,10000,100000,1000000,3000000)
y=c(1,1,10,15,20,30,40,60)

I would like to use an exponential function so (ignore for the moment that I log the x value, because exp() fails for very large values):我想使用指数 function 所以(暂时忽略我记录 x 值,因为 exp() 对于非常大的值失败):

model = lm( y ~ exp(log10(x)))
mypred = predict(model)
plot(log(x),mypred)

I have tried我努力了

lm_coef <- coef(model)
plot(log10(x),lm_coef[1]*exp(-lm_coef[2]*x))

However this is giving me a decreasing exponential instead of the increasing.然而,这给了我一个递减的指数而不是增加。 My goal is to extract the equation of the exponential function so I can reuse the coefficients in another context.我的目标是提取指数 function 的方程,以便我可以在另一个上下文中重用系数。 . . What equation is predict() using and is there a way to see it? predict() 使用什么方程,有没有办法看到它?

I did something along the lines of:我做了一些类似的事情:

Df<-data.frame(x=c(1,10,100,1000,10000,100000,1000000,3000000),
               y=c(1,1,10,15,20,30,40,60))


model<-lm(data = Df, formula = y~log(x))
predict(model)
plot(log(Df$x),predict(model))

summary(model)

The relevant output you get is:您得到的相关 output 是:

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -6.0700     4.7262  -1.284 0.246386    
log(x)        3.5651     0.5035   7.081 0.000398 ***
---

Your equation therefore is 3.5651*log(x)-6.0700因此,您的等式是 3.5651*log(x)-6.0700

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM