R: Waldtest: “Error in solve.default(vc[ovar, ovar]) : 'a' is 0-diml”

半世苍凉 提交于 2019-12-11 18:17:25

问题


If there is already an answer to my problem, i apologize for asking my question. So far, I couldn't find one.

I'm currently doing a regression for financial data of bonds. Objective of my regression is to determine if two portfolios of bonds are showing significant different yields. I´m controlling for 4 variables (V1 to V4) to control for other sources of risk.

The regression formula is the following:

(one regression for "High-Portfolio", one regression for "Low-Portfolio")

𝑌ield(p)=∝(p)+ 𝛽1(p)*V1+𝛽2(p)*V2+𝛽3(p)*V3(p)+𝛽4(p)*V4(p)  

which results in the following code in R:

   Regression_High <- lm(T_Portfolio ~ T_Slope +T_Credit+T_Ratingscore+ T_Duration)


 (construct variables for Low-Portfolio)


   Regression_Low <- lm(T_Portfolio ~ T_Slope +T_Credit+T_Ratingscore+ T_Duration)

The idea now is to compare the two intercepts to determine if the two portfolios show different yields.

For that reason, i want to use a Wald test to determine the joint significance of the intercepts: The test statistic is asymptotically x²-distributed with 2 degrees of freedom.

library(aod)
library(lmtest)
Vcov=vcov(Regression_High,Regression_Low)

1. waldtest(Regression_High, Regression_Low, vcov=Vcov,test="Chisq",name=NULL)

2. waldtest(Regression_High, Regression_Low, test="Chisq")

Both of my attempts produce the following error message:

Error in solve.default(vc[ovar, ovar]) : 'a' is 0-diml

Does anybody know how to conduct the waldtest correctly or where my mistake is?

Any advice or suggestions will be appreciated.

Kind regards,

Simon

Reproducible example:

#loading packages
library(plm)
library(aod)
library(lmtest)

#Data "High-Portfolio"
y=rnorm(10)
v1=rnorm(10)
v2=rnorm(10)
v3=rnorm(10)
v4=rnorm(10)

#Regression 1

lm1<-lm(y~v1+v2+v3+v4)

#Data "Low-Portfolio"
y=rnorm(10)
v1=rnorm(10)
v2=rnorm(10)
v3=rnorm(10)
v4=rnorm(10)

#Regression 2 

lm2<-lm(y~v1+v2+v3+v4)

#Waldtest
library(aod)
library(lmtest)
Vcov=vcov(lm1,lm2)

#Attempt 1
waldtest(lm1,lm2, vcov=Vcov,test="Chisq",name=NULL)

#Attempt 2
waldtest(lm1, lm2, test="Chisq")

回答1:


As I understand it, the waldtest takes two different models on the same object (not two models on two different objects). You need different variables in your two models in order for it to run. The error is thrown at: solve(vc[ovar, ovar]), and is telling you vc[ovar, ovar] doesn't have any dimensions. This is where ovar comes from

ovar <- which(!(names(coef0(fm1)) %in% names(coef0(fm0))))

fm1and fm0 are your two models, which have the same variables.



来源:https://stackoverflow.com/questions/49230697/r-waldtest-error-in-solve-defaultvcovar-ovar-a-is-0-diml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!