These scripts are used to predict if N application is profitable in maize farms in Tanzania. Incorporating soil characteristics, maize price predictions, fertilizer price and distance to markets.
This code is the basis for the analysis in: Palmas S, Chamberlin J (2020) Fertilizer profitability for smallholder maize farmers in Tanzania: A spatially-explicit ex ante analysis. PLoS ONE 15(9):e0239149. https://doi.org/10.1371/journal.pone.0239149
- simulationsYieldModel/simulation_OPnetrev_rf.R: simulation to get an optimized nitrogen application amount for a maximum profitability.
- simulationsYieldModel/simulation_OPyield_rf.R: simulation to get an optimized nitrogen application amount for a maximum yield.
- simulationsYieldModel/simulation_ZERO_BK_rf.R: simulation for no nitrogen and a blanket nitrogen application amount.
- simulationsYieldModel/N_to_netrev.R: Definition of the fitness function to optimize for profitability.
- access.rmd: to estimate time from every pixel to to large cities.
- buildraster.R: function to use when constructing a raster from values in a table.
- fertilizer_price.rmd: simple model to create fertilizer price using city access, a mean fertilizer price and a correction factor depending on transportation costs.
- fertilizer_prof_measures.R: Methods for fertilizer profitability measures such as NUE, AVCR, MVCR.
- fitness.R: Methods for r squared and RMSE.
- maize_price_farmgate.rmd: To estimate maize farmgate prices depending on market prices in several locations and using market access.
- maize_price_market.rmd: Random forest model to predict maize market prices using multiple covariates.
- make_soilprice_table.R: Creates a table from multiple rasters that will be used in the simulation.
- preprocess_rasters.sh: Processes all original elevation, slope, soil, rainfall rasters to a common geometry to use in the analysis. It runs as a bash script in linux.
- rainfall_CV.R: To estimate coefficient of variance of the rainfall in Tanzania.
- Results_TablesFigures.rmd: To create tables and figures for the paper.
- run_simulations.sh:
- TZAPS_hhid_coords_extract.R: to extract covariates from many rasters into a table with the household measurements to use in the yield prediction.
- yield_response.R: Deprecated linear fit model for yield response. Superseded by random forest model.
- yield_response_fit.rmd: To fit a random forest model for yield using multiple covariates.
-
data/hh_summary_stats.csv: Contains all the household variable means used in the simulation.
-
data/models/yield.rf2.rda: Random forest model used in the simulation.