以下.lin4
将是AFTER
增加的金额Y
:
# test data
set.seed(123)
time<-seq(1,60)
Y<- -2.5+rnorm(60)+2*sin(2*pi*time/8)+2.5*(-1)^time
varia <- rep(c('BEFORE', 'AFTER'), each = 30)
fm <- nls(Y ~ cbind(1, sin(2 * pi * time/Alpha3), (-1)^time, varia == "AFTER"),
start = list(Alpha3 = 8), alg = "plinear")
summary(fm)
给予:
Formula: Y ~ cbind(1, sin(2 * pi * time/Alpha3), (-1)^time, (varia ==
"AFTER"))
Parameters:
Estimate Std. Error t value Pr(>|t|)
Alpha3 8.03367 0.02583 310.984 < 2e-16 ***
.lin1 -2.55242 0.16740 -15.247 < 2e-16 ***
.lin2 1.88528 0.16726 11.272 6.45e-16 ***
.lin3 2.53734 0.11828 21.453 < 2e-16 ***
.lin4 0.23992 0.23673 1.013 0.315
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.9159 on 55 degrees of freedom
Number of iterations to convergence: 3
Achieved convergence tolerance: 6.226e-07
因此,在这种情况下,除了最后一个参数外,所有参数都很重要,正如预期的那样。
REVISED重新阅读问题后修改。