Giter Club home page Giter Club logo

Comments (3)

philmikejones avatar philmikejones commented on September 1, 2024

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.

philmikejones avatar philmikejones commented on September 1, 2024

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.

philmikejones avatar philmikejones commented on September 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.