本文介绍了如何在 R 中使用季节性假人运行指数 nls?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在用 R 中的季节性假人运行 nls 回归时遇到问题.我可以在没有季节性假人的情况下做到这一点,但不能.这是我目前所拥有的:

year=floor(time(lsts))>月=轮(时间(lsts)-年,4)>月.f=因子(月)>假人=model.matrix(~month.f)hotdogNLS

总结(hotdogNLS)

公式:lsts ~ beta1/(1 + exp(beta2 + beta3 * t))参数:估计标准误差 t 值 Pr(>|t|)beta1 2.030e+03 5.874e+01 34.55 <2e-16 ***beta2 1.146e+00 5.267e-02 21.76 

我如何包含季节性假人?谢谢!

解决方案

我不认为在 nls 中实现了傻瓜,因为事实上它们在 glmnls 的公式"是一个真正的数学公式,与 glm 不同.

您仍然可以指定是否必须为每个类别的假人单独评估参数:

 数据(汽车)# 定义假人汽车$虚拟 <- as.factor(LETTERS[1:5])# 编码为 0/1 虚拟,每个虚拟级别有一列汽车$A<- as.numeric(cars$dummy=="A")汽车$B<- as.numeric(cars$dummy=="B")汽车$C

I'm having trouble with running an nls regression with seasonal dummies in R.I'm able to do it without the seasonal dummies, but not with.This is what I have so far:

year=floor(time(lsts))
> month=round(time(lsts)-year,4)
> month.f=factor(month)
> dummies=model.matrix(~month.f)
hotdogNLS<-nls(lsts~beta1/(1+exp(beta2+beta3*t)),start=list(beta1=2500,beta2=0.5,beta3=-0.5),trace=F)
Formula: lsts ~ beta1/(1 + exp(beta2 + beta3 * t))

Parameters:
        Estimate Std. Error t value Pr(>|t|)
beta1  2.030e+03  5.874e+01   34.55   <2e-16 ***
beta2  1.146e+00  5.267e-02   21.76   <2e-16 ***
beta3 -1.116e-02  7.668e-04  -14.56   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 192.3 on 333 degrees of freedom

Number of iterations to convergence: 8
Achieved convergence tolerance: 2.054e-06

How do I include seasonal dummies?Thanks!

解决方案

I don't think dummies are implemented for nls like they are in glm due to the fact that "formula" for nls is a real mathematical formula unlike for glm.

You can nevertheless specify if a parameter must be assessed separately for each class of a dummy:

    data(cars)
    # define the dummy
    cars$dummy <- as.factor(LETTERS[1:5])
    # code as 0/1 the dummy with a column per dummy level
    cars$A<- as.numeric(cars$dummy=="A")
    cars$B<- as.numeric(cars$dummy=="B")
    cars$C<- as.numeric(cars$dummy=="C")
    cars$D<- as.numeric(cars$dummy=="D")
    cars$E<- as.numeric(cars$dummy=="E")

    # precise in the formula where the dummy level should play out
    # here in the intercept:
    model <- nls(dist~beta1*speed^beta2+beta3*A+beta4*B+beta5*C+beta6*D+beta7*E,data=cars)

    model

    Nonlinear regression model
      model: dist ~ beta1 * speed^beta2 + beta3 * A + beta4 * B + beta5 * C + beta6 * D + beta7 * E
      data: cars
      beta1   beta2   beta3   beta4   beta5   beta6   beta7
      0.2069  1.8580  2.8266  5.3973 13.0002  9.3539  2.5361
      residual sum-of-squares: 10040

      Number of iterations to convergence: 8
      Achieved convergence tolerance: 4.924e-06

这篇关于如何在 R 中使用季节性假人运行指数 nls?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 17:54