问题
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))))
fm1
and 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