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

Weights argument for binomial models in sdmTMB, mgcv, glm, or glmmTMB #93

Closed
seananderson opened this issue May 19, 2022 · 1 comment
Closed

Comments

@seananderson
Copy link
Member

Arnaud Mosnier writes:

In one of my previous projects I have used the BAM function (mgcv package) to fit a logistic model. I have used the “weights” parameter to weight the contribution of each data point to the likelihood.
I plan to test sdmTBM for my next project, still using a logistic model, and I wonder how the “weights” parameter compare to the BAM’s one.

In the BAM help it is defined as :
Prior weights on the contribution of the data to the log likelihood. Note that a weight of 2, for example, is equivalent to having made exactly the same observation twice. If you want to reweight the contributions of each datum without changing the overall magnitude of the log likelihood, then you should normalize the weights (e.g. weights <- weights/mean(weights)).

While in sdmTMB, it is:

A numeric vector representing optional likelihood weights for the conditional model. Implemented as in glmmTMB: weights do not have to sum to one and are not internally modified. Can also be used for trials with the binomial family; the weights argument needs to be a vector and not a name of the variable in the data frame. See the Details section below.

It seems there is a different interpretation of the “weights” using BAM vs sdmTMB when using the “binomial” family.

@seananderson
Copy link
Member Author

seananderson commented May 19, 2022

Despite the different descriptions (we based the binomial weights section in sdmTMB on glm()), I believe these are all doing the same thing. Here's an example:

set.seed(1)
w <- rpois(100, 10)
y <- rbinom(100, size = w, prob = 0.4)
data <- data.frame(y = y / w)
m1 <- mgcv::gam(y ~ 1, data = data, family = binomial(), weights = w)
m2 <- glm(y ~ 1, data = data, family = binomial(), weights = w)
m3 <- sdmTMB::sdmTMB(y ~ 1, data = data, family = binomial(), weights = w, spatial = 'off')
m4 <- glmmTMB::glmmTMB(y ~ 1, data = data, family = binomial(), weights = w)
coef(m1)
#> (Intercept) 
#>   -0.526955
coef(m2)
#> (Intercept) 
#>   -0.526955
sdmTMB::tidy(m3)
#>          term  estimate std.error
#> 1 (Intercept) -0.526955 0.0656508
broom.mixed::tidy(m4)
#> # A tibble: 1 × 7
#>   effect component term        estimate std.error statistic  p.value
#>   <chr>  <chr>     <chr>          <dbl>     <dbl>     <dbl>    <dbl>
#> 1 fixed  cond      (Intercept)   -0.527    0.0657     -8.03 1.00e-15

Created on 2022-05-19 by the reprex package (v2.0.1)

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

1 participant