Skip to content

Commit 444ccf9

Browse files
authored
Merge pull request #39 from ikosmidis/develop
Develop
2 parents f748bc9 + 2769231 commit 444ccf9

18 files changed

+86
-62
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ README_cache
3030
^CRAN-RELEASE$
3131
^code_of_conduct\.md$
3232
^CRAN-SUBMISSION$
33+
^doc$
34+
^Meta$

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,6 @@ flycheck_*.el
115115
.dir-locals.el
116116

117117
# network security
118-
/network-security.data
118+
/network-security.data
119+
/doc/
120+
/Meta/

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: brglm2
22
Title: Bias Reduction in Generalized Linear Models
3-
Version: 0.9.1
3+
Version: 0.9.2
44
Authors@R: c(person(given = "Ioannis", family = "Kosmidis", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-1556-0302")),
55
person(given = c("Euloge", "Clovis"), family = c("Kenne Pagui"), role = "aut", email = "[email protected]"),
66
person(given = "Kjell", family = "Konis", role = "ctb", email = "[email protected]"),

NEWS.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
# brglm2 0.9.2
2+
3+
## Improvements, updates and additions
4+
5+
* Convergence of the `brglm_fit` iterations is now determined if the L^Inf norm of the step size (rather than the L^1 as it was previously) of the quasi-Fisher scoring procedure is less than `epsilon` (see `?brglm_control` for the definition of `epsilon`). This is more natural as `epsilon` then determines directly the precision of the reported estimates and does not depend on their number.
6+
7+
* `brglm_control()` now checks that the supplied value of `max_step_factor` is numeric and greater or equal to `1`. If not, then it is set to the default value of `12`.
8+
9+
* Vignette updates
10+
11+
112
# brglm2 0.9.1
213

3-
## Other improvements, updates and additions
14+
## Improvements, updates and additions
415

516
* Added the `enzymes` and `hepatitis` data sets (from the [*pmlr*](https://cran.r-project.org/package=pmlr)) to support examples and tests.
617

@@ -14,7 +25,7 @@
1425

1526
* Fixed a bug where the dispersion in the resulting object would not be transformed even if `transformation != "identity"` when `type` is `ML` or `AS_median` or `AS_mixed`.
1627

17-
## Other improvements, updates and additions
28+
## Improvements, updates and additions
1829

1930
* Moved unit tests to [**tinytest**](https://cran.r-project.org/package=tinytest).
2031

@@ -26,7 +37,7 @@
2637

2738
# brglm2 0.8.2
2839

29-
## Other improvements, updates and additions
40+
## Improvements, updates and additions
3041

3142
* Housekeeping.
3243
* Removed lpSolveAPI from imports.
@@ -37,7 +48,7 @@
3748

3849
* Fixed a bug when predicting from `bracl` objects with non-identifiable parameters.
3950

40-
## Other improvements, updates and additions
51+
## Improvements, updates and additions
4152

4253
* Work on output consistently from `print()` methods for `summary.XYZ`
4354
objects; estimator type is now printed and other fixes.
@@ -72,7 +83,7 @@
7283
* `brglmFit()` iteration returns last estimates that worked if
7384
iteration fails.
7485

75-
## Other improvements, updates and additions
86+
## Improvements, updates and additions
7687

7788
* Documentation and example updates.
7889

@@ -92,7 +103,7 @@
92103
(`check_aliasing = FALSE`) rank deficiency checks (through a QR
93104
decomposition of the model matrix), saving some computational effort.
94105

95-
## Other improvements, updates and additions
106+
## Improvements, updates and additions
96107
* updated DOI links in documentation and some http -> https fixes.
97108

98109
# brglm2 0.7.0
@@ -104,15 +115,15 @@
104115
## New functionality
105116
* `confint` method for `brmulitnom` objects
106117

107-
## Other improvements, updates and additions
118+
## Improvements, updates and additions
108119
* Updated reference to [Kenne Pagui et al (2017)](https://doi.org/10.1093/biomet/asx046).q
109120
* Updated reference to [Kosmidis and Firth (2020)](https://doi.org/10.1093/biomet/asaa052).
110121
* Fixed issues with references.
111122
* Updated documentation.
112123

113124
# brglm2 0.6.2
114125

115-
## Other improvements, updates and additions
126+
## Improvements, updates and additions
116127
* `vcov.brglmFit()` now uses `vcov.summary.glm()` and supports the
117128
`complete` argument for controlling whether the variance covariance
118129
matrix should include rows and columns for aliased parameters.
@@ -130,7 +141,7 @@
130141
`bracl` objects.
131142
* `detect_separation()` now handles one-column model matrices correctly.
132143

133-
## Other improvements, updates and additions
144+
## Improvements, updates and additions
134145
* Documentation improvements and typo fixes.
135146

136147
# brglm2 0.6
@@ -140,7 +151,7 @@
140151
supported generalized linear models. See the help files of
141152
`brglmControl()` and `brglmFit()` for details.
142153

143-
## Other improvements, updates and additions
154+
## Improvements, updates and additions
144155
* Documentation updates and improvements.
145156
* Updated vignettes to include maximum penalized likelihood with
146157
powers of the Jeffreys prior as penalty.
@@ -156,14 +167,14 @@
156167
for more fine-tuning of the starting values when `brglmFit()` is
157168
called with `start = NULL`.
158169

159-
## Other improvements, updates and additions
170+
## Improvements, updates and additions
160171
* Documentation updates and improvements.
161172
* Added Kosmidis et al (2019) in the description file.
162173
* Added tests for `brglmControl()`.
163174

164175
# brglm2 0.5.1
165176

166-
## Other improvements, updates and additions
177+
## Improvements, updates and additions
167178
* Fixed typos in vignettes and documentation.
168179
* Added ORCHID for Ioannis Kosmidis in DESCRIPTION.
169180

@@ -191,15 +202,15 @@ Added `residuals()` methods for `brmultinom` and `bracl` objects
191202
misclassification in binomial response models (Neuhaus, 1999,
192203
Biometrika).
193204

194-
## Other improvements, updates and additions
205+
## Improvements, updates and additions
195206
* Improved `summary()` method for `brmultinom` objects.
196207
* Better starting values for null fits.
197208
* Added references to [arxiv:1804.04085](https://arxiv.org/abs/1804.04085) in
198209
documentation.
199210
* Updated reference to [Kenne Pagui et al (2017)](https://doi.org/10.1093/biomet/asx046).
200211

201212
# brglm2 0.1.8
202-
## Other improvements, updates and additions
213+
## Improvements, updates and additions
203214
* Improved documentation examples.
204215
* Removed warning about observations with non-positive weights from brmultinom.
205216
* Updated email address for Ioannis Kosmidis in brglmFit.
@@ -212,15 +223,15 @@ Added `residuals()` methods for `brmultinom` and `bracl` objects
212223

213224
# brglm2 0.1.7
214225

215-
## Other improvements, updates and additions
226+
## Improvements, updates and additions
216227
* Eliminated errors from markdown chunks in multinomial vignette.
217228

218229
# brglm2 0.1.6
219230

220231
## Bug fixes
221232
* Compatibility with new version of enrichwith.
222233

223-
## Other improvements, updates and additions
234+
## Improvements, updates and additions
224235
* New email for Ioannis Kosmidis.
225236

226237
# brglm2 0.1.5
@@ -237,7 +248,7 @@ Added `residuals()` methods for `brmultinom` and `bracl` objects
237248
`detect_separation()` methods in line with the update of
238249
`glm.fit()`.
239250

240-
## Other improvements, updates and additions
251+
## Improvements, updates and additions
241252
* less strict tolerance in `brglm_control()`.
242253
* Updates to help files.
243254
* Fixed typos in iteration vignette.
@@ -263,7 +274,7 @@ Added `residuals()` methods for `brmultinom` and `bracl` objects
263274
`detectSeparationControl()`, `detect_separation_control()`,
264275
`checkInfiniteEstimates()`, `check_infinite_estimates()`).
265276

266-
## Other improvements, updates and additions
277+
## Improvements, updates and additions
267278
* Minor enhancements in the codebase.
268279
* The inverse expected information matrix is computed internally using
269280
`cho2inv()`.
@@ -272,12 +283,8 @@ Added `residuals()` methods for `brmultinom` and `bracl` objects
272283

273284
# brglm2 0.1.3
274285

275-
## Bug fixes
276-
277-
## New functionality
278-
279-
## Other improvements, updates and additions
280-
* Fixed typo in f_{Y_i}(y) in iteration vignette (thanks to Eugene
286+
## Improvements, updates and additions
287+
* Fixed typo in $f_{Y_i}(y)$ in iteration vignette (thanks to Eugene
281288
Clovis Kenne Pagui for spotting),
282289

283290
# brglm2 0.1.2

R/brglm2-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
#' 185-196. \doi{10.1002/wics.1296}.
9797
#'
9898
#' @docType package
99+
#' @aliases brglm2-package
99100
#' @name brglm2
100101
#' @import stats
101102
#' @import enrichwith

R/brglmControl.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ brglmControl <- function(epsilon = 1e-06, maxit = 100,
201201
}
202202
if (!is.numeric(epsilon) || epsilon <= 0)
203203
stop("value of 'epsilon' must be > 0")
204+
205+
if (!is.numeric(max_step_factor) || max_step_factor < 1) {
206+
warning("`max_step_factor = ", deparse(max_step_factor), "` is not a permissible value. Defaulting to 12")
207+
max_step_factor <- 12
208+
}
204209
list(epsilon = epsilon, maxit = maxit, trace = trace,
205210
check_aliasing = check_aliasing,
206211
response_adjustment = response_adjustment,

R/brglmFit.R

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -876,29 +876,35 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL
876876
for (iter in seq.int(control$maxit)) {
877877
step_factor <- 0
878878
testhalf <- TRUE
879+
879880
## Inner iteration
880881
while (testhalf & step_factor < control$max_step_factor) {
881882
## store previous values
882-
betas0 <- betas; dispersion0 <- dispersion
883+
## betas0 <- betas
884+
## dispersion0 <- dispersion
883885
step_beta_previous <- step_beta
884886
step_zeta_previous <- step_zeta
887+
885888
## Update betas
886889
betas <- betas + slowit * 2^(-step_factor) * step_beta
890+
887891
## Update zetas
888892
if (!no_dispersion & df_residual > 0) {
889893
transformed_dispersion <- eval(control$Trans)
890894
transformed_dispersion <- transformed_dispersion + 2^(-step_factor) * step_zeta
891895
dispersion <- eval(control$inverseTrans)
892896
}
897+
893898
## Compute key quantities
894899
theta <- c(betas, dispersion)
895900
transformed_dispersion <- eval(control$Trans)
896-
## Mean quantities
897901

902+
## Mean quantities
898903
quantities <- try(key_quantities(theta, y = y, level = 2 * !no_dispersion, scale_totals = has_fixed_totals, qr = TRUE), silent = TRUE)
899904
## This is to capture qr failing and revering to previous estimates
900905
if (failed_adjustment_beta <- inherits(quantities, "try-error")) {
901-
betas <- betas0; dispersion <- dispersion0
906+
## betas <- betas0
907+
## dispersion <- dispersion0
902908
warning("failed to calculate score adjustment")
903909
break
904910
}
@@ -912,10 +918,9 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL
912918
warning("failed to calculate score adjustment")
913919
break
914920
}
915-
adjusted_grad_beta <- with(step_components_beta, {
916-
grad + adjustment
917-
})
921+
adjusted_grad_beta <- with(step_components_beta, grad + adjustment)
918922
step_beta <- drop(step_components_beta$inverse_info %*% adjusted_grad_beta)
923+
919924
## Dispersion quantities
920925
if (no_dispersion) {
921926
adjusted_grad_zeta <- step_zeta <- NA_real_
@@ -929,28 +934,28 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL
929934
warning("failed to calculate score adjustment")
930935
break
931936
}
932-
adjusted_grad_zeta <- with(step_components_zeta, {
933-
grad + adjustment
934-
})
937+
adjusted_grad_zeta <- with(step_components_zeta, grad + adjustment)
935938
step_zeta <- as.vector(adjusted_grad_zeta * step_components_zeta$inverse_info)
936939
}
940+
941+
## Convergence criteria
942+
linf_current <- max(abs(c(step_beta, step_zeta)), na.rm = TRUE)
943+
linf_previous <- max(abs(c(step_beta_previous, step_zeta_previous)), na.rm = TRUE)
944+
testhalf <- linf_current > linf_previous
945+
937946
## Continue inner loop
938-
if (step_factor == 0 & iter == 1) {
939-
testhalf <- TRUE
940-
} else {
941-
s2 <- c(abs(step_beta), abs(step_zeta))
942-
s1 <- c(abs(step_beta_previous), abs(step_zeta_previous))
943-
testhalf <- sum(s2, na.rm = TRUE) > sum(s1, na.rm = TRUE)
944-
}
947+
## if (step_factor == 0 & iter == 1) {
948+
## testhalf <- TRUE
949+
## }
945950
step_factor <- step_factor + 1
951+
946952
## Trace here
947953
if (control$trace) {
948-
949954
trace_iteration()
950955
}
951956
}
952957
failed <- failed_adjustment_beta | failed_inversion_beta | failed_adjustment_zeta | failed_inversion_zeta
953-
if (failed | sum(abs(c(step_beta, step_zeta)), na.rm = TRUE) < control$epsilon) {
958+
if (failed | linf_current < control$epsilon) {
954959
break
955960
}
956961
}
@@ -987,6 +992,7 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL
987992
## residuals and working_weights
988993

989994
quantities <- key_quantities(c(betas, dispersion), y = y, level = 2 * !no_dispersion, scale_totals = has_fixed_totals, qr = TRUE)
995+
990996
qr.Wx <- quantities$qr_decomposition
991997

992998
mus <- quantities$mus

R/brmultinom.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
#' contrasts(hepat$type) <- contr.treatment(3, base = 1)
143143
#'
144144
#' # Maximum likelihood estimation fails to converge because some estimates are infinite
145-
#' hepML <- brmultinom(type ~ group * time, data = hepat, weights = counts, type = "ML")
145+
#' hepML <- brmultinom(type ~ group * time, data = hepat, weights = counts, type = "ML", slowit = 0.1)
146146
#'
147147
#' # Mean bias reduction returns finite estimates
148148
#' hep_meanBR <- brmultinom(type ~ group * time, data = hepat, weights = counts, type = "AS_mean")

inst/tinytest/test-binomial.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ library("brglm")
22
data("lizards", package = "brglm2")
33
links <- lapply(c("logit", "probit", "cloglog", "cauchit"), make.link)
44

5-
tol <- 1e-10
5+
tol <- 1e-08
66
for (l in seq_along(links)) {
77
expect_warning(
88
lizardsBRlegacy <- brglm(cbind(grahami, opalinus) ~ height + diameter +

inst/tinytest/test-bracl.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ s2p <- summary(fit_vgam_p)
8585

8686
tol <- 1e-06
8787
## summary method for bracl returns the correct coef mat
88-
expect_equal(coef(s1), coef(s2), tolerance = tol, check.attributes = FALSE)
89-
expect_equal(coef(s1p), coef(s2p), tolerance = tol, check.attributes = FALSE)
88+
expect_equal(coef(s1), s2@coef3, tolerance = tol, check.attributes = FALSE)
89+
expect_equal(coef(s1p), s2p@coef3, tolerance = tol, check.attributes = FALSE)
9090

9191
newdata <- expand.grid(gender = c("male", "female"), religion = c("moderate", "fundamentalist"))
9292
## predict.bracl works as expected
9393
pp <- predict(fit_bracl_p, newdata = stemcell, type = "probs")
9494
p <- predict(fit_bracl, newdata = stemcell, type = "probs")
9595
expect_equal(predict(fit_vgam_p, type = "response"),
9696
pp[19:24, ],
97-
tolerance = 1e-08, check.attributes = FALSE)
97+
tolerance = 1e-06, check.attributes = FALSE)
9898
expect_equal(predict(fit_vgam, type = "response"),
9999
p[19:24, ],
100-
tolerance = 1e-08, check.attributes = FALSE)
100+
tolerance = 1e-06, check.attributes = FALSE)
101101

102102
## no intercept returns warning
103103
expect_warning(

inst/tinytest/test-jeffreys.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ data("lizards", package = "brglm2")
4141
links <- lapply(c("logit", "probit", "cloglog", "cauchit"), make.link)
4242

4343

44-
tol <- 1e-10
44+
tol <- 1e-08
4545
for (l in seq_along(links)) {
4646
expect_warning(
4747
lizardsBRlegacy <- brglm(cbind(grahami, opalinus) ~ height + diameter +

inst/tinytest/test-transformation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ c_sqrt[5] <- c_sqrt[5]^2
2424
c_inverse <- coef(mod_inverse, model = "full")
2525
c_inverse[5] <- 1/c_inverse[5]
2626

27-
tol <- sqrt(.Machine$double.eps)
27+
tol <- 1e-08
2828
## ML estimate of gamma dispersion from brglmFit is invariant to trasnformation
2929
expect_equal(c_identity, c_log, tolerance = tol, check.attributes = FALSE)
3030
expect_equal(c_identity, c_sqrt, tolerance = tol, check.attributes = FALSE)

man/brglm2.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)