Calculates Net Energy Burden with proper aggregation methodology via the Net Energy Return (Nh) framework. For individual households, NEB = EB = S/G. When aggregating across households (with weights), automatically uses the Nh method to avoid 1-5% aggregation errors.
Arguments
- g
Numeric vector of gross income values
- s
Numeric vector of energy spending values
- se
Optional numeric vector of effective energy spending (defaults to s)
- weights
Optional numeric vector of weights for aggregation (e.g., household counts). When provided, uses Nh method:
1 / (1 + weighted.mean(nh, weights))- aggregate
Logical, if TRUE forces aggregation even without weights (uses unweighted mean). Default FALSE for backwards compatibility.
Value
If
weights = NULLandaggregate = FALSE: Numeric vector of individual NEB values (S/G)If
weightsprovided oraggregate = TRUE: Single aggregated NEB value via Nh method
Details
Individual Level: NEB = EB = S/G (mathematically identical)
Aggregation Modes:
No aggregation (default): Returns vector of individual NEB values
Weighted aggregation: Automatically uses Nh method when weights provided
Unweighted aggregation: Use
aggregate = TRUEfor simple mean
Why Nh Method? Avoids 1-5% error from naive averaging:
CORRECT:
neb_func(g, s, weights = w)→ Uses Nh internallyWRONG:
weighted.mean(s/g, w)→ Introduces bias
The Nh method: 1 / (1 + weighted.mean(nh, weights)) where nh = (g-s)/se
uses arithmetic mean instead of harmonic mean, providing computational
simplicity and numerical stability.
See also
ner_func() for the Net Energy Return (Nh) calculation
energy_burden_func() for simple EB without aggregation support
Examples
# Individual household - returns vector
neb_func(50000, 3000) # 0.06
#> [1] 0.06
neb_func(c(30000, 50000), c(3000, 3500)) # c(0.10, 0.07)
#> [1] 0.10 0.07
# Aggregation with weights - returns single value (CORRECT method)
incomes <- c(30000, 50000, 75000)
spending <- c(3000, 3500, 4000)
households <- c(100, 150, 200)
neb_func(incomes, spending, weights = households)
#> [1] 0.06528497
# Unweighted aggregation
neb_func(incomes, spending, aggregate = TRUE)
#> [1] 0.06970954
# Comparison: naive mean (WRONG) vs Nh method (CORRECT)
neb_naive <- weighted.mean(spending/incomes, households) # Biased
neb_correct <- neb_func(incomes, spending, weights = households) # Correct
abs(neb_naive - neb_correct) / neb_correct # ~1-5% error
#> [1] 0.06087596