Skip to content

Commit 6b125e9

Browse files
nt-williamsclaude
andcommitted
Propagate critical_value through arithmetic operations
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d4662d8 commit 6b125e9

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: ife
22
Type: Package
33
Title: Autodiff for Influence Function Based Estimates
4-
Version: 0.2.3
4+
Version: 0.2.4
55
Authors@R:
66
c(person(given = "Nicholas",
77
family = "Williams",

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# ife 0.2.4
2+
3+
* Propagate `critical_value` through arithmetic operations. Binary operations between two estimates use the maximum critical value.
4+
15
# ife 0.2.3
26

37
* Adding `^` method for raising estimates to a power via the delta method.

R/influence_func_estimand.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ method(print, influence_func_estimate) <- function(x, ...) {
139139
# x + y
140140
method(`+`, list(influence_func_estimate, influence_func_estimate)) <- function(e1, e2) {
141141
check_same(e1, e2)
142-
influence_func_estimate(e1@x + e2@x, e1@eif + e2@eif, e1@weights, e1@id)
142+
influence_func_estimate(e1@x + e2@x, e1@eif + e2@eif, e1@weights, e1@id, max(e1@critical_value, e2@critical_value))
143143
}
144144

145145
method(`+`, list(influence_func_estimate, class_numeric)) <- function(e1, e2) {
146-
influence_func_estimate(e1@x + e2, e1@eif, e1@weights, e1@id)
146+
influence_func_estimate(e1@x + e2, e1@eif, e1@weights, e1@id, e1@critical_value)
147147
}
148148

149149
# Delegate to ife + scalar since addition is commutative
@@ -152,15 +152,15 @@ method(`+`, list(class_numeric, influence_func_estimate)) <- function(e1, e2) e2
152152
# x - y
153153
method(`-`, list(influence_func_estimate, influence_func_estimate)) <- function(e1, e2) {
154154
check_same(e1, e2)
155-
influence_func_estimate(e1@x - e2@x, e1@eif - e2@eif, e1@weights, e1@id)
155+
influence_func_estimate(e1@x - e2@x, e1@eif - e2@eif, e1@weights, e1@id, max(e1@critical_value, e2@critical_value))
156156
}
157157

158158
method(`-`, list(influence_func_estimate, class_numeric)) <- function(e1, e2) {
159-
influence_func_estimate(e1@x - e2, e1@eif, e1@weights, e1@id)
159+
influence_func_estimate(e1@x - e2, e1@eif, e1@weights, e1@id, e1@critical_value)
160160
}
161161

162162
method(`-`, list(class_numeric, influence_func_estimate)) <- function(e1, e2) {
163-
influence_func_estimate(e1 - e2@x, -e2@eif, e2@weights, e2@id)
163+
influence_func_estimate(e1 - e2@x, -e2@eif, e2@weights, e2@id, e2@critical_value)
164164
}
165165

166166
# x / y
@@ -170,36 +170,36 @@ method(`/`, list(influence_func_estimate, influence_func_estimate)) <- function(
170170
stop("Division by zero: denominator estimate is zero", call. = FALSE)
171171
}
172172
eif <- (e1@eif / e2@x) - ((e2@eif / e2@x^2) * e1@x)
173-
influence_func_estimate(e1@x / e2@x, eif, e1@weights, e1@id)
173+
influence_func_estimate(e1@x / e2@x, eif, e1@weights, e1@id, max(e1@critical_value, e2@critical_value))
174174
}
175175

176176
method(`/`, list(class_numeric, influence_func_estimate)) <- function(e1, e2) {
177177
if (abs(e2@x) < .Machine$double.eps) {
178178
stop("Division by zero: denominator estimate is zero", call. = FALSE)
179179
}
180-
influence_func_estimate(e1 / e2@x, -e1 / e2@x^2 * e2@eif, e2@weights, e2@id)
180+
influence_func_estimate(e1 / e2@x, -e1 / e2@x^2 * e2@eif, e2@weights, e2@id, e2@critical_value)
181181
}
182182

183183
method(`/`, list(influence_func_estimate, class_numeric)) <- function(e1, e2) {
184184
if (abs(e2) < .Machine$double.eps) {
185185
stop("Division by zero: denominator is zero", call. = FALSE)
186186
}
187-
influence_func_estimate(e1@x / e2, 1 / e2 * e1@eif, e1@weights, e1@id)
187+
influence_func_estimate(e1@x / e2, 1 / e2 * e1@eif, e1@weights, e1@id, e1@critical_value)
188188
}
189189

190190
# x * y
191191
method(`*`, list(influence_func_estimate, influence_func_estimate)) <- function(e1, e2) {
192192
check_same(e1, e2)
193-
influence_func_estimate(e1@x * e2@x, e2@x * e1@eif + e1@x * e2@eif, e1@weights, e1@id)
193+
influence_func_estimate(e1@x * e2@x, e2@x * e1@eif + e1@x * e2@eif, e1@weights, e1@id, max(e1@critical_value, e2@critical_value))
194194
}
195195

196196
method(`*`, list(class_numeric, influence_func_estimate)) <- function(e1, e2) {
197-
influence_func_estimate(e1 * e2@x, e1 * e2@eif, e2@weights, e2@id)
197+
influence_func_estimate(e1 * e2@x, e1 * e2@eif, e2@weights, e2@id, e2@critical_value)
198198
}
199199

200200
# x^n
201201
method(`^`, list(influence_func_estimate, class_numeric)) <- function(e1, e2) {
202-
influence_func_estimate(e1@x^e2, e2 * e1@x^(e2 - 1) * e1@eif, e1@weights, e1@id)
202+
influence_func_estimate(e1@x^e2, e2 * e1@x^(e2 - 1) * e1@eif, e1@weights, e1@id, e1@critical_value)
203203
}
204204

205205
# Delegate to scalar * ife since multiplication is commutative
@@ -210,10 +210,10 @@ method(log, influence_func_estimate) <- function(x, base) {
210210
if (x@x <= 0) {
211211
stop("log() requires positive values: estimate is ", x@x, call. = FALSE)
212212
}
213-
influence_func_estimate(log(x@x), x@eif / x@x, x@weights, x@id)
213+
influence_func_estimate(log(x@x), x@eif / x@x, x@weights, x@id, x@critical_value)
214214
}
215215

216216
# exp(x)
217217
method(exp, influence_func_estimate) <- function(x) {
218-
influence_func_estimate(exp(x@x), exp(x@x) * x@eif, x@weights, x@id)
218+
influence_func_estimate(exp(x@x), exp(x@x) * x@eif, x@weights, x@id, x@critical_value)
219219
}

0 commit comments

Comments
 (0)