Comments (3)
Example internal validation function:
int_validate <- function(constraints, ind_agg) {
correlation <- cor(as.numeric(constraints), as.numeric(ind_agg))
max_abs_diff <- max(abs(ind_agg - constraints))
tae <- tae(constraints, ind_agg)
sae <- tae(constraints, ind_agg) / sum(constraints)
cor_vec <- rep(0, dim(constraints)[1])
for (i in 1:dim(constraints)[1]) {
cor_vec[i] <- cor(as.numeric(constraints[i, ]), as.numeric(ind_agg[i, ]))
}
# cor_vec <- summary(cor_vec)
tae_vec <- rep(0, nrow(constraints))
sae_vec <- rep(0, nrow(constraints))
for (i in 1:nrow(constraints)) {
tae_vec[i] <- tae(constraints[i, ], ind_agg[i, ])
sae_vec[i] <- tae_vec[i] / sum(constraints[i, ])
}
worst_zone <- which.max(tae_vec)
# worst_zone <- tae_vec[worst_zone] / sum(tae_vec))
out <- list(
"correlation" = correlation,
"max_abs_diff" = max_abs_diff,
"tae" = tae,
"sae" = sae,
"cor_vec" = cor_vec,
"tae_vec" = tae_vec,
"sae_vec" = sae_vec,
"worst_zone" = worst_zone
)
out
}
from raker.
Example external validation function:
ext_validate <- function(llid_val, constraint, simdf, code_geo) {
llid_val <- llid_val %>%
select(GEOGRAPHY_CODE, C_DISABILITY_NAME, OBS_VALUE) %>%
spread(C_DISABILITY_NAME, OBS_VALUE)
llid_val$llid <- rowSums(llid_val[, 2:3])
colnames(llid_val) <- c("code", "little", "lot",
"llid_no_census", "llid_census")
llid_val <- select(llid_val, -little, -lot)
context("Check llid_val object")
test_that("Population of llid_val matches constraint", {
expect_equal(sum(llid_val[, 2:3]),
sum(constraint[, grep("age_[[:digit:]]", colnames(constraint))]))
})
# Add sim_llid to zone_simdf_oa
llid_sim <- simdf %>%
select(c_llid, zone) %>%
count(zone, c_llid) %>%
spread(c_llid, n)
colnames(llid_sim) <- c("zone", "llid_no_sim", "llid_sim")
llid_sim$code <- NA
llid_sim$code <- codes[[as.character(code_geo)]]
# merge on codes (not rbind) because prison OAs removed!
llid_val <- left_join(llid_val, llid_sim, by = "code")
llid_val
}
from raker.
Example percentage error function:
calc_perr <- function(llid_val) {
total <- rowSums(llid_val[, c("llid_no_census", "llid_census")])
perr <- llid_val$llid_census - llid_val$llid_sim
perr <- abs(perr)
perr <- perr / total
perr <- perr * 100
perr
}
from raker.
Related Issues (20)
- Add progress bar
- prevent extract() working with numeric variables HOT 1
- Implement combinatorial optimization
- Handle zeros gracefully HOT 2
- extract is masked by tidyverse::extract HOT 1
- Refactor/remove checks in functions HOT 1
- Submit enquiry to ropensci HOT 2
- Peer review of rakeR HOT 2
- Rename functions with `rk_` prefix for tab autocompletion
- Error with `rake()`
- Test returns warning that rake() is deprecated HOT 1
- Move check functions to deprecated HOT 1
- Check all `cons` populations match
- Update function reference on documentation website HOT 1
- Update documentation and NEWS to reflect changes to function names HOT 1
- Simplify rk_weight() HOT 1
- Refactor rk_extract() and tests HOT 1
- Refactor rk_integerise() and tests
- refactor rk_rake() and tests
- Error when running rk_rake HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raker.