Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

regression - How do I run an exponential nls with seasonal dummies in R?

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)

summary(hotdogNLS)

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the factor to subset the estimated coefficient like alpha[dummy].

data(cars)
cars$dummy <- as.factor(LETTERS[1:5])

nls(dist ~ alpha[dummy] + beta1*speed^beta2, data=cars, start=list(beta1=.2, beta2=3, alpha=rep(10, nlevels(cars$dummy))))
#Nonlinear regression model
#  model: dist ~ alpha[dummy] + beta1 * speed^beta2
#   data: cars
#  beta1   beta2  alpha1  alpha2  alpha3  alpha4  alpha5 
# 0.2069  1.8580  2.8264  5.3971 13.0000  9.3537  2.5359 
# residual sum-of-squares: 10040
#
#Number of iterations to convergence: 12 
#Achieved convergence tolerance: 2.372e-06

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...