【问题标题】:Performing VIF Test in R在 R 中执行 VIF 测试
【发布时间】:2016-11-23 14:57:21
【问题描述】:

几天前我开始使用 R studio,但我在计算 VIF 时有点吃力。情况如下:

我有一个面板数据并运行了固定效应和随机效应回归。我有一个因变量(New_biz_density)和两个自变量(Cost_to_startCapital_requirements)。我想通过计算固定和随机效应模型的方差膨胀因子来检查我的两个自变量是否存在多重共线性。

我已经安装了一些包来执行 VIF(FarawayCar),但没有成功。有人知道怎么做吗?

这是我的脚本:

# install.packages("plm")
library(plm)

mydata<- read.csv("/Users/juliantabone/Downloads/DATAweakoutliers.csv")


Y <- cbind(new_biz_density)
X <- cbind(capital_requirements, cost_to_start)

# Set data as panel data
pdata <- plm.data(mydata, index=c("country_code","year"))

# Descriptive statistics
summary(Y)
summary(X)

# Pooled OLS estimator
pooling <- plm(Y ~ X, data=pdata, model= "pooling")
summary(pooling)

# Between estimator
between <- plm(Y ~ X, data=pdata, model= "between")
summary(between)

# First differences estimator
firstdiff <- plm(Y ~ X, data=pdata, model= "fd")
summary(firstdiff)

# Fixed effects or within estimator
fixed <- plm(Y ~ X, data=pdata, model= "within")
summary(fixed)

# Random effects estimator
random <- plm(Y ~ X, data=pdata, model= "random")
summary(random)

# LM test for random effects versus OLS
plmtest(pooling)

# LM test for fixed effects versus OLS
pFtest(fixed, pooling)

# Hausman test for fixed versus random effects model
phtest(random, fixed)

【问题讨论】:

    标签: r plm


    【解决方案1】:

    在 R 中似乎有两种流行的计算 VIF(方差膨胀因子,用于检测回归变量之间的共线性)的方法:

    car 包中的vif() 函数,其中输入是模型。这要求您首先拟合模型,然后才能检查模型中变量之间的 VIF。

    corvif() 函数,其中输入是实际的候选解释变量(即在模型拟合之前的变量列表)。此功能是 AED 包 (Zuur et al. 2009) 的一部分,该包已停产。这似乎只适用于变量列表,而不适用于拟合回归模型。

    【讨论】:

      【解决方案2】:

      要计算 VIF,请从 metan 包中引用函数 non_collinear_vars

      要计算两个变量 Cost_to_startCapital_requirements 之间的 VIF,请使用,

      library(metan)
      non_collinear_vars(X)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-30
        • 2021-02-11
        • 1970-01-01
        • 2021-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多