From 538ee6d0b7598c0d6414475904617282cfd61127 Mon Sep 17 00:00:00 2001 From: AssiALi16 <154439283+AssiALi16@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:09:11 +0300 Subject: [PATCH 1/4] Updated FCS Indicator Calculation in Python, R, Stata, and SPSS --- .gitignore | 1 + .../FCS-indicator-calculation.R | 243 ++++++------------ .../FCS-indicator-calculation.do | 97 ++++--- .../FCS-indicator-calculation.py | 85 ++++++ .../FCS-indicator-calculation.sps | 104 +++++--- 5 files changed, 287 insertions(+), 243 deletions(-) create mode 100644 Indicators/Food-consumption-score/FCS-indicator-calculation.py diff --git a/.gitignore b/.gitignore index e1eff70..6066991 100644 --- a/.gitignore +++ b/.gitignore @@ -80,5 +80,6 @@ rsconnect/ # CUSTOM Indicators/Food-consumption-score/.Rhistory *.xlsx +*.csv *.sav node_modules \ No newline at end of file diff --git a/Indicators/Food-consumption-score/FCS-indicator-calculation.R b/Indicators/Food-consumption-score/FCS-indicator-calculation.R index 3f0de9a..c896c3a 100644 --- a/Indicators/Food-consumption-score/FCS-indicator-calculation.R +++ b/Indicators/Food-consumption-score/FCS-indicator-calculation.R @@ -1,166 +1,87 @@ #------------------------------------------------------------------------------# - -# WFP RAM Standardized Scripts -# Calculating FCS - +# WFP RAM Standardized Scripts +# Food Consumption Score (FCS) Calculation in R +#------------------------------------------------------------------------------# +# 1. Purpose: +# This script calculates the Food Consumption Score (FCS) using standardized +# food group variables. It assumes that the required variables are available in +# your dataset and correctly formatted for use in the calculation. +# +# 2. Assumptions: +# - The dataset contains standardized variables from Survey Designer. +# - The variables used for the FCS calculation are properly named and cleaned. +# - The dataset is loaded into a data frame before executing the script. +# +# 3. Requirements: +# - Required variables in the dataset: +# - FCSStap : Consumption of starchy staples +# - FCSPulse : Consumption of pulses/legumes +# - FCSDairy : Consumption of dairy products +# - FCSPr : Consumption of meat/fish/protein +# - FCSVeg : Consumption of vegetables +# - FCSFruit : Consumption of fruits +# - FCSFat : Consumption of fats/oils +# - FCSSugar : Consumption of sugar +# +# - Required Packages: +# - dplyr (Install with `install.packages("dplyr")`) +# +# 4. R Version: +# - R version 3.x or higher is recommended for compatibility with modern libraries. #------------------------------------------------------------------------------# -## Load Packages --------------------------------------------------------------# - -ipak <- function(pkg){ - new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])] - if (length(new.pkg)) - install.packages(new.pkg, dependencies = TRUE) - sapply(pkg, require, character.only = TRUE) +# Load necessary libraries +library(dplyr) + +# Function to calculate FCS +calculate_fcs <- function(df) { + # Calculate the Food Consumption Score (FCS) + + # Parameters: + # - df: DataFrame, the dataset containing the eight FCS variables + + # Returns: + # - df: DataFrame, the dataset with the calculated 'FCS' variable + + df <- df %>% + mutate(FCS = (FCSStap * 2 + + FCSPulse * 3 + + FCSDairy * 4 + + FCSPr * 4 + + FCSVeg + + FCSFruit + + FCSFat * 0.5 + + FCSSugar * 0.5)) + + return(df) } -packages<-c('psych','diveRsity','expss') -ipak(packages) - -library('psych') -library("diveRsity") - -# Set working directory -------------------------------------------------------# - -## Get working directory -getwd()# Display current working directory -dir()# Display working directory content - -setwd("C:\\Users\\name.lastname\\Documents\\Rfolder") -# This is just an example. Copy and paste your own working directory. Remember to use "\\" instead of "/" -# The data base to be used should be part of the content - -# Load Sample Data ------------------------------------------------------------# - -data <- read.csv("../../Static/FCS_Sample_Survey.csv",na.strings = "n/a") - -names(data)# Display var names for the entire data base -attach(data)# Attach the data base for easy access to var names. - -# Prepare FCS related variables -----------------------------------------------# - -# 1. Re-coding missing values to zero -data$FCSStap[is.na(data$FCSStap)] <-0 -data$FCSVeg[is.na(data$FCSVeg)] <-0 -data$FCSFruit[is.na(data$FCSFruit)] <-0 -data$FCSPr[is.na(data$FCSPr)] <-0 -data$FCSPulse[is.na(data$FCSPulse)] <-0 -data$FCSDairy[is.na(data$FCSDairy)] <-0 -data$FCSSugar[is.na(data$FCSSugar)] <-0 -data$FCSFat[is.na(data$FCSFat)] <-0 -data$FCSCond[is.na(data$FCSCond)] <-0 - -# Test results -print(data$FCSStap) # How data looks like? - -## 2. Variables creation and statistics testing -# Var FCSStapCer FCSStapTub -# although deprecated, in case two staples are collected separately, then: -if ("FCSStap" %in% colnames(data)) {"x"} else - { - data$FCSStap <- mapply(max, data$FCSStapCer, data$FCSStapTub, na.rm=T) - } -count(data$FCSStap) -basicStats(data$FCSStap, ci=0.95) -plot(density(data$FCSStap)) - -# Legumes/nuts (FCSPulse) -data$FCSPulse -count(data$FCSPulse) -basicStats(data$FCSPulse, ci=0.95) -plot(density(data$FCSPulse)) - -# Milk and other dairy products (FCSDairy) -data$FCSDairy -count(data$FCSDairy) -basicStats(data$FCSDairy, ci=0.95) -plot(density(data$FCSDairy)) - -# Meat, fish and eggs (FCSPr) -data$FCSPr -count(data$FCSPr) -basicStats(data$FCSPr, ci=0.95) -plot(density(data$FCSPr)) - -# Vegetables and leaves (FCSVeg) -data$FCSVeg -count(data$FCSVeg) -basicStats(data$FCSVeg, ci=0.95) -plot(density(data$FCSVeg)) - -# Fruits (FCSFruit) -data$FCSFruit -count(data$FCSFruit) -basicStats(data$FCSFruit, ci=0.95) -plot(density(data$FCSFruit)) - -# Oil, fat and butter (FCSFat) -data$FCSFat -count(data$FCSFat) -basicStats(data$FCSFat, ci=0.95) -plot(density(data$FCSFat)) - -# Sugar and sweet (FCSSugar) -data$FCSSugar -count(data$FCSSugar) -basicStats(data$FCSSugar, ci=0.95) -plot(density(data$FCSSugar)) - -# Condiments / Spices -data$FCSCond -count(data$FCSCond) -basicStats(data$FCSCond, ci=0.95) -plot(density(data$FCSCond)) - -# 2.1 Recode above 7 to 7 (only if necessary) -data$Ncertub[data$FCSStap>7] <- 7 -data$FCSPulse[data$FCSPulse>7] <- 7 -data$FCSDairy[data$FCSDairy>7] <- 7 -data$FCSPr[data$FCSPr>7] <- 7 -data$FCSVeg[data$FCSVeg>7] <- 7 -data$FCSFruit[data$FCSFruit>7] <- 7 -data$FCSFat[data$FCSFat>7] <- 7 -data$FCSSugar[data$FCSSugar>7] <- 7 -data$FCSCond[data$FCSCond>7] <- 7 - -# Calculate FCS ---------------------------------------------------------------# -data$FCS <- mapply(sum,(data$FCSStap*2),(data$FCSPulse*3),(data$FCSDairy*4), - (data$FCSPr*4),(data$FCSVeg),(data$FCSFruit),(data$FCSFat*0.5), - (data$FCSSugar*0.5)) -###### Test ##### -head(data$FCS, n=10) -psych::describe(data$FCS) -summary(data$FCS) -stat.desc(data$FCS, basic = F) -plot(density(data$FCS)) - -# Create FCG groups based on 21/55 or 28/42 thresholds ------------------------# -###Use this when analyzing a country with low consumption of sugar and oil - thresholds 21-35 -data$FCSCat21 <-cut(data$FCS, - breaks=c(0,21,35,Inf), - include.lowest=TRUE, - #labels=c("Poor","Borderline","Acceptable")) - labels=FALSE) - -### define value labels and properties for "FCS Categories". -val_lab(data$FCSCat21) = num_lab(" - 1 Poor - 2 Borderline - 3 Acceptable -") - -### Important note: pay attention to the threshold used by your CO when selecting the syntax (21 cat. vs 28 cat.) -### Use this when analyzing a country with high consumption of sugar and oil - thresholds 28-42 -data$FCSCat28 <-cut(data$FCS, - breaks=c(0,28,42,Inf), - include.lowest=TRUE, - #labels=c("Poor","Borderline","Acceptable")) - labels=FALSE) -### define value labels and properties for "FCS Categories". -val_lab(data$FCSCat28) = num_lab(" - 1 Poor - 2 Borderline - 3 Acceptable -") - -# End of Scripts \ No newline at end of file +# Function to categorize FCS into groups based on thresholds +categorize_fcs <- function(df, fcs_column = 'FCS') { + # Categorize FCS into groups based on thresholds + + # Parameters: + # - df: DataFrame, the dataset containing the FCS + # - fcs_column: str, the name of the column containing the calculated food consumption score (default is 'FCS') + + # Returns: + # - df: DataFrame, the dataset with the calculated 'FCSCat21' and 'FCSCat28' variables + + # Low consumption of sugar and oil + df$FCSCat21 <- cut( + df[[fcs_column]], + breaks = c(-Inf, 21, 35, Inf), + labels = c("Poor", "Borderline", "Acceptable"), + right = TRUE + ) + + # High consumption of sugar and oil + df$FCSCat28 <- cut( + df[[fcs_column]], + breaks = c(-Inf, 28, 42, Inf), + labels = c("Poor", "Borderline", "Acceptable"), + right = TRUE + ) + + return(df) +} diff --git a/Indicators/Food-consumption-score/FCS-indicator-calculation.do b/Indicators/Food-consumption-score/FCS-indicator-calculation.do index 6fc0758..c7f589e 100644 --- a/Indicators/Food-consumption-score/FCS-indicator-calculation.do +++ b/Indicators/Food-consumption-score/FCS-indicator-calculation.do @@ -1,50 +1,65 @@ *------------------------------------------------------------------------------* +* WFP RAM Standardized Scripts +* Food Consumption Score (FCS) Calculation in STATA +*------------------------------------------------------------------------------* +* 1. Purpose: +* This script calculates the Food Consumption Score (FCS) using standardized +* food group variables. It assumes that the required variables are available in +* your dataset and correctly formatted for use in the calculation. +* +* 2. Assumptions: +* - The dataset contains standardized variables from Survey Designer. +* - The variables used for the FCS calculation are properly named and cleaned. +* - The dataset is already loaded in STATA. +* +* 3. Requirements: +* - Required variables in the dataset: +* - FCSStap : Consumption of starchy staples +* - FCSPulse : Consumption of pulses/legumes +* - FCSDairy : Consumption of dairy products +* - FCSPr : Consumption of meat/fish/protein +* - FCSVeg : Consumption of vegetables +* - FCSFruit : Consumption of fruits +* - FCSFat : Consumption of fats/oils +* - FCSSugar : Consumption of sugar +* +* 4. STATA Version: +* - STATA 14 or higher is recommended. +*------------------------------------------------------------------------------* -* WFP RAM Standardized Scripts -* Calculating Food Consumption Score (FCS) - -*----------------------------------------------------------------------------- - -** Load data -* --------- - import delim using "../../Static/FCS_Sample_Survey.csv", clear /// - case(preserve) bindquotes(strict) varn(1) - -** Label FCS relevant variables - label var FCSStap "Consumption over the past 7 days: cereals, grains and tubers" - label var FCSPulse "Consumption over the past 7 days: pulses" - label var FCSDairy "Consumption over the past 7 days: dairy products" - label var FCSPr "Consumption over the past 7 days: meat, fish and eggs" - label var FCSVeg "Consumption over the past 7 days: vegetables" - label var FCSFruit "Consumption over the past 7 days: fruit" - label var FCSFat "Consumption over the past 7 days: fat and oil" - label var FCSSugar "Consumption over the past 7 days: sugaror sweets" - label var FCSCond "Consumption over the past 7 days: condiments or spices" - -** Clean and recode missing values - recode FCSStap FCSVeg FCSFruit FCSPr FCSPulse FCSDairy FCSFat FCSSugar (. = 0) +*------------------------------------------------------------------------------ +* Step 1: Calculate the Food Consumption Score (FCS) +*------------------------------------------------------------------------------ -** Create FCS - gen FCS = (FCSStap * 2) + (FCSPulse * 3) + (FCSDairy * 4) + (FCSPr * 4) + /// - (FCSVeg * 1) + (FCSFruit * 1) + (FCSFat * 0.5) + (FCSSugar * 0.5) +* The formula for FCS is: +* FCS = (FCSStap * 2) + (FCSPulse * 3) + (FCSDairy * 4) + (FCSPr * 4) +* + FCSVeg + FCSFruit + (FCSFat * 0.5) + (FCSSugar * 0.5) - label var FCS "Food Consumption Score" +gen FCS = (FCSStap * 2) + + (FCSPulse * 3) + + (FCSDairy * 4) + + (FCSPr * 4) + + FCSVeg + + FCSFruit + + (FCSFat * 0.5) + + (FCSSugar * 0.5) -** Create FCG groups based on 21/35 or 28/42 thresholds -*** Use this when analyzing a country with low consumption of sugar and oil +*------------------------------------------------------------------------------ +* Step 2: Categorize FCS into Groups Based on Thresholds +*------------------------------------------------------------------------------ -*** thresholds 21-35 - gen FCSCat21 = cond(FCS <= 21, 1, cond(FCS <= 35, 2, 3)) - label var FCSCat21 "FCS Categories, thresholds 21-35" +* Create categorical variables based on thresholds for low and high consumption +* of sugar and oil. -*** thresholds 28-42 - gen FCSCat28 = cond(FCS <= 28, 1, cond(FCS <= 42, 2, 3)) - label var FCSCat28 "FCS Categories, thresholds 28-42" +* Low consumption of sugar and oil: +gen FCSCat21 = "" +replace FCSCat21 = "Poor" if FCS < 21 +replace FCSCat21 = "Borderline" if FCS >= 21 & FCS <= 35 +replace FCSCat21 = "Acceptable" if FCS > 35 +* High consumption of sugar and oil: +gen FCSCat28 = "" +replace FCSCat28 = "Poor" if FCS < 28 +replace FCSCat28 = "Borderline" if FCS >= 28 & FCS <= 42 +replace FCSCat28 = "Acceptable" if FCS > 42 -*** define variables labels and properties for "FCS Categories" - label def FCSCat 1 "Poor" 2 "Borderline" 3 "Acceptable" - label val FCSCat21 FCSCat28 FCSCat - -* --------- -** End of Scripts diff --git a/Indicators/Food-consumption-score/FCS-indicator-calculation.py b/Indicators/Food-consumption-score/FCS-indicator-calculation.py new file mode 100644 index 0000000..e29582e --- /dev/null +++ b/Indicators/Food-consumption-score/FCS-indicator-calculation.py @@ -0,0 +1,85 @@ +#------------------------------------------------------------------------------# +# WFP RAM Standardized Scripts +# Food Consumption Score (FCS) Calculation in Python +#------------------------------------------------------------------------------# +# 1. Purpose: +# This script calculates the Food Consumption Score (FCS) using standardized +# food group variables. It assumes that the required variables are available in +# your dataset and correctly formatted for use in the calculation. +# +# 2. Assumptions: +# - The dataset contains standardized variables from Survey Designer. +# - The variables used for the FCS calculation are properly named and cleaned. +# - The dataset is loaded into a pandas DataFrame before executing the script. +# +# 3. Requirements: +# - Required variables in the dataset: +# - FCSStap : Consumption of starchy staples +# - FCSPulse : Consumption of pulses/legumes +# - FCSDairy : Consumption of dairy products +# - FCSPr : Consumption of meat/fish/protein +# - FCSVeg : Consumption of vegetables +# - FCSFruit : Consumption of fruits +# - FCSFat : Consumption of fats/oils +# - FCSSugar : Consumption of sugar +# +# - Required Packages: +# - pandas (Install with `pip install pandas`) +# +# 4. Python Version: +# - Python 3.x is recommended for compatibility with the pandas package. +#------------------------------------------------------------------------------# + +# Load necessary libraries +import pandas as pd + +# Function to calculate FCS +def calculate_fcs(df): + """ + Calculate the Food Consumption Score (FCS). + + Parameters: + - df: pandas.DataFrame, the dataset containing the eight FCS variables + + Returns: + - df: pandas.DataFrame, the dataset with the calculated 'FCS' variable + """ + df['FCS'] = (df['FCSStap'] * 2 + + df['FCSPulse'] * 3 + + df['FCSDairy'] * 4 + + df['FCSPr'] * 4 + + df['FCSVeg'] + + df['FCSFruit'] + + df['FCSFat'] * 0.5 + + df['FCSSugar'] * 0.5) + return df + +# Function to categorize FCS into groups based on thresholds +def categorize_fcs(df, fcs_column='FCS'): + """ + Categorize FCS into groups based on thresholds. + + Parameters: + - df: pandas.DataFrame, the dataset containing the FCS + - fcs_column: str, the name of the column containing the calculated food consumption score (default is 'FCS') + + Returns: + - df: pandas.DataFrame, the dataset with the calculated 'FCSCat21' and 'FCSCat28' variables + """ + # Low consumption of sugar and oil + df['FCSCat21'] = pd.cut( + df[fcs_column], + bins=[-float('inf'), 21, 35, float('inf')], + labels=["Poor", "Borderline", "Acceptable"], + right=True + ) + + # High consumption of sugar and oil + df['FCSCat28'] = pd.cut( + df[fcs_column], + bins=[-float('inf'), 28, 42, float('inf')], + labels=["Poor", "Borderline", "Acceptable"], + right=True + ) + + return df diff --git a/Indicators/Food-consumption-score/FCS-indicator-calculation.sps b/Indicators/Food-consumption-score/FCS-indicator-calculation.sps index 17ce50a..d16f731 100644 --- a/Indicators/Food-consumption-score/FCS-indicator-calculation.sps +++ b/Indicators/Food-consumption-score/FCS-indicator-calculation.sps @@ -1,51 +1,73 @@ -*** -------------------------------------------------------------------------- +*------------------------------------------------------------------------------* +* WFP RAM Standardized Scripts +* Food Consumption Score (FCS) Calculation in SPSS +*------------------------------------------------------------------------------* +* 1. Purpose: +* This script calculates the Food Consumption Score (FCS) using standardized +* food group variables. It assumes that the required variables are available in +* your dataset and correctly formatted for use in the calculation. +* +* 2. Assumptions: +* - The dataset contains standardized variables from Survey Designer. +* - The variables used for the FCS calculation are properly named and cleaned. +* - The dataset is already loaded in SPSS. +* +* 3. Requirements: +* - Required variables in the dataset: +* - FCSStap : Consumption of starchy staples +* - FCSPulse : Consumption of pulses/legumes +* - FCSDairy : Consumption of dairy products +* - FCSPr : Consumption of meat/fish/protein +* - FCSVeg : Consumption of vegetables +* - FCSFruit : Consumption of fruits +* - FCSFat : Consumption of fats/oils +* - FCSSugar : Consumption of sugar +* +* 4. SPSS Version: +* - SPSS 21 or higher is recommended. +*------------------------------------------------------------------------------* -*** WFP RAM Standardized Scripts -*** Calculating Food Consumption Score (FCS) +*------------------------------------------------------------------------------ +* Step 1: Calculate the Food Consumption Score (FCS) +*------------------------------------------------------------------------------ -*** -------------------------------------------------------------------------- +* The formula for FCS is: +* FCS = (FCSStap * 2) + (FCSPulse * 3) + (FCSDairy * 4) + (FCSPr * 4) +* + FCSVeg + FCSFruit + (FCSFat * 0.5) + (FCSSugar * 0.5) -* Encoding: UTF-8. - -*** Define labels - -Variable labels -FCSStap 'Consumption over the past 7 days: cereals, grains and tubers' -FCSPulse 'Consumption over the past 7 days: pulses' -FCSDairy 'Consumption over the past 7 days: dairy products' -FCSPr 'Consumption over the past 7 days: meat, fish and eggs' -FCSVeg 'Consumption over the past 7 days: vegetables and leaves' -FCSFruit 'Consumption over the past 7 days: fruit' -FCSFat 'Consumption over the past 7 days: fat and oil' -FCSSugar 'Consumption over the past 7 days: sugar or sweets' -FCSCond 'Consumption over the past 7 days: condiments or spices'. - -*** Calculate FCS -Compute FCS = sum(FCSStap*2, FCSPulse*3, FCSDairy*4, FCSPr*4, FCSVeg*1, FCSFruit*1, FCSFat*0.5, FCSSugar*0.5). -Variable labels FCS "Food Consumption Score". -EXECUTE. - -*** Use this when analyzing a country with low consumption of sugar and oil - thresholds 21-35 - -Recode FCS (lowest thru 21 = 1) (21.5 thru 35 = 2) (35.5 thru highest = 3) into FCSCat21. -Variable labels FCSCat21 "FCS Categories: 21/35 thresholds". +COMPUTE FCS = (FCSStap * 2) + + (FCSPulse * 3) + + (FCSDairy * 4) + + (FCSPr * 4) + + FCSVeg + + FCSFruit + + (FCSFat * 0.5) + + (FCSSugar * 0.5). EXECUTE. -*** Define value labels and properties for "FCS Categories". - -Value labels FCSCat21 1.00 "Poor" 2.00 "Borderline" 3.00 "Acceptable". -EXECUTE. +*------------------------------------------------------------------------------ +* Step 2: Categorize FCS into Groups Based on Thresholds +*------------------------------------------------------------------------------ -*** Important note: pay attention to the threshold used by your CO when selecting the syntax (21 cat. vs 28 cat.) -*** Use this when analyzing a country with high consumption of sugar and oil – thresholds 28-42 +* Create categorical variables based on thresholds for low and high consumption +* of sugar and oil. -Recode FCS (lowest thru 28 = 1) (28.5 thru 42 = 2) (42.5 thru highest = 3) into FCSCat28. -Variable labels FCSCat28 "FCS Categories: 28/42 thresholds". +* Low consumption of sugar and oil: +DO IF (FCS < 21). + COMPUTE FCSCat21 = 'Poor'. +ELSE IF (FCS >= 21 AND FCS <= 35). + COMPUTE FCSCat21 = 'Borderline'. +ELSE IF (FCS > 35). + COMPUTE FCSCat21 = 'Acceptable'. +END IF. EXECUTE. -*** Define value labels and properties for "FCS Categories" - -Value labels FCSCat28 1.00 "Poor" 2.00 "Borderline" 3.00 "Acceptable". +* High consumption of sugar and oil: +DO IF (FCS < 28). + COMPUTE FCSCat28 = 'Poor'. +ELSE IF (FCS >= 28 AND FCS <= 42). + COMPUTE FCSCat28 = 'Borderline'. +ELSE IF (FCS > 42). + COMPUTE FCSCat28 = 'Acceptable'. +END IF. EXECUTE. - -*** End of scripts \ No newline at end of file From 8bf0794cbf2ee527374c2761d70b056f04408bd1 Mon Sep 17 00:00:00 2001 From: AssiALi16 <154439283+AssiALi16@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:48:06 +0300 Subject: [PATCH 2/4] Updated rCSI Indicator Calculation Scripts in Python, R, Stata, and SPSS --- .../FCS-indicator-calculation.R | 6 -- .../rCSI-indicator-calculation.R | 64 +++++++++++++++++ .../rCSI-indicator-calculation.do | 49 +++++++++++++ .../rCSI-indicator-calculation.py | 69 +++++++++++++++++++ .../rCSI-indicator-calculation.sps | 53 ++++++++++++++ .../rCSI-indicator.do | 25 ------- .../rCSI-indicator.sps | 16 ----- 7 files changed, 235 insertions(+), 47 deletions(-) create mode 100644 Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.R create mode 100644 Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.do create mode 100644 Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.py create mode 100644 Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.sps delete mode 100644 Indicators/Reduced-coping-strategy-index/rCSI-indicator.do delete mode 100644 Indicators/Reduced-coping-strategy-index/rCSI-indicator.sps diff --git a/Indicators/Food-consumption-score/FCS-indicator-calculation.R b/Indicators/Food-consumption-score/FCS-indicator-calculation.R index c896c3a..2bce2fd 100644 --- a/Indicators/Food-consumption-score/FCS-indicator-calculation.R +++ b/Indicators/Food-consumption-score/FCS-indicator-calculation.R @@ -23,16 +23,10 @@ # - FCSFat : Consumption of fats/oils # - FCSSugar : Consumption of sugar # -# - Required Packages: -# - dplyr (Install with `install.packages("dplyr")`) -# # 4. R Version: # - R version 3.x or higher is recommended for compatibility with modern libraries. #------------------------------------------------------------------------------# -# Load necessary libraries -library(dplyr) - # Function to calculate FCS calculate_fcs <- function(df) { # Calculate the Food Consumption Score (FCS) diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.R b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.R new file mode 100644 index 0000000..6f3a73a --- /dev/null +++ b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.R @@ -0,0 +1,64 @@ +#------------------------------------------------------------------------------# +# WFP RAM Standardized Scripts +# Reduced Coping Strategies Index (rCSI) Calculation in R +#------------------------------------------------------------------------------# +# 1. Purpose: +# This script calculates the Reduced Coping Strategies Index (rCSI) using standardized +# variables. It assumes that the required variables are available in your dataset and +# correctly formatted for use in the calculation. +# +# 2. Assumptions: +# - The dataset contains standardized variables from Survey Designer. +# - The variables used for the rCSI calculation are properly named and cleaned. +# - The dataset is already loaded in a data frame in R. +# +# 3. Requirements: +# - Required variables in the dataset: +# - rCSILessQlty : Reduced quality of meals +# - rCSIBorrow : Borrow food +# - rCSIMealNb : Reduce number of meals +# - rCSIMealSize : Reduce meal size +# - rCSIMealAdult: Restrict consumption of adults +# +# 4. R Version: +# - R 3.x or higher is recommended. +#------------------------------------------------------------------------------# + +# Function to calculate rCSI +calculate_rcsi <- function(df) { + # Calculate the Reduced Coping Strategies Index (rCSI). + + # Parameters: + # - df: pandas.DataFrame, the dataset containing the five rCSI variables + + # Returns: + # - df: pandas.DataFrame, the dataset with the calculated 'rCSI' variable + + df$rCSI <- df$rCSILessQlty + + (df$rCSIBorrow * 2) + + df$rCSIMealNb + + df$rCSIMealSize + + (df$rCSIMealAdult * 3) + + return(df) +} + +# Function to categorize rCSI into groups based on thresholds +categorize_rcsi <- function(df, rcsi_column = 'rCSI') { + # Categorize rCSI into groups based on thresholds. + + # Parameters: + # - df: pandas.DataFrame, the dataset containing the rCSI + # - rcsi_column: str, the name of the column containing the calculated rCSI (default is 'rCSI') + + # Returns: + # - df: pandas.DataFrame, the dataset with the calculated 'rCSICat' variable + + df <- df %>% + mutate(rCSICat = cut(.data[[rcsi_column]], + breaks = c(-Inf, 3.5, 18, Inf), + labels = c("Minimal", "Moderate", "Severe"), + right = TRUE)) + + return(df) +} diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.do b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.do new file mode 100644 index 0000000..70d13a1 --- /dev/null +++ b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.do @@ -0,0 +1,49 @@ +*------------------------------------------------------------------------------* +* WFP RAM Standardized Scripts +* Reduced Coping Strategies Index (rCSI) Calculation in STATA +*------------------------------------------------------------------------------* +* 1. Purpose: +* This script calculates the Reduced Coping Strategies Index (rCSI) using standardized +* variables. It assumes that the required variables are available in your dataset and +* correctly formatted for use in the calculation. +* +* 2. Assumptions: +* - The dataset contains standardized variables from Survey Designer. +* - The variables used for the rCSI calculation are properly named and cleaned. +* - The dataset is already loaded in STATA. +* +* 3. Requirements: +* - Required variables in the dataset: +* - rCSILessQlty : Reduced quality of meals +* - rCSIBorrow : Borrow food +* - rCSIMealNb : Reduce number of meals +* - rCSIMealSize : Reduce meal size +* - rCSIMealAdult: Restrict consumption of adults +* +* 4. STATA Version: +* - STATA 14 or higher is recommended. +*------------------------------------------------------------------------------* + +*------------------------------------------------------------------------------ +* Step 1: Calculate the Reduced Coping Strategies Index (rCSI) +*------------------------------------------------------------------------------ + +* The formula for rCSI is: +* rCSI = rCSILessQlty + (rCSIBorrow * 2) + rCSIMealNb + rCSIMealSize + (rCSIMealAdult * 3) + +gen rCSI = rCSILessQlty + + (rCSIBorrow * 2) + + rCSIMealNb + + rCSIMealSize + + (rCSIMealAdult * 3) + +*------------------------------------------------------------------------------ +* Step 2: Categorize rCSI into Groups Based on Thresholds +*------------------------------------------------------------------------------ + +* Categorize rCSI into "Minimal", "Moderate", and "Severe" based on thresholds. +gen rCSICat = "" + +replace rCSICat = "Minimal" if rCSI <= 3.5 +replace rCSICat = "Moderate" if rCSI > 3.5 & rCSI <= 18 +replace rCSICat = "Severe" if rCSI > 18 diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.py b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.py new file mode 100644 index 0000000..c0cce28 --- /dev/null +++ b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.py @@ -0,0 +1,69 @@ +#------------------------------------------------------------------------------# +# WFP RAM Standardized Scripts +# Reduced Coping Strategies Index (rCSI) Calculation in Python +#------------------------------------------------------------------------------# +# 1. Purpose: +# This script calculates the Reduced Coping Strategies Index (rCSI) using standardized +# variables. It assumes that the required variables are available in your dataset and +# correctly formatted for use in the calculation. +# +# 2. Assumptions: +# - The dataset contains standardized variables from Survey Designer. +# - The variables used for the rCSI calculation are properly named and cleaned. +# - The dataset is loaded into a pandas DataFrame before executing the script. +# +# 3. Requirements: +# - Required variables in the dataset: +# - rCSILessQlty : Reduced quality of meals +# - rCSIBorrow : Borrow food +# - rCSIMealNb : Reduce number of meals +# - rCSIMealSize : Reduce meal size +# - rCSIMealAdult: Restrict consumption of adults +# +# - Required Packages: +# - pandas (Install with `pip install pandas`) +# +# 4. Python Version: +# - Python 3.x is recommended for compatibility with the pandas package. +#------------------------------------------------------------------------------# + +# Load necessary libraries +import pandas as pd + +# Function to calculate rCSI +def calculate_rcsi(df): + """ + Calculate the Reduced Coping Strategies Index (rCSI). + + Parameters: + - df: pandas.DataFrame, the dataset containing the five rCSI variables + + Returns: + - df: pandas.DataFrame, the dataset with the calculated 'rCSI' variable + """ + df['rCSI'] = (df['rCSILessQlty'] + + (df['rCSIBorrow'] * 2) + + df['rCSIMealNb'] + + df['rCSIMealSize'] + + (df['rCSIMealAdult'] * 3)) + return df + +# Function to categorize rCSI into groups based on thresholds +def categorize_rcsi(df, rcsi_column='rCSI'): + """ + Categorize rCSI into groups based on thresholds. + + Parameters: + - df: pandas.DataFrame, the dataset containing the rCSI + - rcsi_column: str, the name of the column containing the calculated rCSI (default is 'rCSI') + + Returns: + - df: pandas.DataFrame, the dataset with the calculated 'rCSICat' variable + """ + df['rCSICat'] = pd.cut( + df[rcsi_column], + bins=[-float('inf'), 3.5, 18, float('inf')], + labels=["Minimal", "Moderate", "Severe"], + right=True + ) + return df diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.sps b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.sps new file mode 100644 index 0000000..00337ba --- /dev/null +++ b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.sps @@ -0,0 +1,53 @@ +*------------------------------------------------------------------------------* +* WFP RAM Standardized Scripts +* Reduced Coping Strategies Index (rCSI) Calculation in SPSS +*------------------------------------------------------------------------------* +* 1. Purpose: +* This script calculates the Reduced Coping Strategies Index (rCSI) using standardized +* variables. It assumes that the required variables are available in your dataset and +* correctly formatted for use in the calculation. +* +* 2. Assumptions: +* - The dataset contains standardized variables from Survey Designer. +* - The variables used for the rCSI calculation are properly named and cleaned. +* - The dataset is already loaded in SPSS. +* +* 3. Requirements: +* - Required variables in the dataset: +* - rCSILessQlty : Reduced quality of meals +* - rCSIBorrow : Borrow food +* - rCSIMealNb : Reduce number of meals +* - rCSIMealSize : Reduce meal size +* - rCSIMealAdult: Restrict consumption of adults +* +* 4. SPSS Version: +* - SPSS 21 or higher is recommended. +*------------------------------------------------------------------------------* + +*------------------------------------------------------------------------------ +* Step 1: Calculate the Reduced Coping Strategies Index (rCSI) +*------------------------------------------------------------------------------ + +* The formula for rCSI is: +* rCSI = rCSILessQlty + (rCSIBorrow * 2) + rCSIMealNb + rCSIMealSize + (rCSIMealAdult * 3) + +COMPUTE rCSI = rCSILessQlty + + (rCSIBorrow * 2) + + rCSIMealNb + + rCSIMealSize + + (rCSIMealAdult * 3). +EXECUTE. + +*------------------------------------------------------------------------------ +* Step 2: Categorize rCSI into Groups Based on Thresholds +*------------------------------------------------------------------------------ + +* Categorize rCSI into "Minimal", "Moderate", and "Severe" based on thresholds. +DO IF (rCSI <= 3.5). + COMPUTE rCSICat = "Minimal". +ELSE IF (rCSI > 3.5 AND rCSI <= 18). + COMPUTE rCSICat = "Moderate". +ELSE IF (rCSI > 18). + COMPUTE rCSICat = "Severe". +END IF. +EXECUTE. diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator.do b/Indicators/Reduced-coping-strategy-index/rCSI-indicator.do deleted file mode 100644 index 9e80a3c..0000000 --- a/Indicators/Reduced-coping-strategy-index/rCSI-indicator.do +++ /dev/null @@ -1,25 +0,0 @@ -******************************************************************************** -* reduced Coping Strategy Index (rCSI) -*******************************************************************************/ - -** Load data -* --------- -import delim using "../GitHub/RAMResourcesScripts/Static/rCSI_Sample_Survey.csv", /// - clear case(preserve) - -** Check and recode missing values as 0 - sum rCSI* - -** Label rCSI relevant variables - lab var rCSILessQlty "Relied on less preferred, less expensive food" - lab var rCSIBorrow "Borrowed food or relied on help from friends or relatives" - lab var rCSIMealNb "Reduced the number of meals eaten per day" - lab var rCSIMealSize "Reduced portion size of meals at meals time" - lab var rCSIMealAdult "Restricted consumption by adults in order for young children to eat" - -** Calculate rCSI - gen rCSI = (rCSILessQlty * 1) + (rCSIBorrow * 2) + (rCSIMealNb * 1) + /// - (rCSIMealSize * 1) + (rCSIMealAdult * 3) - lab var rCSI "Reduced Consumption Strategies Index" - -** End of Scripts diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator.sps b/Indicators/Reduced-coping-strategy-index/rCSI-indicator.sps deleted file mode 100644 index fc85b7d..0000000 --- a/Indicators/Reduced-coping-strategy-index/rCSI-indicator.sps +++ /dev/null @@ -1,16 +0,0 @@ -* Encoding: UTF-8. -***Reduced Coping Strategy Index*** -***define variables - -Variable labels -rCSILessQlty ‘Rely on less preferred and less expensive food in the past 7 days’ -rCSIBorrow ‘Borrow food or rely on help from a relative or friend in the past 7 days’ -rCSIMealNb ‘Reduce number of meals eaten in a day in the past 7 days’ -rCSIMealSize ‘Limit portion size of meals at meal times in the past 7 days’ -rCSIMealAdult ‘Restrict consumption by adults in order for small children to eat in the past 7 days’. - -Compute rCSI = sum(rCSILessQlty*1,rCSIBorrow*2,rCSIMealNb*1,rCSIMealSize*1,rCSIMealAdult*3). -Variable labels rCSI 'Reduced coping strategies index (rCSI)'. -EXECUTE. - - From d40fd8b1661a27a58391677bf325323ffb509571 Mon Sep 17 00:00:00 2001 From: AssiALi16 <154439283+AssiALi16@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:52:15 +0300 Subject: [PATCH 3/4] Updated HDDS Indicator Calculation in Python, R, Stata, and SPSS --- .../HDDS-indicator-calculation.R | 79 ++++++++++++++++ .../HDDS-indicator-calculation.do | 60 +++++++++++++ .../HDDS-indicator-calculation.py | 89 +++++++++++++++++++ .../HDDS-indicator-calculation.sps | 73 +++++++++++++++ .../Household-Dietary-Diversity-Score.sps | 36 -------- 5 files changed, 301 insertions(+), 36 deletions(-) create mode 100644 Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.R create mode 100644 Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.do create mode 100644 Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.py create mode 100644 Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.sps delete mode 100644 Indicators/Household-Dietary-Diversity-Score/Household-Dietary-Diversity-Score.sps diff --git a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.R b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.R new file mode 100644 index 0000000..87bbc34 --- /dev/null +++ b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.R @@ -0,0 +1,79 @@ +#------------------------------------------------------------------------------# +# WFP RAM Standardized Scripts +# Calculating Household Dietary Diversity Score (HDDS) in R +#------------------------------------------------------------------------------# +# 1. Purpose: +# This script calculates the Household Dietary Diversity Score (HDDS) using standardized +# food group variables based on a 24-hour recall. It assumes that the required variables +# are available in your dataset and correctly formatted for use in the calculation. +# +# 2. Assumptions: +# - The dataset contains standardized variables from Survey Designer. +# - The variables used for the HDDS calculation are properly named and cleaned. +# - The dataset is loaded into a data frame before executing the script. +# +# 3. Requirements: +# - Required variables in the dataset: +# - HDDSStapCer : Consumption of cereals +# - HDDSStapRoot : Consumption of roots/tubers +# - HDDSVeg : Consumption of vegetables +# - HDDSFruit : Consumption of fruits +# - HDDSPrMeat : Consumption of meat/poultry +# - HDDSPrEggs : Consumption of eggs +# - HDDSPrFish : Consumption of fish +# - HDDSPulse : Consumption of pulses/legumes +# - HDDSDairy : Consumption of milk and dairy products +# - HDDSFat : Consumption of oils/fats +# - HDDSSugar : Consumption of sugar/honey +# - HDDSCond : Consumption of miscellaneous/condiments +# +# 4. R Version: +# - R version 3.x or higher is recommended. +#------------------------------------------------------------------------------# + +# Function to calculate HDDS +calculate_hdds <- function(df) { + # Calculate the Household Dietary Diversity Score (HDDS) + + # Parameters: + # - df: DataFrame, the dataset containing the twelve HDDS variables + + # Returns: + # - df: DataFrame, the dataset with the calculated 'HDDS' variable + + df$HDDS <- df$HDDSStapCer + + df$HDDSStapRoot + + df$HDDSVeg + + df$HDDSFruit + + df$HDDSPrMeat + + df$HDDSPrEggs + + df$HDDSPrFish + + df$HDDSPulse + + df$HDDSDairy + + df$HDDSFat + + df$HDDSSugar + + df$HDDSCond + + return(df) +} + +# Function to categorize HDDS into groups based on IPC thresholds +categorize_hdds <- function(df, hdds_column = 'HDDS') { + # Categorize HDDS into groups based on IPC thresholds + + # Parameters: + # - df: DataFrame, the dataset containing the HDDS + # - hdds_column: str, the name of the column containing the calculated HDDS (default is 'HDDS') + + # Returns: + # - df: DataFrame, the dataset with the calculated 'HDDSCat_IPC' variable + + df$HDDSCat_IPC <- cut(df[[hdds_column]], + breaks = c(-Inf, 2, 4, Inf), + labels = c("0-2 food groups (phase 4 to 5)", + "3-4 food groups (phase 3)", + "5-12 food groups (phase 1 to 2)"), + right = TRUE) + + return(df) +} diff --git a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.do b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.do new file mode 100644 index 0000000..7039f50 --- /dev/null +++ b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.do @@ -0,0 +1,60 @@ +*------------------------------------------------------------------------------* +* WFP RAM Standardized Scripts +* Calculating Household Dietary Diversity Score (HDDS) in STATA +*------------------------------------------------------------------------------* +* 1. Purpose: +* This script calculates the Household Dietary Diversity Score (HDDS) using standardized +* food group variables based on a 24-hour recall. It assumes that the required variables +* are available in your dataset and correctly formatted for use in the calculation. +* +* 2. Assumptions: +* - The dataset contains standardized variables from Survey Designer. +* - The variables used for the HDDS calculation are properly named and cleaned. +* - The dataset is already loaded in STATA. +* +* 3. Requirements: +* - Required variables in the dataset: +* - HDDSStapCer : Consumption of cereals +* - HDDSStapRoot : Consumption of roots/tubers +* - HDDSVeg : Consumption of vegetables +* - HDDSFruit : Consumption of fruits +* - HDDSPrMeat : Consumption of meat/poultry +* - HDDSPrEggs : Consumption of eggs +* - HDDSPrFish : Consumption of fish +* - HDDSPulse : Consumption of pulses/legumes +* - HDDSDairy : Consumption of milk and dairy products +* - HDDSFat : Consumption of oils/fats +* - HDDSSugar : Consumption of sugar/honey +* - HDDSCond : Consumption of miscellaneous/condiments +* +* 4. STATA Version: +* - STATA 14 or higher is recommended. +*------------------------------------------------------------------------------* + +*------------------------------------------------------------------------------ +* Step 1: Calculate the Household Dietary Diversity Score (HDDS) +*------------------------------------------------------------------------------ + +* The formula for HDDS is a sum of the 12 food group variables +gen HDDS = HDDSStapCer + + HDDSStapRoot + + HDDSVeg + + HDDSFruit + + HDDSPrMeat + + HDDSPrEggs + + HDDSPrFish + + HDDSPulse + + HDDSDairy + + HDDSFat + + HDDSSugar + + HDDSCond + +*------------------------------------------------------------------------------ +* Step 2: Categorize HDDS into Groups Based on IPC Thresholds +*------------------------------------------------------------------------------ + +* Categorize HDDS into "0-2", "3-4", and "5-12" food groups based on IPC thresholds. +gen HDDSCat_IPC = "" +replace HDDSCat_IPC = "0-2 food groups (phase 4 to 5)" if HDDS <= 2 +replace HDDSCat_IPC = "3-4 food groups (phase 3)" if HDDS > 2 & HDDS <= 4 +replace HDDSCat_IPC = "5-12 food groups (phase 1 to 2)" if HDDS > 4 diff --git a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.py b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.py new file mode 100644 index 0000000..cbd457c --- /dev/null +++ b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.py @@ -0,0 +1,89 @@ +#------------------------------------------------------------------------------# +# WFP RAM Standardized Scripts +# Calculating Household Dietary Diversity Score (HDDS) in Python +#------------------------------------------------------------------------------# +# 1. Purpose: +# This script calculates the Household Dietary Diversity Score (HDDS) using standardized +# food group variables based on a 24-hour recall. It assumes that the required variables +# are available in your dataset and correctly formatted for use in the calculation. +# +# 2. Assumptions: +# - The dataset contains standardized variables from Survey Designer. +# - The variables used for the HDDS calculation are properly named and cleaned. +# - The dataset is loaded into a pandas DataFrame before executing the script. +# +# 3. Requirements: +# - Required variables in the dataset: +# - HDDSStapCer : Consumption of cereals +# - HDDSStapRoot : Consumption of roots/tubers +# - HDDSVeg : Consumption of vegetables +# - HDDSFruit : Consumption of fruits +# - HDDSPrMeat : Consumption of meat/poultry +# - HDDSPrEggs : Consumption of eggs +# - HDDSPrFish : Consumption of fish +# - HDDSPulse : Consumption of pulses/legumes +# - HDDSDairy : Consumption of milk and dairy products +# - HDDSFat : Consumption of oils/fats +# - HDDSSugar : Consumption of sugar/honey +# - HDDSCond : Consumption of miscellaneous/condiments +# +# - Required Packages: +# - pandas (Install with `pip install pandas`) +# +# 4. Python Version: +# - Python 3.x is recommended for compatibility with the pandas package. +#------------------------------------------------------------------------------# + +# Load necessary libraries +import pandas as pd + +# Function to calculate HDDS +def calculate_hdds(df): + """ + Calculate the Household Dietary Diversity Score (HDDS). + + Parameters: + - df: pandas.DataFrame, the dataset containing the twelve HDDS variables + + Returns: + - df: pandas.DataFrame, the dataset with the calculated 'HDDS' variable + """ + # Calculate HDDS by summing the 12 food group variables + df['HDDS'] = (df['HDDSStapCer'] + + df['HDDSStapRoot'] + + df['HDDSVeg'] + + df['HDDSFruit'] + + df['HDDSPrMeat'] + + df['HDDSPrEggs'] + + df['HDDSPrFish'] + + df['HDDSPulse'] + + df['HDDSDairy'] + + df['HDDSFat'] + + df['HDDSSugar'] + + df['HDDSCond']) + + return df + +# Function to categorize HDDS into groups based on IPC thresholds +def categorize_hdds(df, hdds_column='HDDS'): + """ + Categorize HDDS into groups based on IPC severity scale. + + Parameters: + - df: pandas.DataFrame, the dataset containing the HDDS + - hdds_column: str, the name of the column containing the calculated HDDS (default is 'HDDS') + + Returns: + - df: pandas.DataFrame, the dataset with the calculated 'HDDSCat_IPC' variable + """ + # Recode HDDS into categories using IPC thresholds + df['HDDSCat_IPC'] = pd.cut( + df[hdds_column], + bins=[-float('inf'), 2, 4, float('inf')], + labels=["0-2 food groups (phase 4 to 5)", + "3-4 food groups (phase 3)", + "5-12 food groups (phase 1 to 2)"], + right=True + ) + + return df diff --git a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.sps b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.sps new file mode 100644 index 0000000..1ac6f4e --- /dev/null +++ b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.sps @@ -0,0 +1,73 @@ +*------------------------------------------------------------------------------* +* WFP RAM Standardized Scripts +* Calculating Household Dietary Diversity Score (HDDS) in SPSS +*------------------------------------------------------------------------------* +* 1. Purpose: +* This script calculates the Household Dietary Diversity Score (HDDS) using standardized +* food group variables based on a 24-hour recall. It assumes that the required variables +* are available in your dataset and correctly formatted for use in the calculation. +* +* 2. Assumptions: +* - The dataset contains standardized variables from Survey Designer. +* - The variables used for the HDDS calculation are properly named and cleaned. +* - The dataset is already loaded in SPSS. +* +* 3. Requirements: +* - Required variables in the dataset: +* - HDDSStapCer : Consumption of cereals +* - HDDSStapRoot : Consumption of roots/tubers +* - HDDSVeg : Consumption of vegetables +* - HDDSFruit : Consumption of fruits +* - HDDSPrMeat : Consumption of meat/poultry +* - HDDSPrEggs : Consumption of eggs +* - HDDSPrFish : Consumption of fish +* - HDDSPulse : Consumption of pulses/legumes +* - HDDSDairy : Consumption of milk and dairy products +* - HDDSFat : Consumption of oils/fats +* - HDDSSugar : Consumption of sugar/honey +* - HDDSCond : Consumption of miscellaneous/condiments +* +* 4. SPSS Version: +* - SPSS 21 or higher is recommended. +*------------------------------------------------------------------------------* + +*------------------------------------------------------------------------------ +* Step 1: Calculate the Household Dietary Diversity Score (HDDS) +*------------------------------------------------------------------------------ + +* The formula for HDDS is a sum of the 12 food group variables. +COMPUTE HDDS = HDDSStapCer + + HDDSStapRoot + + HDDSVeg + + HDDSFruit + + HDDSPrMeat + + HDDSPrEggs + + HDDSPrFish + + HDDSPulse + + HDDSDairy + + HDDSFat + + HDDSSugar + + HDDSCond. +EXECUTE. + +*------------------------------------------------------------------------------ +* Step 2: Categorize HDDS into Groups Based on IPC Thresholds +*------------------------------------------------------------------------------ + +* Recode HDDS into categories using IPC thresholds. +DO IF (HDDS <= 2). + COMPUTE HDDSCat_IPC = 1. +ELSE IF (HDDS > 2 AND HDDS <= 4). + COMPUTE HDDSCat_IPC = 2. +ELSE IF (HDDS > 4). + COMPUTE HDDSCat_IPC = 3. +END IF. +EXECUTE. + +* Label the HDDS categories based on IPC. +VALUE LABELS HDDSCat_IPC + 1 '0-2 food groups (phase 4 to 5)' + 2 '3-4 food groups (phase 3)' + 3 '5-12 food groups (phase 1 to 2)'. +VARIABLE LABELS HDDSCat_IPC 'HDDS categories using IPC severity scale'. +EXECUTE. diff --git a/Indicators/Household-Dietary-Diversity-Score/Household-Dietary-Diversity-Score.sps b/Indicators/Household-Dietary-Diversity-Score/Household-Dietary-Diversity-Score.sps deleted file mode 100644 index 092cca9..0000000 --- a/Indicators/Household-Dietary-Diversity-Score/Household-Dietary-Diversity-Score.sps +++ /dev/null @@ -1,36 +0,0 @@ -*** -------------------------------------------------------------------------- - -***    WFP RAM Standardized Scripts -*** Calculating Household Dietary Diversity Score (HDDS) - -*** -------------------------------------------------------------------------- - -* Encoding: UTF-8. - -***Create Household Dietary Diversity Score – 24hr recall from HDDS module *** -**remember that you need 12 food groups to compute the HDDS, recall period is past 24 hours before the survey - -Variable labels -HDDSStapCer Cereals consumption in the previous 24 hours -HDDSStapRoot Roots and tubers consumption in the previous 24 hours -HDDSVeg Vegetable consumption in the previous 24 hours -HDDSFruit Fruit consumption in the previous 24 hours -HDDSPrMeat Meat/poultry consumption in the previous 24 hours -HDDSPrEggs Eggs consumption in the previous 24 hours -HDDSPrFish Fish consumption in the previous 24 hours -HDDSPulse Pulses/legumes consumption in the previous 24 hours -HDDSDairy Milk and dairy product consumption in the previous 24 hours -HDDSFat Oil/fats consumption in the previous 24 hours -HDDSSugar Sugar/honey consumption in the previous 24 hours -HDDSCond Miscellaneous/condiments consumption in the previous 24 hours. - -**Note that it is advised to use + instead of SUM() as cases with missing values should not be included in the calcuation. - -Compute HDDS = HDDSStapCer + HDDSStapRoot + HDDSVeg + HDDSFruit + HDDSPrMeat + HDDSPrEggs + HDDSPrFish + HDDSPulse + HDDSDairy + HDDSFat + HDDSSugar + HDDSCond. -Variable labels HDDS 'Household Dietary Diversity Score'. -EXECUTE. - -Recode HDDS (lowest thru 2=1) (3 thru 4=2) (5 thru highest = 3) into HDDSCat_IPC. -Value labels HDDSCat_IPC 1 '0-2 food groups (phase 4 to 5)' 2 '3-4 food groups (phase 3)' 3 '5-12 food groups (phase 1 to 2)'. -Variable labels HDDSCat_IPC 'HDDS categories using IPC severity scale'. -EXECUTE. From b93da5de34fdbddbcee865cf0a3ec727ddf39a23 Mon Sep 17 00:00:00 2001 From: AssiALi16 <154439283+AssiALi16@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:43:40 +0300 Subject: [PATCH 4/4] Updated FCSN Indicator Calculation Scripts in Python, R, Stata, and SPSS --- .../FCSN-indicator-calculation.R | 90 +++++++++++++ .../FCSN-indicator-calculation.do | 122 +++++++++++------- .../FCSN-indicator-calculation.py | 88 +++++++++++++ .../FCSN-indicator-calculation.sps | 121 ++++++++--------- .../FCSN_indicator_tidyverse.R | 87 ------------- .../FCS-indicator-calculation.R | 2 +- .../FCS-indicator-calculation.do | 2 +- .../FCS-indicator-calculation.py | 2 +- .../FCS-indicator-calculation.sps | 2 +- .../HDDS-indicator-calculation.R | 20 +-- .../HDDS-indicator-calculation.do | 19 +-- .../HDDS-indicator-calculation.py | 19 +-- .../HDDS-indicator-calculation.sps | 19 +-- .../rCSI-indicator-calculation.R | 2 +- .../rCSI-indicator-calculation.do | 2 +- .../rCSI-indicator-calculation.py | 2 +- .../rCSI-indicator-calculation.sps | 2 +- 17 files changed, 343 insertions(+), 258 deletions(-) create mode 100644 Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.R create mode 100644 Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.py delete mode 100644 Indicators/Food-consumption-score-nutrition/FCSN_indicator_tidyverse.R diff --git a/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.R b/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.R new file mode 100644 index 0000000..312e7b7 --- /dev/null +++ b/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.R @@ -0,0 +1,90 @@ +#------------------------------------------------------------------------------# +# WFP APP Standardized Scripts +# Calculating Food Consumption Score Nutrition (FCSN) in R +#------------------------------------------------------------------------------# +# 1. Purpose: +# This script calculates the Food Consumption Score Nutrition (FCSN) by aggregating +# food consumption data for different nutrients. It assumes that the required variables +# are available in your dataset and correctly formatted for use in the calculation. +# +# 2. Assumptions: +# - The dataset contains standardized variables from Survey Designer. +# - The variables used for the FCSN calculation are properly named and cleaned. +# - The dataset is loaded into a data frame before executing the script. +# +# 3. Requirements: +# - Required variables in the dataset: +# - FCSDairy : Consumption of dairy (past 7 days) +# - FCSPulse : Consumption of pulse (past 7 days) +# - FCSNPrMeatF : Consumption of flesh meat (past 7 days) +# - FCSNPrMeatO : Consumption of organ meat (past 7 days) +# - FCSNPrFish : Consumption of fish/shellfish (past 7 days) +# - FCSNPrEggs : Consumption of eggs (past 7 days) +# - FCSNVegOrg : Consumption of orange vegetables (vitamin A-rich) +# - FCSNVegGre : Consumption of green leafy vegetables +# - FCSNFruiOrg : Consumption of orange fruits (vitamin A-rich) +# +# - Required Packages: +# - No specific packages needed. +# +# 4. R Version: +# - R 3.x or higher is recommended for compatibility with modern libraries. +#------------------------------------------------------------------------------# + +# Function to compute key nutrient aggregates (vitamin A, protein, and iron) +compute_nutrient_aggregates <- function(df) { + # Compute aggregates of key micronutrient consumption (Vitamin A, Protein, Hem Iron) + + # Parameters: + # - df: DataFrame, the dataset containing the FCS and FCSN variables + + # Returns: + # - df: DataFrame, the dataset with calculated micronutrient aggregates + + # Sum the columns and treat NA as 0 for vitamin A-rich foods + df$FGVitA <- rowSums(df[, c('FCSDairy', 'FCSNPrMeatO', 'FCSNPrEggs', + 'FCSNVegOrg', 'FCSNVegGre', 'FCSNFruiOrg')], na.rm = TRUE) + + # Sum the columns and treat NA as 0 for protein-rich foods + df$FGProtein <- rowSums(df[, c('FCSPulse', 'FCSDairy', 'FCSNPrMeatF', + 'FCSNPrMeatO', 'FCSNPrFish', 'FCSNPrEggs')], na.rm = TRUE) + + # Sum the columns and treat NA as 0 for hem iron-rich foods + df$FGHIron <- rowSums(df[, c('FCSNPrMeatF', 'FCSNPrMeatO', 'FCSNPrFish')], na.rm = TRUE) + + return(df) +} + +# Function to categorize nutrient consumption groups based on thresholds +categorize_nutrient_consumption <- function(df, vita_column = 'FGVitA', fgprotein_column = 'FGProtein', fghiron_column = 'FGHIron') { + # Categorize nutrient consumption into groups (Never, Sometimes, At least 7 times) + + # Parameters: + # - df: DataFrame, the dataset containing the nutrient data + # - vita_column: str, the name of vitamin A-rich nutrient column + # - fgprotein_column: str, the name of the protein-rich nutrient column + # - fghiron_column: str, the name of the iron-rich nutrient column + + # Returns: + # - df: DataFrame, the dataset with categorized nutrient groups + + # Define categories for vitamin A-rich foods + df$FGVitACat <- cut(df[[vita_column]], + breaks = c(-Inf, 0, 6, Inf), + labels = c("Never consumed", "Consumed sometimes", "Consumed at least 7 times"), + right = TRUE) + + # Define categories for protein-rich foods + df$FGProteinCat <- cut(df[[fgprotein_column]], + breaks = c(-Inf, 0, 6, Inf), + labels = c("Never consumed", "Consumed sometimes", "Consumed at least 7 times"), + right = TRUE) + + # Define categories for iron-rich foods + df$FGHIronCat <- cut(df[[fghiron_column]], + breaks = c(-Inf, 0, 6, Inf), + labels = c("Never consumed", "Consumed sometimes", "Consumed at least 7 times"), + right = TRUE) + + return(df) +} diff --git a/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.do b/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.do index 9a66613..a2f66f9 100644 --- a/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.do +++ b/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.do @@ -1,51 +1,77 @@ *------------------------------------------------------------------------------* +* WFP APP Standardized Scripts +* Calculating Food Consumption Score Nutrition (FCSN) in Stata +*------------------------------------------------------------------------------* +* 1. Purpose: +* This script calculates the Food Consumption Score Nutrition (FCSN) by aggregating +* food consumption data for different nutrients. It assumes that the required variables +* are available in your dataset and correctly formatted for use in the calculation. +* +* 2. Assumptions: +* - The dataset contains standardized variables from Survey Designer. +* - The variables used for the FCSN calculation are properly named and cleaned. +* - The dataset is loaded into Stata before executing the script. +* +* 3. Requirements: +* - Required variables in the dataset: +* - FCSDairy : Consumption of dairy (past 7 days) +* - FCSPulse : Consumption of pulse (past 7 days) +* - FCSNPrMeatF : Consumption of flesh meat (past 7 days) +* - FCSNPrMeatO : Consumption of organ meat (past 7 days) +* - FCSNPrFish : Consumption of fish/shellfish (past 7 days) +* - FCSNPrEggs : Consumption of eggs (past 7 days) +* - FCSNVegOrg : Consumption of orange vegetables (vitamin A-rich) +* - FCSNVegGre : Consumption of green leafy vegetables +* - FCSNFruiOrg : Consumption of orange fruits (vitamin A-rich) +* +* 4. Stata Version: +* - Stata 13 or higher is recommended for compatibility with modern syntax. +*------------------------------------------------------------------------------* -* WFP RAM Standardized Scripts -* Calculating Food Consumption Score - Nutrition (FCSN) +*------------------------------------------------------------------------------* +* Step 1: Compute Nutrient Aggregates (Vitamin A, Protein, and Hem Iron) +*------------------------------------------------------------------------------* -* -----------------------------------------------------------------------------* -* -* Load data -* --------- - import delim using "../GitHub/RAMResourcesScripts/Static/FCSN_Sample_Survey.csv", /// - clear case(preserve) - -** check and recode missing values as 0 - sum FCS* - sum FCSN* - recode FCS* (. = 0) - -** assign variable labels - label var FCSNPrMeatF "Consumption in past 7 days: Flesh meat" - label var FCSNPrMeatO "Consumption in past 7 days: Organ meat" - label var FCSNPrFish "Consumption in past 7 days: Fish/shellfish" - label var FCSNPrEggs "Consumption in past 7 days: Eggs" - label var FCSNVegOrg "Consumption in past 7 days: Orange vegetables (vegetables rich in Vitamin A)" - label var FCSNVegGre "Consumption in past 7 days: Green leafy vegetables" - label var FCSNFruiOrg "Consumption in past 7 days: Orange fruits (Fruits rich in Vitamin A)" - -** create aggregates of key micronutrient consumption of vitamin, iron and protein - gen FGVitA = FCSDairy + FCSNPrMeatO + FCSNPrEggs + FCSNVegOrg + FCSNVegGre + FCSNFruiOrg - gen FGProtein = FCSPulse + FCSDairy + FCSNPrMeatF + FCSNPrMeatO + FCSNPrFish + FCSNPrEggs - gen FGHIron = FCSNPrMeatF + FCSNPrMeatO + FCSNPrFish - - label var FGVitA "Consumption of vitamin A-rich foods" - label var FGProtein "Consumption of protein-rich foods" - label var FGHIron "Consumption of hem iron-rich foods" - -** recode into nutritious groups - gen FGVitACat = cond(FGVitA < 1,1,cond(FGVitA <= 6,2,3)) - gen FGProteinCat = cond(FGProtein < 1,1,cond(FGProtein <= 6,2,3)) - gen FGHIronCat = cond(FGHIron < 1,1,cond(FGHIron <= 6,2,3)) - -** define variables labels and properties for FGVitACat FGProteinCat FGHIronCat - label def FGN_l 1 "Never consumed" /// - 2 "Consumed sometimes" /// - 3 "Consumed at least 7 times" - label val FGVitACat FGProteinCat FGHIron_Cat FGHIronCat - - label var FGVitACat "Consumption group of vitamin A-rich foods" - label var FGProteinCat "Consumption group of protein-rich foods" - label var FGHIronCat "Consumption group of heme iron-rich foods" - -* End of scripts +* Use rowtotal() to sum the relevant columns and treat missing values as 0 +* Compute Vitamin A-rich foods aggregate +gen FGVitA = rowtotal(FCSDairy FCSNPrMeatO FCSNPrEggs FCSNVegOrg FCSNVegGre FCSNFruiOrg) +label variable FGVitA "Consumption of vitamin A-rich foods" + +* Compute Protein-rich foods aggregate +gen FGProtein = rowtotal(FCSPulse FCSDairy FCSNPrMeatF FCSNPrMeatO FCSNPrFish FCSNPrEggs) +label variable FGProtein "Consumption of protein-rich foods" + +* Compute Hem Iron-rich foods aggregate +gen FGHIron = rowtotal(FCSNPrMeatF FCSNPrMeatO FCSNPrFish) +label variable FGHIron "Consumption of hem iron-rich foods" + +*------------------------------------------------------------------------------* +* Step 2: Categorize Nutrient Consumption Groups Based on Thresholds +*------------------------------------------------------------------------------* + +* Categorize consumption of Vitamin A-rich foods +gen FGVitACat = . +replace FGVitACat = 1 if FGVitA == 0 +replace FGVitACat = 2 if FGVitA > 0 & FGVitA <= 6 +replace FGVitACat = 3 if FGVitA > 6 +label define FGVitACat_lbl 1 "Never consumed" 2 "Consumed sometimes" 3 "Consumed at least 7 times" +label values FGVitACat FGVitACat_lbl +label variable FGVitACat "Consumption group of vitamin A-rich foods" + +* Categorize consumption of Protein-rich foods +gen FGProteinCat = . +replace FGProteinCat = 1 if FGProtein == 0 +replace FGProteinCat = 2 if FGProtein > 0 & FGProtein <= 6 +replace FGProteinCat = 3 if FGProtein > 6 +label define FGProteinCat_lbl 1 "Never consumed" 2 "Consumed sometimes" 3 "Consumed at least 7 times" +label values FGProteinCat FGProteinCat_lbl +label variable FGProteinCat "Consumption group of protein-rich foods" + +* Categorize consumption of Hem Iron-rich foods +gen FGHIronCat = . +replace FGHIronCat = 1 if FGHIron == 0 +replace FGHIronCat = 2 if FGHIron > 0 & FGHIron <= 6 +replace FGHIronCat = 3 if FGHIron > 6 +label define FGHIronCat_lbl 1 "Never consumed" 2 "Consumed sometimes" 3 "Consumed at least 7 times" +label values FGHIronCat FGHIronCat_lbl +label variable FGHIronCat "Consumption group of hem iron-rich foods" diff --git a/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.py b/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.py new file mode 100644 index 0000000..3a0f9aa --- /dev/null +++ b/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.py @@ -0,0 +1,88 @@ +#------------------------------------------------------------------------------# +# WFP APP Standardized Scripts +# Calculating Food Consumption Score Nutrition (FCSN) in Python +#------------------------------------------------------------------------------# +# 1. Purpose: +# This script calculates the Food Consumption Score Nutrition (FCSN) by aggregating +# food consumption data for different nutrients. It assumes that the required variables +# are available in your dataset and correctly formatted for use in the calculation. +# +# 2. Assumptions: +# - The dataset contains standardized variables from Survey Designer. +# - The variables used for the FCSN calculation are properly named and cleaned. +# - The dataset is loaded into a pandas DataFrame before executing the script. +# +# 3. Requirements: +# - Required variables in the dataset: +# - FCSDairy : Consumption of dairy (past 7 days) +# - FCSPulse : Consumption of pulse (past 7 days) +# - FCSNPrMeatF : Consumption of flesh meat (past 7 days) +# - FCSNPrMeatO : Consumption of organ meat (past 7 days) +# - FCSNPrFish : Consumption of fish/shellfish (past 7 days) +# - FCSNPrEggs : Consumption of eggs (past 7 days) +# - FCSNVegOrg : Consumption of orange vegetables (vitamin A-rich) +# - FCSNVegGre : Consumption of green leafy vegetables +# - FCSNFruiOrg : Consumption of orange fruits (vitamin A-rich) +# +# - Required Packages: +# - pandas (Install with `pip install pandas`) +# +# 4. Python Version: +# - Python 3.x is recommended for compatibility with the pandas package. +#------------------------------------------------------------------------------# + +# Load necessary libraries +import pandas as pd + +# Function to compute key nutrient aggregates (vitamin A, protein, and iron) +def compute_nutrient_aggregates(df): + """ + Compute aggregates of key micronutrient consumption (Vitamin A, Protein, Hem Iron). + + Parameters: + - df: pandas.DataFrame, the dataset containing the FCS and FCSN variables + + Returns: + - df: pandas.DataFrame, the dataset with calculated micronutrient aggregates + """ + # Sum the columns and treat NaN as 0 for vitamin A-rich foods + df['FGVitA'] = df[['FCSDairy', 'FCSNPrMeatO', 'FCSNPrEggs', 'FCSNVegOrg', + 'FCSNVegGre', 'FCSNFruiOrg']].sum(axis=1, skipna=True) + + # Sum the columns and treat NaN as 0 for protein-rich foods + df['FGProtein'] = df[['FCSPulse', 'FCSDairy', 'FCSNPrMeatF', + 'FCSNPrMeatO', 'FCSNPrFish', 'FCSNPrEggs']].sum(axis=1, skipna=True) + + # Sum the columns and treat NaN as 0 for hem iron-rich foods + df['FGHIron'] = df[['FCSNPrMeatF', 'FCSNPrMeatO', 'FCSNPrFish']].sum(axis=1, skipna=True) + + return df + +# Function to categorize nutrient consumption groups based on thresholds +def categorize_nutrient_consumption(df, vita_column='FGVitA', fgprotein_column='FGProtein', fghiron_column='FGHIron'): + """ + Categorize nutrient consumption into groups (Never, Sometimes, At least 7 times). + + Parameters: + - df: pandas.DataFrame, the dataset containing the nutrient data + - vita_column: str, the name of vitamin A-rich nutrient column + - fgprotein_column: str, the name of the protein-rich nutrient column + - fghiron_column: str, the name of the iron-rich nutrient column + + Returns: + - df: pandas.DataFrame, the dataset with categorized nutrient groups + """ + for column in [vita_column, fgprotein_column, fghiron_column]: + df[column + 'Cat'] = pd.cut( + df[column], + bins=[-float('inf'), 0, 6, 42], + labels=["Never consumed", "Consumed sometimes", "Consumed at least 7 times"], + right=True + ) + + return df + +# Example usage of the functions: +df = pd.DataFrame({'FCSDairy': [5, 0, 1], 'FCSNPrMeatF': [1, 0, 1], 'FCSNPrMeatO': [0, 0, 1], + 'FCSNPrFish': [5, 0, 0], 'FCSNPrEggs': [1, 0, 0], 'FCSNVegOrg': [0, 0, 1], + 'FCSNVegGre': [5, 0, 1], 'FCSNFruiOrg': [1, 0, 1], 'FCSPulse': [1, 0, 0]}) diff --git a/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.sps b/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.sps index dcb5a32..879c019 100644 --- a/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.sps +++ b/Indicators/Food-consumption-score-nutrition/FCSN-indicator-calculation.sps @@ -1,66 +1,69 @@ -*** -------------------------------------------------------------------------- - -*** WFP RAM Standardized Scripts -*** Calculating Food Consumption Score Nutrition (FCSN) - -*** -------------------------------------------------------------------------- - -* Encoding: UTF-8. - -*** Define labels - -Variable labels -FCSNPrMeatF "Consumption in past 7 days: Flesh meat" -FCSNPrMeatO "Consumption in past 7 days: Organ meat" -FCSNPrFish "Consumption in past 7 days: Fish/shellfish" -FCSNPrEggs "Consumption in past 7 days: Eggs" -FCSNVegOrg "Consumption in past 7 days: Orange vegetables (vegetables rich in Vitamin A)" -FCSNVegGre "Consumption in past 7 days: Green leafy vegetables" -FCSNFruiOrg "Consumption in past 7 days: Orange fruits (Fruits rich in Vitamin A)". - -*** Recode "n/a" values to 0 and change variable type to numeric - -ALTER TYPE FCSNPrMeatF FCSNPrMeatO FCSNPrFish FCSNPrEggs FCSNVegOrg FCSNVegGre FCSNFruiOrg (a5). - -RECODE FCSNPrMeatF FCSNPrMeatO FCSNPrFish FCSNPrEggs FCSNVegOrg FCSNVegGre FCSNFruiOrg - ('n/a'='0'). +*------------------------------------------------------------------------------* +* WFP APP Standardized Scripts +* Calculating Food Consumption Score Nutrition (FCSN) in SPSS +*------------------------------------------------------------------------------* +* 1. Purpose: +* This script calculates the Food Consumption Score Nutrition (FCSN) by aggregating +* food consumption data for different nutrients. It assumes that the required variables +* are available in your dataset and correctly formatted for use in the calculation. +* +* 2. Assumptions: +* - The dataset contains standardized variables from Survey Designer. +* - The variables used for the FCSN calculation are properly named and cleaned. +* - The dataset is loaded into SPSS before executing the script. +* +* 3. Requirements: +* - Required variables in the dataset: +* - FCSDairy : Consumption of dairy (past 7 days) +* - FCSPulse : Consumption of pulse (past 7 days) +* - FCSNPrMeatF : Consumption of flesh meat (past 7 days) +* - FCSNPrMeatO : Consumption of organ meat (past 7 days) +* - FCSNPrFish : Consumption of fish/shellfish (past 7 days) +* - FCSNPrEggs : Consumption of eggs (past 7 days) +* - FCSNVegOrg : Consumption of orange vegetables (vitamin A-rich) +* - FCSNVegGre : Consumption of green leafy vegetables +* - FCSNFruiOrg : Consumption of orange fruits (vitamin A-rich) +* +*------------------------------------------------------------------------------* + +*------------------------------------------------------------------------------* +* Step 1: Compute Nutrient Aggregates (Vitamin A, Protein, and Hem Iron) +*------------------------------------------------------------------------------* + +* Use SUM() to sum the relevant columns and treat missing values as 0 +* Compute Vitamin A-rich foods aggregate. +COMPUTE FGVitA = SUM(FCSDairy, FCSNPrMeatO, FCSNPrEggs, FCSNVegOrg, FCSNVegGre, FCSNFruiOrg). +VARIABLE LABELS FGVitA 'Consumption of vitamin A-rich foods'. EXECUTE. -ALTER TYPE FCSNPrMeatF FCSNPrMeatO FCSNPrFish FCSNPrEggs FCSNVegOrg FCSNVegGre FCSNFruiOrg (F1). - -*** Compute aggregates of key micronutrient consumption – vitamin, iron and protein - -Compute FGVitA = sum(FCSDairy, FCSNPrMeatO, FCSNPrEggs, FCSNVegOrg, FCSNVegGre, FCSNFruiOrg). -Variable labels FGVitA 'Consumption of vitamin A-rich foods'. -EXECUTE. - -Compute FGProtein = sum(FCSPulse, FCSDairy, FCSNPrMeatF, FCSNPrMeatO, FCSNPrFish, FCSNPrEggs). -Variable labels FGProtein 'Consumption of protein-rich foods'. -EXECUTE. - -Compute FGHIron = sum(FCSNPrMeatF, FCSNPrMeatO, FCSNPrFish). -Variable labels FGHIron 'Consumption of hem iron-rich foods'. -EXECUTE. - -*** Recode into nutritious groups - -Recode FGVitA (0=1) (1 thru 6=2) (7 thru 42=3) into FGVitACat. -Variable labels FGVitACat 'Consumption group of vitamin A-rich foods'. -EXECUTE. - -Recode FGProtein (0=1) (1 thru 6=2) (7 thru 42=3) into FGProteinCat. -Variable labels FGProteinCat 'Consumption group of protein-rich foods'. -EXECUTE. +* Compute Protein-rich foods aggregate. +COMPUTE FGProtein = SUM(FCSPulse, FCSDairy, FCSNPrMeatF, FCSNPrMeatO, FCSNPrFish, FCSNPrEggs). +VARIABLE LABELS FGProtein 'Consumption of protein-rich foods'. +EXECUTE. -Recode FGHIron (0=1) (1 thru 6=2) (7 thru 42=3) into FGHIronCat. -Variable labels FGHIronCat 'Consumption group of hem iron-rich foods'. -EXECUTE. +* Compute Hem Iron-rich foods aggregate. +COMPUTE FGHIron = SUM(FCSNPrMeatF, FCSNPrMeatO, FCSNPrFish). +VARIABLE LABELS FGHIron 'Consumption of hem iron-rich foods'. +EXECUTE. - *** Define variables labels and properties for "FGVitACat FGProteinCat FGHIronCat". +*------------------------------------------------------------------------------* +* Step 2: Categorize Nutrient Consumption Groups Based on Thresholds +*------------------------------------------------------------------------------* - Value labels FGVitACat FGProteinCat FGHIronCat -1.00 'Never consumed' 2.00 'Consumed sometimes' 3.00 'Consumed at least 7 times'. +* Categorize Vitamin A-rich foods consumption. +RECODE FGVitA (0=1) (1 THRU 6=2) (7 THRU HI=3) INTO FGVitACat. +VARIABLE LABELS FGVitACat 'Consumption group of vitamin A-rich foods'. +VALUE LABELS FGVitACat 1 'Never consumed' 2 'Consumed sometimes' 3 'Consumed at least 7 times'. +EXECUTE. -EXECUTE. +* Categorize Protein-rich foods consumption. +RECODE FGProtein (0=1) (1 THRU 6=2) (7 THRU HI=3) INTO FGProteinCat. +VARIABLE LABELS FGProteinCat 'Consumption group of protein-rich foods'. +VALUE LABELS FGProteinCat 1 'Never consumed' 2 'Consumed sometimes' 3 'Consumed at least 7 times'. +EXECUTE. -*** End of Scripts \ No newline at end of file +* Categorize Hem Iron-rich foods consumption. +RECODE FGHIron (0=1) (1 THRU 6=2) (7 THRU HI=3) INTO FGHIronCat. +VARIABLE LABELS FGHIronCat 'Consumption group of hem iron-rich foods'. +VALUE LABELS FGHIronCat 1 'Never consumed' 2 'Consumed sometimes' 3 'Consumed at least 7 times'. +EXECUTE. diff --git a/Indicators/Food-consumption-score-nutrition/FCSN_indicator_tidyverse.R b/Indicators/Food-consumption-score-nutrition/FCSN_indicator_tidyverse.R deleted file mode 100644 index 6c1b504..0000000 --- a/Indicators/Food-consumption-score-nutrition/FCSN_indicator_tidyverse.R +++ /dev/null @@ -1,87 +0,0 @@ -#------------------------------------------------------------------------------# - -# WFP RAM Standardized Scripts -# Calculating Food Consumption Score - Nutrition (FCSN) - -#------------------------------------------------------------------------------# - -rm(list = ls()) - -## Load Packages --------------------------------------------------------------# - -library(tidyverse) -library(labelled) -library(expss) - -# Load Sample Data ------------------------------------------------------------# - -data <- read_csv("~/GitHub/RAMResourcesScripts/Static/FCSN_Sample_Survey.csv") - -# Label FCSN relevant variables -----------------------------------------------# - -var_label(data$FCSNPrMeatF) <- "Consumption in past 7 days: Flesh meat" -var_label(data$FCSNPrMeatO) <- "Consumption in past 7 days: Organ meat" -var_label(data$FCSNPrFish) <- "Consumption in past 7 days: Fish/shellfish" -var_label(data$FCSNPrEggs) <- "Consumption in past 7 days: Eggs" -var_label(data$FCSNVegOrg) <- "Consumption in past 7 days: Orange vegetables (vegetables rich in Vitamin A)" -var_label(data$FCSNVegGre) <- "Consumption in past 7 days: Green leafy vegetables" -var_label(data$FCSNFruiOrg) <- "Consumption in past 7 days: Orange fruits (Fruits rich in Vitamin A)" - -#recode "n/a" values to 0 and change to numeric -vars2recode <- c("FCSNPrMeatF","FCSNPrMeatO","FCSNPrFish","FCSNPrEggs", - "FCSNVegOrg","FCSNVegGre","FCSNFruiOrg") - -data <- data %>% mutate_at(vars2recode, ~replace(., . == "n/a", "0")) -data <- data %>% mutate_at(vars2recode, as.numeric) - -# Compute aggregates of key micronutrient consumption -------------------------# - -## Vitamin A-Rich Foods -------------------------------------------------------# - -data <- data %>% mutate(FGVitA = FCSDairy +FCSNPrMeatO +FCSNPrEggs + - FCSNVegOrg +FCSNVegGre +FCSNFruiOrg) -var_label(data$FGVitA) <- "Consumption of vitamin A-rich foods" - -## Protein-Rich Foods ---------------------------------------------------------# - -data <- data %>% mutate(FGProtein = FCSPulse +FCSDairy +FCSNPrMeatF + - FCSNPrMeatO +FCSNPrFish +FCSNPrEggs) -var_label(data$FGProtein) <- "Consumption of protein-rich foods" - -## Iron-Rich Foods ------------------------------------------------------------# - -data <- data %>% mutate(FGHIron = FCSNPrMeatF +FCSNPrMeatO +FCSNPrFish) -var_label(data$FGHIron) <- "Consumption of heme iron-rich foods" - -## recode into nutritious groups ---------------------------------------------# - -data <- data %>% mutate(FGVitACat = case_when(FGVitA == 0 ~ 1, - between(FGVitA,1,6) ~ 2, - FGVitA >= 7 ~ 3), - FGProteinCat = case_when(FGProtein == 0 ~ 1, - between(FGProtein,1,6) ~ 2, - FGProtein >= 7 ~ 3), - FGHIronCat = case_when(FGHIron == 0 ~ 1, - between(FGHIron,1,6) ~ 2, - FGHIron >= 7 ~ 3)) - -# define variables labels and properties for FGVitACat FGProteinCat FGHIronCat -data <- data %>% - mutate(across(c(FGVitACat, FGProteinCat, FGHIronCat), - ~labelled(., labels = c( - "Never consumed" = 1, - "Consumed sometimes" = 2, - "Consumed at least 7 times" = 3 - )))) - -data <- data %>% - mutate(across(c(FGVitACat, FGProteinCat, FGHIronCat), - ~factor(., levels = c(1, 2, 3), - labels = c("Never consumed", "Consumed sometimes", - "Consumed at least 7 times")))) - -var_label(data$FGVitACat) <- "Consumption group of vitamin A-rich foods" -var_label(data$FGProteinCat) <- "Consumption group of protein-rich foods" -var_label(data$FGHIronCat) <- "Consumption group of heme iron-rich foods" - -# End of Scripts \ No newline at end of file diff --git a/Indicators/Food-consumption-score/FCS-indicator-calculation.R b/Indicators/Food-consumption-score/FCS-indicator-calculation.R index 2bce2fd..104ffb1 100644 --- a/Indicators/Food-consumption-score/FCS-indicator-calculation.R +++ b/Indicators/Food-consumption-score/FCS-indicator-calculation.R @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------# -# WFP RAM Standardized Scripts +# WFP APP Standardized Scripts # Food Consumption Score (FCS) Calculation in R #------------------------------------------------------------------------------# # 1. Purpose: diff --git a/Indicators/Food-consumption-score/FCS-indicator-calculation.do b/Indicators/Food-consumption-score/FCS-indicator-calculation.do index c7f589e..554c02c 100644 --- a/Indicators/Food-consumption-score/FCS-indicator-calculation.do +++ b/Indicators/Food-consumption-score/FCS-indicator-calculation.do @@ -1,5 +1,5 @@ *------------------------------------------------------------------------------* -* WFP RAM Standardized Scripts +* WFP APP Standardized Scripts * Food Consumption Score (FCS) Calculation in STATA *------------------------------------------------------------------------------* * 1. Purpose: diff --git a/Indicators/Food-consumption-score/FCS-indicator-calculation.py b/Indicators/Food-consumption-score/FCS-indicator-calculation.py index e29582e..dcebd50 100644 --- a/Indicators/Food-consumption-score/FCS-indicator-calculation.py +++ b/Indicators/Food-consumption-score/FCS-indicator-calculation.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------# -# WFP RAM Standardized Scripts +# WFP APP Standardized Scripts # Food Consumption Score (FCS) Calculation in Python #------------------------------------------------------------------------------# # 1. Purpose: diff --git a/Indicators/Food-consumption-score/FCS-indicator-calculation.sps b/Indicators/Food-consumption-score/FCS-indicator-calculation.sps index d16f731..f776124 100644 --- a/Indicators/Food-consumption-score/FCS-indicator-calculation.sps +++ b/Indicators/Food-consumption-score/FCS-indicator-calculation.sps @@ -1,5 +1,5 @@ *------------------------------------------------------------------------------* -* WFP RAM Standardized Scripts +* WFP APP Standardized Scripts * Food Consumption Score (FCS) Calculation in SPSS *------------------------------------------------------------------------------* * 1. Purpose: diff --git a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.R b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.R index 87bbc34..db40ed0 100644 --- a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.R +++ b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.R @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------# -# WFP RAM Standardized Scripts +# WFP APP Standardized Scripts # Calculating Household Dietary Diversity Score (HDDS) in R #------------------------------------------------------------------------------# # 1. Purpose: @@ -41,19 +41,11 @@ calculate_hdds <- function(df) { # Returns: # - df: DataFrame, the dataset with the calculated 'HDDS' variable - df$HDDS <- df$HDDSStapCer + - df$HDDSStapRoot + - df$HDDSVeg + - df$HDDSFruit + - df$HDDSPrMeat + - df$HDDSPrEggs + - df$HDDSPrFish + - df$HDDSPulse + - df$HDDSDairy + - df$HDDSFat + - df$HDDSSugar + - df$HDDSCond - + # Sum the columns and treat NA as 0 + df$HDDS <- rowSums(df[, c('HDDSStapCer', 'HDDSStapRoot', 'HDDSVeg', 'HDDSFruit', + 'HDDSPrMeat', 'HDDSPrEggs', 'HDDSPrFish', 'HDDSPulse', + 'HDDSDairy', 'HDDSFat', 'HDDSSugar', 'HDDSCond')], na.rm = TRUE) + return(df) } diff --git a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.do b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.do index 7039f50..07f35a6 100644 --- a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.do +++ b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.do @@ -1,5 +1,5 @@ *------------------------------------------------------------------------------* -* WFP RAM Standardized Scripts +* WFP APP Standardized Scripts * Calculating Household Dietary Diversity Score (HDDS) in STATA *------------------------------------------------------------------------------* * 1. Purpose: @@ -35,19 +35,10 @@ * Step 1: Calculate the Household Dietary Diversity Score (HDDS) *------------------------------------------------------------------------------ -* The formula for HDDS is a sum of the 12 food group variables -gen HDDS = HDDSStapCer + - HDDSStapRoot + - HDDSVeg + - HDDSFruit + - HDDSPrMeat + - HDDSPrEggs + - HDDSPrFish + - HDDSPulse + - HDDSDairy + - HDDSFat + - HDDSSugar + - HDDSCond +* Use rowtotal() to sum the 12 food group variables and treat missing values as 0 +gen HDDS = rowtotal(HDDSStapCer HDDSStapRoot HDDSVeg HDDSFruit HDDSPrMeat + HDDSPrEggs HDDSPrFish HDDSPulse HDDSDairy HDDSFat + HDDSSugar HDDSCond) *------------------------------------------------------------------------------ * Step 2: Categorize HDDS into Groups Based on IPC Thresholds diff --git a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.py b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.py index cbd457c..dbaacc6 100644 --- a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.py +++ b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------# -# WFP RAM Standardized Scripts +# WFP APP Standardized Scripts # Calculating Household Dietary Diversity Score (HDDS) in Python #------------------------------------------------------------------------------# # 1. Purpose: @@ -48,19 +48,10 @@ def calculate_hdds(df): Returns: - df: pandas.DataFrame, the dataset with the calculated 'HDDS' variable """ - # Calculate HDDS by summing the 12 food group variables - df['HDDS'] = (df['HDDSStapCer'] + - df['HDDSStapRoot'] + - df['HDDSVeg'] + - df['HDDSFruit'] + - df['HDDSPrMeat'] + - df['HDDSPrEggs'] + - df['HDDSPrFish'] + - df['HDDSPulse'] + - df['HDDSDairy'] + - df['HDDSFat'] + - df['HDDSSugar'] + - df['HDDSCond']) + # Sum the 12 food group variables, treating NaN as 0 + df['HDDS'] = df[['HDDSStapCer', 'HDDSStapRoot', 'HDDSVeg', 'HDDSFruit', + 'HDDSPrMeat', 'HDDSPrEggs', 'HDDSPrFish', 'HDDSPulse', + 'HDDSDairy', 'HDDSFat', 'HDDSSugar', 'HDDSCond']].sum(axis=1, skipna=True) return df diff --git a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.sps b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.sps index 1ac6f4e..59363d6 100644 --- a/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.sps +++ b/Indicators/Household-Dietary-Diversity-Score/HDDS-indicator-calculation.sps @@ -1,5 +1,5 @@ *------------------------------------------------------------------------------* -* WFP RAM Standardized Scripts +* WFP APP Standardized Scripts * Calculating Household Dietary Diversity Score (HDDS) in SPSS *------------------------------------------------------------------------------* * 1. Purpose: @@ -35,19 +35,10 @@ * Step 1: Calculate the Household Dietary Diversity Score (HDDS) *------------------------------------------------------------------------------ -* The formula for HDDS is a sum of the 12 food group variables. -COMPUTE HDDS = HDDSStapCer + - HDDSStapRoot + - HDDSVeg + - HDDSFruit + - HDDSPrMeat + - HDDSPrEggs + - HDDSPrFish + - HDDSPulse + - HDDSDairy + - HDDSFat + - HDDSSugar + - HDDSCond. +* Use SUM() function to sum the 12 food group variables, treating missing values as 0. +COMPUTE HDDS = SUM(HDDSStapCer, HDDSStapRoot, HDDSVeg, HDDSFruit, + HDDSPrMeat, HDDSPrEggs, HDDSPrFish, HDDSPulse, + HDDSDairy, HDDSFat, HDDSSugar, HDDSCond). EXECUTE. *------------------------------------------------------------------------------ diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.R b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.R index 6f3a73a..9d911d1 100644 --- a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.R +++ b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.R @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------# -# WFP RAM Standardized Scripts +# WFP APP Standardized Scripts # Reduced Coping Strategies Index (rCSI) Calculation in R #------------------------------------------------------------------------------# # 1. Purpose: diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.do b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.do index 70d13a1..3e52ce3 100644 --- a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.do +++ b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.do @@ -1,5 +1,5 @@ *------------------------------------------------------------------------------* -* WFP RAM Standardized Scripts +* WFP APP Standardized Scripts * Reduced Coping Strategies Index (rCSI) Calculation in STATA *------------------------------------------------------------------------------* * 1. Purpose: diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.py b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.py index c0cce28..b777f06 100644 --- a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.py +++ b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.py @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------# -# WFP RAM Standardized Scripts +# WFP APP Standardized Scripts # Reduced Coping Strategies Index (rCSI) Calculation in Python #------------------------------------------------------------------------------# # 1. Purpose: diff --git a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.sps b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.sps index 00337ba..451131e 100644 --- a/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.sps +++ b/Indicators/Reduced-coping-strategy-index/rCSI-indicator-calculation.sps @@ -1,5 +1,5 @@ *------------------------------------------------------------------------------* -* WFP RAM Standardized Scripts +* WFP APP Standardized Scripts * Reduced Coping Strategies Index (rCSI) Calculation in SPSS *------------------------------------------------------------------------------* * 1. Purpose: