BMA icon indicating copy to clipboard operation
BMA copied to clipboard

problem with bicreg, when the number of observations equals the number of coefficients

Open pfitznerl opened this issue 3 months ago • 2 comments

Hello,

I just started to use the powerfull BMA package, so maybe I am doing something wrong. But if not, I think there could be a problem in the function

residualVariance <- function(coef, x, y) { print(length(coef)) sum((y - fittedValues(coef, x))^2)/(length(y) - length(coef)) }

used in bicreg(). The problem appears when length(y) = length(coef) implying infinite values which causes the function quantBMAnormal to exit with an error because uniroot has an error.

I use R 3.6.1 and BMA 3.18.20

Here is a code that does not work at iteration t=13 and the data where I have the problem ("donnee" means data in french):

donnee_t_00_6_06088001.txt

library(BMA) donnee=read.table("donnee_t_00_6_06088001.txt",head=T,sep=";",na.strings=c(" NA"," NA"," NA"," NA"," NA"," NA"," NA","NA")) names(donnee)[which(names(donnee)=="Q20")]="Q30" liste_exp=c("raw.aro","mos.aro","raw.arp","mos.arp","raw.cep","mos.cep","Q10","Q30","Q50","Q70","Q90") X=donnee[,liste_exp] Y=donnee$obs.t Y=as.numeric(Y) Y=c(Y)

for (t in 1:nrow(X)){

print(t)
if (t>2) {
    bma_model=bicreg(X[1:(t-1),], Y[1:(t-1)], strict = FALSE, OR = 20)
    pred=predict(bma_model,X[t,])$mean
} else {
    pred=rowMeans(X[t,])
}
print(paste("prediction : ",pred,sep=""))

}

where predict(bma_model,X[t,])$mean should be "the BMA predictive mean is just the conditional expectation of y given the forecasts, namely" equation 4 of

mwre-mwr2906.1.pdf

Kind regards, Leo Pfitzner

pfitznerl avatar Oct 23 '25 11:10 pfitznerl