2017-02-02 1 views
0

と回帰モデルでのコントラストを変更するI持って次のデータ(例):Y2005は、Y2006、Y2007、およびY2008は毎年ある私はR.で回帰モデルを推定について質問がありますR

Year XY 
2002 5 
2003 2 
2004 4 
2005 8 
2006 3 
2007 5 
2008 10 

the regression model I want to estimate is: 
XY = B0 + Y2005 + Y2006 + Y2007 + Y2008 + e 

指標変数は、2005年、2006年、2007年、2008年および0年のそれぞれについて1の値をとる。

2005年、2006年、2007年、2008年の(XY)の値を(2002-2004)の期間の(XY)の平均値と比較する必要があります。

私はこの問題を理解して助けていただきありがとうございます。

答えて

0
DF <- read.table(text = "Year XY 
       2002 5 
       2003 2 
       2004 4 
       2005 8 
       2006 3 
       2007 5 
       2008 10", header = TRUE) 

DF$facYear <- DF$Year 
DF$facYear[DF$facYear < 2005] <- "baseline" 
DF$facYear <- factor(DF$facYear) 

#make sure that baseline is used as intercept: 
DF$facYear <- relevel(DF$facYear, "baseline") 

fit <- lm(XY ~ facYear, data = DF) 
summary(fit) 
#Coefficients: 
#   Estimate Std. Error t value Pr(>|t|) 
#(Intercept) 3.6667  0.8819 4.158 0.0533 . 
#facYear2005 4.3333  1.7638 2.457 0.1333 
#facYear2006 -0.6667  1.7638 -0.378 0.7418 
#facYear2007 1.3333  1.7638 0.756 0.5286 
#facYear2008 6.3333  1.7638 3.591 0.0696 . 
+0

ありがとうございます@Roland –

関連する問題