knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
For instructions on using this package, please see thepackage Manual.
The calculation can be described as follows:
For each household individually...
msni
to the largest value of health
, protection
and shelter
msni
to the impact
score, if impact
is lower than the previous msni
. msni
to the largets value of msni
, wash
, fsl
, capacity gaps
if that is larger than the previous msni
msni
to 2
if and only ifmsni
is currently 1
3
msni
to NA
if any of the input scores was NA
Here is the actual code.
# 1. set `msni` to the largest value of `health`, `protection` and `shelter` msni <- pmax(health_lsg,protection_lsg,shelter_lsg) # 2. set `msni` to the `impact` score, if `impact` is lower than the previous `msni`. msni <- pmin(msni, impact) # 3. set `msni` to the largets value of `msni`, `wash`, `fsl`, `capacity gaps` if that is larger than the previous `msni` largest_lsg_combination_hps <- pmax( pmin(health_lsg,protection_lsg), pmin(health_lsg, shelter_lsg), pmin(protection_lsg,shelter_lsg) ) msni <- pmax(msni, largest_lsg_combination_hps) # If higher than current, replace with highest from wash, FSL or capacity gap msni <- pmax(msni, wash_lsg,fsl_lsg,capacity_gaps) #4.A is `msni` is currently `1` _and_ one of health, protection, shelter and education is larger than `3` ? max_of_remaining <- c(custom_input_indices,list(health_lsg,protection_lsg,shelter_lsg,education_lsg)) %>% as.data.frame(stringsAsFactors = FALSE) %>% apply(1,max,na.rm = FALSE) max_of_remaining_larger_equal_3 <- max_of_remaining >= 3 note_applies<-(msni ==1) & max_of_remaining_larger_equal_3 # 4.B set `msni` to `2` where condition above applies msni[note_applies]<- 2
Dictionary for non-programmers:
<-
means "resplace" or "assign" the value to the namepmin()
the smallest of the values in parenthesis (per record)pmax()
the largest of the values in parenthesis (per record)variable[condition] <-
replace / assign only if/where condition is metAdd the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.