简体   繁体   English

R:nls和lm不相同的加权指数函数

[英]R:Weighted Exponential Function with nls and lm not the same

im struggeling with something. 我在努力挣扎。 If i estimate an exponential function with lm and using transformation ie. 如果我用lm并使用变换即估计指数函数。

    leastsquares.complete=lm(log(PPPrate)~Highest+Mortrate5Y+Crate+DummieJan+DummieDec,weights=Notional)
b.completebestin= predict.lm(leastsquares.completebestout)
Forecast.completebestin= exp(b.completebestin)

I get different result than using a weighted nls 我得到的结果与使用加权nls的结果不同

form<-as.formula(PPPrate~exp(alfa0+alfa1*Highest+alfa2*Mortrate5Y+alfa3*Crate+alfa4*DummieJan+alfa5*DummieDec))
nlsresultshehe=nls(
  form,
  data=AllDataXX,
  start=list(alfa0=1,alfa1=1,alfa2=1,alfa3=1,alfa4=1,alfa5=1),trace=TRUE,
  weight=Notional,control=nls.control(minFactor=0.0001,maxiter = 5000))
T=summary(nlsresultshehe)$parameters
Forecast=exp(T[1,1]+Highest*T[2,1]+Mortrate5Y*T[3,1]+Crate*T[4,1]+DummieJan*T[5,1]+DummieDec*T[6,1])

Does it have something to do with the weighting scheme? 它与加权方案有关吗? im kinda lost here 我有点迷失在这里

You're fitting two different models. 您要拟合两个不同的模型。

  • The lm call fits a straight line through the log-transformed response. lm调用通过对数转换后的响应拟合一条直线。 It's finding the line that minimises the sum of squared residuals on the log scale. 正在找到使对数刻度上的残差平方和最小的线。
  • The nls call fits an exponential line without transforming anything. nls调用适合指数行而无需进行任何转换。 It's finding the line that minimises the sum of squared residuals on the original scale. 它找到的线使原始比例的残差平方和最小。

In general, you're not going to get the same result from both these cases. 通常,您不会从这两种情况下获得相同的结果。

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

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