Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在lm()中表示时间段虚拟变量_R_Lm - Fatal编程技术网

R 如何在lm()中表示时间段虚拟变量

R 如何在lm()中表示时间段虚拟变量,r,lm,R,Lm,我正在分析x_t对y_t的影响在特定时间段内和之后是否有所不同。 我试图使用lm(),在R中回归以下模型: 其中D_t是一个虚拟变量,在整个时间段内的值为1,否则为0 这个公式可以使用lm()吗?观测次数你有多少周期?周期向量是什么样子的?我在10年内观察了80次。我想用假人把它们分成两个时段。第二个时段什么时候开始?在第55个obs。这是一个有趣的新方法!obsFactor[55,81)和x:obsFactor[55,81)是否表示水平变化和趋势变化的系数? observationNumber

我正在分析x_t对y_t的影响在特定时间段内和之后是否有所不同。 我试图使用
lm()
,在R中回归以下模型:

其中D_t是一个虚拟变量,在整个时间段内的值为1,否则为0


这个公式可以使用
lm()
吗?

观测次数你有多少周期?周期向量是什么样子的?我在10年内观察了80次。我想用假人把它们分成两个时段。第二个时段什么时候开始?在第55个obs。这是一个有趣的新方法!
obsFactor[55,81)
x:obsFactor[55,81)
是否表示水平变化和趋势变化的系数?
observationNumber <- 1:80
obsFactor <- cut(observationNumber, breaks = c(0,55,81), right =F)
fit <- lm(y ~ x * obsFactor)
observationNumber <- 1:80
obsFactor <- cut(observationNumber, breaks = c(0,55,81), right =F)
fit <- lm(y ~ x * obsFactor)
 y = runif(80)
 x = rnorm(80) + c(rep(0,54), rep(1, 26))
 fit <- lm(y ~ x * obsFactor)
 summary(fit)

Call:
lm(formula = y ~ x * obsFactor)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.48375 -0.29655  0.05957  0.22797  0.49617 

Coefficients:
                   Estimate Std. Error t value Pr(>|t|)    
(Intercept)         0.50959    0.04253  11.983   <2e-16 ***
x                  -0.02492    0.04194  -0.594    0.554    
obsFactor[55,81)   -0.06357    0.09593  -0.663    0.510    
x:obsFactor[55,81)  0.07120    0.07371   0.966    0.337    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.3116 on 76 degrees of freedom
Multiple R-squared:  0.01303,   Adjusted R-squared:  -0.02593 
F-statistic: 0.3345 on 3 and 76 DF,  p-value: 0.8004