<code>predict()</code>

问题描述 投票:0回答:1
估计。

lag()

所有三个模型都是相同的:
library(plm)

data <- data.frame(country = rep(c("A", "B", "C"), each = 3),
                  year = rep(c(1, 2, 3), 3),
                  population = c(100, 150, 200, 1000, 1200, 1250, 10, 20, 45)) |>
        pdata.frame(index = c('country', 'year'))

data$lag_population <- plm::lag(data$population, k = 1)

lm_model <- lm(population ~ lag_population, data)
plm_model <- plm(population ~ plm::lag(population, k = 1), data, model = 'pooling')
plm_model2 <- plm(population ~ lag_population, data, model = 'pooling')
shyet,他们对相同数据的预测是不同的:

> print(lm_model) Call: lm(formula = population ~ lag_population, data = data) Coefficients: (Intercept) lag_population 31.633 1.079 + print(plm_model) Model Formula: population ~ plm::lag(population, k = 1) Coefficients: (Intercept) plm::lag(population, k = 1) 31.6332 1.0787 + print(plm_model2) Model Formula: population ~ lag_population Coefficients: (Intercept) lag_population 31.6332 1.0787
基于预期的预测,每个横截面的第一阶段(b/c第一期都没有滞后观测值)

lm()
使用生成的变量而不是
NA

函数的预测与

plm()
    函数相似,但是,drops删除了
  • lag_population
    预测使用使用
    lag()
  • 函数是最有问题的:值是向后移动1个周期,加上某些值是在上一个周期生成的(模型是汇总的,没有固定效果,那么如何在第一个周期生成预测,尤其是使用
  • lm()
    ?)
    
    NA
    有人遇到类似问题吗?
    如何使PLM预测看起来与基于
    plm()
    的预测相同
    	
  • 这已经在开发版本中修复了,请参见
  • Github.com/ycroissant/plm
    https://github.com/ycroissant/plm/
    
    
    将开发版本构建,例如:
  • lag()
以您的例子,它产生:

fill.na = FALSE

predict_plm <- predict(plm_model, newdata = data, na.fill = FALSE) predict_plm2 <- predict(plm_model2, newdata = data, na.fill = FALSE) predict_lm <- predict(lm_model, newdata = data) > print(predict_lm) A-1 A-2 A-3 B-1 B-2 B-3 C-1 C-2 C-3 NA 139.50424 193.43973 NA 1110.34313 1326.08511 NA 42.42035 53.20745 + print(predict_plm2) A-2 A-3 B-2 B-3 C-2 C-3 139.50424 193.43973 1110.34313 1326.08511 42.42035 53.20745 + print(predict_plm) A-1 A-2 A-3 B-1 B-2 B-3 C-1 C-2 C-3 139.50424 193.43973 247.37522 1110.34313 1326.08511 1380.02060 42.42035 53.20745 80.17519
r prediction panel-data plm
1个回答
0
投票
lm()

填充(通过)。因此,PLM的cormponds to LM通过以下论点进行了预测:

plm
    
	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.