Robinlovelace / spatial-microsim-book

Code, data and prose of the book: Spatial Microsimulation with R
https://www.crcpress.com/Spatial-Microsimulation-with-R/Lovelace-Dumont/p/book/9781498711548
MIT License
114 stars 76 forks source link

Broken code in GREGWT section #80

Closed Robinlovelace closed 9 years ago

Robinlovelace commented 9 years ago

This code fails here:

for(area in seq(dim(age)[1])){
    gregwt = GREGWT(data_in, area_code = area)
    fw <- gregwt$final_weights
    fweights <- c(fweights, fw)
    ## Estimate income
    sum.income <- sum(fw * ind$income)
    cap.income <- sum(fw * ind$income / sum(fw))
    Result[area,] <- c(area, sum.income, cap.income)
}

## Error in Tx_complete[i, ] : subscript out of bounds

Just not running the code is not a good solution! https://github.com/Robinlovelace/spatial-microsim-book/commit/f02fb394fe179f1f84a4b6d50d9e4ddc9ba631ce

Please take a look @emunozh

New version of GREGWT is looking good.

emunozh commented 9 years ago
    gregwt = GREGWT(data_in = data_in, area_code = area)

data_in is a function input that needs to be explicitly define because of the different available methods to define input data in the GREGWT function.