Hi, everyone,

I'm trying to test some models with my dataset to see if I find any correlation between the variables and the response. I ran 5 different models and the best model was 5.a, but the residual plots were not really satisfying

(please see the two boxplots attached) because I have different numbers of samples for different classes (at least that's what I thought that could be the responsible for this difference). You can find the best model here:

mod_Bd5a <- glm(Bd_pre_bi ~ Tourism + poly(Altitude,degree=2) + Livestock, data = data2, family=binomial())

So I looked for other options to try to make it better and the residual plots more balanced and I was suggested to bootstrap the analysis and add weights to the classes, due to the different amount of samples. I used this question here to test my data: bootstrap weighted mean in R - Stack Overflow

and copied the first command:

```
samplewmean <- function(d, i, j) {
d <- d[i, ]
w <- j[i, ]
return(weighted.mean(d, w))
}
```

followed by:

```
results_qsec <- boot(data= data2 [, 7, drop = FALSE],
statistic = samplewmean,
R=10000,
j = data2 [, 6 , drop = FALSE])
```

But I get the error message: **Error in weighted.mean.default(d, w) : (list) object cannot be coerced to type 'double'**

I already try to solve this problem using the solution suggested here - r - How to coerce a list object to type 'double' - Stack Overflow - but then I get another error message:

as.numeric(unlist(samplewmean))

Error in as.numeric(unlist(samplewmean)) :

cannot coerce type 'closure' to vector of type 'double'lapply(samplewmean, as.numeric)

Error in FUN(X[[i]], ...) :

cannot coerce type 'symbol' to vector of type 'double'

I don't know if it is clear to understand, I tried to put all the info I could remember.

Could someone help me with these error messages or with a better way to fit the data?

Thanks a lot,

Adriana