0

my table kinda looks like this:

date        factor1      factor2     factor3
1973-01-31  3.112309    1.011383    NA
1973-02-28  2.120466    11.021701    NA
1973-03-31  1.125156    0.030822    1.011383    
1973-04-30  11.135342   1.067682    1.067682    
1973-05-31  NA          -1.069136    1.071959    
1973-06-30  1.139889    1.071959    1.034

I am trying to calculate the t-value testing the hypothesis that the mean of each column is equal to zero using the NeweyWest method.

coeftest(lm(data~1), vcov = NeweyWest(lm(data~1), lag = 6, prewhite = F, adjust = T))

However, I always receive the error code:

Error in dimnames(x) <- dn : 
  length of 'dimnames' [1] not equal to array extent

I am pretty sure this is due to the NAs in my table. I tried to use na.action of the lm function. However, this did not work. I can calculate the t-value for each column individually but I am looking for a solution to calculate the t-value for the whole table at once since it is a huge table. Does anyone have an idea to solve my problem? I am very thankful for every hint.

  • 1
    It could also be that you are trying to pass a data frame while the function is expecting a vector. You will likely need to use the apply function for this to work. – Dave2e Jun 18 '20 at 22:05
  • The table is in ```xts``` format. I can calculate the t-value of a column with the function ```coeftest(lm(as.integer(data$factor1)~1), vcov = NeweyWest(lm(as.integer(data$factor1)~1), lag = 6, prewhite = F, adjust = T)) ``` Is there any oppurtunity to calculate this for the whole table using one function? – Momentum4Ever Jun 18 '20 at 22:25

1 Answers1

0

may be you have to estimate missing values, e.g. https://stats.stackexchange.com/questions/26326/how-to-estimate-missing-data

Or looking for some so call robust methods (robust t test).

sparedev
  • 26
  • 3