Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prediction function is not working #9

Closed
Pentaonia opened this issue Apr 20, 2023 · 3 comments
Closed

Prediction function is not working #9

Pentaonia opened this issue Apr 20, 2023 · 3 comments

Comments

@Pentaonia
Copy link

I trained a model and want to predict that to a data frame and to a data frame out of a raster. Both is not working.

model.stan <- stan4bart(
    formula = pa ~ bart(. - road_distance - urban_distance - water_distance) +
    (1 | road_distance) + (1 | urban_distance) + (1 | water_distance),
    verbose = 0, 
    data = PA_train,
    #test = PA_test,
    weights = my_weights,
    chains = 1, 
    iter = 10, 
    bart_args = list(n.trees = 10, keepTrees = T)
)
model.stan.predict <- predict(model.stan, newdata = as.data.frame(EU_environment_low, xy = T), type = "ev")

Following error:

Error in dimnames(indiv.bart) <- list(observation = NULL, sample = NULL,  : 
  length of 'dimnames' [3] must match that of 'dims' [2]

When I am using type = "indiv.ranef", it is working but this is not what I need.

Hopefully there is a solution.

Best
Loubert

@Pentaonia Pentaonia changed the title prediction is not working Prediction function is not working Apr 20, 2023
@Pentaonia
Copy link
Author

Hi,
I was able to figure out what was wrong. As soon as I am able to fully test, I can provide you with the code snippet.

Best
Louis

@Pentaonia
Copy link
Author

Hey,

when you run the stan4bart-model with chains = 1, then the indiv.bart object in the predict.stan4bartFit does not fit to the
dimnames(indiv.bart) <- list(observation = NULL, sample = NULL, chain = NULL). Therefore I included before that:

    if(length(dim(indiv.bart)) == 2){
    dim(indiv.bart) <- c(dim(indiv.bart),1)
    }

After including that, the prediction function is working properly, independent from the size of chains in the stan4bart call.

Best
Louis

@vdorie
Copy link
Owner

vdorie commented Apr 27, 2023

Thanks! Fixed in 6fc1a76.

@vdorie vdorie closed this as completed Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants