content
stringlengths 0
14.9M
| filename
stringlengths 44
136
|
---|---|
#' Rainfed Upland Rice terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Rainfed Upland Rice.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' \item SlopeD - Slope (degree, 6 classes)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 6 rows and 8 columns
#' @name RICEURTerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/RICEURTerrain.R |
#' Rainfed Upland Rice water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Rainfed Upland Rice.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WmAv1 - Mean precipitation of first month (mm)
#' \item WmAv2 - Mean precipitation of second month (mm)
#' \item WmAv3 - Mean precipitation of third month (mm)
#' \item WmAv4 - Mean precipitation of fourth month (mm)
#' \item WmhAv2 - Relative humidity of devel. Stage (\%)
#' \item WmhAv4 - Relative humidity at harvest stage (\%)
#' \item WynN - Mean annual n/N
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 7 rows and 8 columns
#' @name RICEURWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/RICEURWater.R |
#' Rubber soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Rubber.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CaCO3 - CaCO3 (\%)
#' \item Gyps - Gypsum (\%)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC - Organic carbon (\%)
#' \item ECedS - ECe (dS/m)
#' \item SoilTe - 12 classes of soil texture (Soil Taxonomy)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 10 rows and 8 columns
#' @name RUBBERSoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/RUBBERSoil.R |
#' Rubber temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Rubber.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TyAv - Mean annual temperature (°C)
#' \item TyMaxAv - Mean annual maximum temperature (°C)
#' \item TdMinXm - Mean daily minimum temperature of coldest month (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 3 rows and 8 columns
#' @name RUBBERTemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/RUBBERTemp.R |
#' Rubber terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Rubber.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Flood - Flooding
#' \item Drainage - Drainage
#' \item Slope - nan
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 4 rows and 8 columns
#' @name RUBBERTerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/RUBBERTerrain.R |
#' Rubber water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Rubber.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WyAv - Annual precipitation (mm)
#' \item WmER - Months of excessive rain (x)
#' \item WmDryLen - Length dry season (months : P < 1/2 PET)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 3 rows and 8 columns
#' @name RUBBERWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/RUBBERWater.R |
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
case_a <- function(df, score, suiClass, Min, Max, mfNum, bias, j, a, b, c, l1, l2, l3, l4, l5, sigma) {
.Call('_ALUES_case_a', PACKAGE = 'ALUES', df, score, suiClass, Min, Max, mfNum, bias, j, a, b, c, l1, l2, l3, l4, l5, sigma)
}
case_b <- function(df, score, suiClass, Min, Max, mfNum, bias, j, a, b, c, l1, l2, l3, l4, l5, sigma) {
.Call('_ALUES_case_b', PACKAGE = 'ALUES', df, score, suiClass, Min, Max, mfNum, bias, j, a, b, c, l1, l2, l3, l4, l5, sigma)
}
case_c <- function(df, score, suiClass, Min, Max, Mid, mfNum, bias, j, a, b, c, d, e, f, l1, l2, l3, l4, l5, sigma) {
.Call('_ALUES_case_c', PACKAGE = 'ALUES', df, score, suiClass, Min, Max, Mid, mfNum, bias, j, a, b, c, d, e, f, l1, l2, l3, l4, l5, sigma)
}
case_d <- function(df, score, suiClass, Min, Max, Mid, mfNum, bias, j, a, b, c, d, l1, l2, l3, l4, l5, sigma) {
.Call('_ALUES_case_d', PACKAGE = 'ALUES', df, score, suiClass, Min, Max, Mid, mfNum, bias, j, a, b, c, d, l1, l2, l3, l4, l5, sigma)
}
case_e <- function(df, score, suiClass, Min, Max, Mid, mfNum, bias, j, a, b, c, l1, l2, l3, l4, l5, sigma) {
.Call('_ALUES_case_e', PACKAGE = 'ALUES', df, score, suiClass, Min, Max, Mid, mfNum, bias, j, a, b, c, l1, l2, l3, l4, l5, sigma)
}
| /scratch/gouwar.j/cran-all/cranData/ALUES/R/RcppExports.R |
#' Safflower soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Safflower.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC - Organic carbon (\%)
#' \item ECedS - ECe (dS/m)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 8 rows and 8 columns
#' @name SAFFLOWERSoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SAFFLOWERSoil.R |
#' Safflower temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Safflower.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TmAv1 - Mean temp. of the initial stage( C )
#' \item TmAv2 - Mean temp. crop development stage (2nd month) (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 2 rows and 8 columns
#' @name SAFFLOWERTemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SAFFLOWERTemp.R |
#' Safflower terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Safflower.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 6 rows and 8 columns
#' @name SAFFLOWERTerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SAFFLOWERTerrain.R |
#' Safflower water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Safflower.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WmAv1 - Mean precipitation of first month (mm)
#' \item WmAv2 - Mean precipitation of second month (mm)
#' \item WmAv3 - Mean precipitation of third month (mm)
#' \item WmAv4 - Mean precipitation of fourth month (mm)
#' \item WmhAv3 - Relative humidity of maturation Stage (\%)
#' \item WmhAv4 - Relative humidity at harvest stage (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 6 rows and 8 columns
#' @name SAFFLOWERWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SAFFLOWERWater.R |
#' Sesame soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Sesame.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC - Organic carbon (\%)
#' \item ECedS - ECe (dS/m)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 7 rows and 8 columns
#' @name SESAMESoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SESAMESoil.R |
#' Sesame temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Sesame.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TgAv - Mean temperature of the growing cycle (°C)
#' \item TgMaxAv - Mean max temp. of growing cycle (°C)
#' \item TgMinAv - Mean min. temp. of growing cycle (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 3 rows and 8 columns
#' @name SESAMETemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SESAMETemp.R |
#' Sesame terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Sesame.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 6 rows and 8 columns
#' @name SESAMETerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SESAMETerrain.R |
#' Sesame water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Sesame.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WmAv1 - Mean precipitation of first month (mm)
#' \item WmAv2 - Mean precipitation of second month (mm)
#' \item WmAv3 - Mean precipitation of third month (mm)
#' \item WghAv - Relative humidity growing cycle (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 4 rows and 8 columns
#' @name SESAMEWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SESAMEWater.R |
#' Sorghum soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Sorghum.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CaCO3 - CaCO3 (\%)
#' \item Gyps - Gypsum (\%)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC6 - Organic carbon (\%) - Kaolinitic materials
#' \item OC7 - Organic carbon (\%) - Non Kaolinitic, Non calcareous materials
#' \item ECedS - ECe (dS/m)
#' \item ESP - ESP (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 12 rows and 8 columns
#' @name SORGHUMSoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SORGHUMSoil.R |
#' Sorghum temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Sorghum.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TgAv - Mean temperature of the growing cycle (°C)
#' \item TgMaxAv - Mean max temp. of growing cycle (°C)
#' \item TgMinAv - Mean min. temp. of growing cycle (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 3 rows and 8 columns
#' @name SORGHUMTemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SORGHUMTemp.R |
#' Sorghum terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Sorghum.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 6 rows and 8 columns
#' @name SORGHUMTerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SORGHUMTerrain.R |
#' Sorghum water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Sorghum.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WgAv - Precipitation of growing cycle (mm)
#' \item WmAv4 - Mean precipitation of fourth month (mm)
#' \item WghAv - Relative humidity growing cycle (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 3 rows and 8 columns
#' @name SORGHUMWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SORGHUMWater.R |
#' Soya soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Soya.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CaCO3 - CaCO3 (\%)
#' \item Gyps - Gypsum (\%)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item OC - Organic carbon (\%)
#' \item ECedS - ECe (dS/m)
#' \item ESP - ESP (\%)
#' \item SoilTe - 12 classes of soil texture (Soil Taxonomy)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 11 rows and 8 columns
#' @name SOYASoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SOYASoil.R |
#' Soya temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Soya.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TgAv - Mean temperature of the growing cycle (°C)
#' \item TgMinAv - Mean min. temp. of growing cycle (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 2 rows and 8 columns
#' @name SOYATemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SOYATemp.R |
#' Soya terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Soya.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' \item SlopeD - Slope (degree, 6 classes)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 7 rows and 8 columns
#' @name SOYATerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SOYATerrain.R |
#' Soya water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Soya.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WgAv - Precipitation of growing cycle (mm)
#' \item WmAv1 - Mean precipitation of first month (mm)
#' \item WmAv2 - Mean precipitation of second month (mm)
#' \item WmAv3 - Mean precipitation of third month (mm)
#' \item WmAv4 - Mean precipitation of fourth month (mm)
#' \item WmhAv2 - Relative humidity of devel. Stage (\%)
#' \item WmhAv3 - Relative humidity of maturation Stage (\%)
#' \item WmnN2 - n/N develop. Stage (2nd month)
#' \item WmnN4 - n/N maturation stage (4th month)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 9 rows and 8 columns
#' @name SOYAWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SOYAWater.R |
#' Sugar Cane soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Sugar Cane.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CaCO3 - CaCO3 (\%)
#' \item Gyps - Gypsum (\%)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC6 - Organic carbon (\%) - Kaolinitic materials
#' \item OC7 - Organic carbon (\%) - Non Kaolinitic, Non calcareous materials
#' \item OC8 - Organic carbon (\%) - Calcareous materials
#' \item ECedS - ECe (dS/m)
#' \item ESP - ESP (\%)
#' \item OC - Organic carbon (\%)
#' \item SoilTe - 12 classes of soil texture (Soil Taxonomy)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 15 rows and 8 columns
#' @name SUGARCANESoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SUGARCANESoil.R |
#' Sugar Cane temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Sugar Cane.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TdAvg0 - Mean day temperature at germination stage(°C)
#' \item TdAvg1 - Mean day temperature for tillage stage (°C)
#' \item TdAvg2 - Mean day temperature for vegetative stage (°C)
#' \item Tcoef - (Tmax-Tmin)/Tmean maturation stage
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 4 rows and 8 columns
#' @name SUGARCANETemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SUGARCANETemp.R |
#' Sugar Cane terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Sugar Cane.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' \item SlopeD - Slope (degree, 6 classes)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 7 rows and 8 columns
#' @name SUGARCANETerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SUGARCANETerrain.R |
#' Sugar Cane water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Sugar Cane.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Wd10 - 10 days of rainfall (mm)
#' \item SunH - Sunshine : hours/year
#' \item WynN - Mean annual n/N
#' \item WmhAv3 - Relative humidity of maturation Stage (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 4 rows and 8 columns
#' @name SUGARCANEWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SUGARCANEWater.R |
#' Sunflower soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Sunflower.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CaCO3 - CaCO3 (\%)
#' \item Gyps - Gypsum (\%)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC - Organic carbon (\%)
#' \item ECedS - ECe (dS/m)
#' \item ESP - ESP (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 11 rows and 8 columns
#' @name SUNFLOWERSoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SUNFLOWERSoil.R |
#' Sunflower temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Sunflower.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TgAv - Mean temperature of the growing cycle (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 1 rows and 8 columns
#' @name SUNFLOWERTemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SUNFLOWERTemp.R |
#' Sunflower terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Sunflower.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 6 rows and 8 columns
#' @name SUNFLOWERTerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SUNFLOWERTerrain.R |
#' Sunflower water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Sunflower.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WgAv - Precipitation of growing cycle (mm)
#' \item WmAv1 - Mean precipitation of first month (mm)
#' \item WmAv2 - Mean precipitation of second month (mm)
#' \item WmAv4 - Mean precipitation of fourth month (mm)
#' \item WmAv5 - Mean precipitation of fifth month (mm)
#' \item WghAv - Relative humidity growing cycle (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 6 rows and 8 columns
#' @name SUNFLOWERWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/SUNFLOWERWater.R |
#' Tea soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Tea.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CaCO3 - CaCO3 (\%)
#' \item Gyps - Gypsum (\%)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC - Organic carbon (\%)
#' \item ECedS - ECe (dS/m)
#' \item ESP - ESP (\%)
#' \item SoilTe - 12 classes of soil texture (Soil Taxonomy)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 12 rows and 8 columns
#' @name TEASoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TEASoil.R |
#' Tea temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Tea.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TyAv - Mean annual temperature (°C)
#' \item TmMinAv - Mean min. temp. of warmest month (°C)
#' \item TmMinXm - Avarage minimum temperature of coldest month ( C )
#' \item TmMaxXm - Average max. temp. warmest month (°C)
#' \item TmAv4Xm - Mean temp. of 4 warmest month (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 5 rows and 8 columns
#' @name TEATemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TEATemp.R |
#' Tea terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Tea.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Flood - Flooding
#' \item Drainage - Drainage
#' \item SlopeD - Slope (degree, 6 classes)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 4 rows and 8 columns
#' @name TEATerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TEATerrain.R |
#' Tea water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Tea.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WyAv - Annual precipitation (mm)
#' \item WmDryLen - Length dry season (months : P < 1/2 PET)
#' \item WmDryLen - Length dry season (months : P < 1/2 PET)
#' \item WyhAv - Mean annual rel. humidity (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 4 rows and 8 columns
#' @name TEAWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TEAWater.R |
#' Tobacco soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Tobacco.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CaCO3 - CaCO3 (\%)
#' \item Gyps - Gypsum (\%)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC - Organic carbon (\%)
#' \item ECedS - ECe (dS/m)
#' \item ESP - ESP (\%)
#' \item SoilTe - 12 classes of soil texture (Soil Taxonomy)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 12 rows and 8 columns
#' @name TOBACCOSoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TOBACCOSoil.R |
#' Tobacco temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Tobacco.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TgAv - Mean temperature of the growing cycle (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 1 rows and 8 columns
#' @name TOBACCOTemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TOBACCOTemp.R |
#' Tobacco terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Tobacco.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' \item SlopeD - Slope (degree, 6 classes)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 7 rows and 8 columns
#' @name TOBACCOTerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TOBACCOTerrain.R |
#' Tobacco water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Tobacco.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WgAv - Precipitation of growing cycle (mm)
#' \item WynN - Mean annual n/N
#' \item WghAv - Relative humidity growing cycle (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 3 rows and 8 columns
#' @name TOBACCOWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TOBACCOWater.R |
#' Tomato soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Tomato.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CaCO3 - CaCO3 (\%)
#' \item Gyps - Gypsum (\%)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC - Organic carbon (\%)
#' \item ECedS - ECe (dS/m)
#' \item ESP - ESP (\%)
#' \item SoilTe - 12 classes of soil texture (Soil Taxonomy)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 12 rows and 8 columns
#' @name TOMATOSoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TOMATOSoil.R |
#' Tomato temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Tomato.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TgAv - Mean temperature of the growing cycle (°C)
#' \item TmAv0 - Mean temp. at germination (°C) (1st month)
#' \item TmAv3 - Mean temp. of the flowering stage (°C)
#' \item TdDiff3 - Temp. diff day/night flowering stage (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 4 rows and 8 columns
#' @name TOMATOTemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TOMATOTemp.R |
#' Tomato terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Tomato.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' \item SlopeD - Slope (degree, 6 classes)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 7 rows and 8 columns
#' @name TOMATOTerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TOMATOTerrain.R |
#' Tomato water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Tomato.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WgAv - Precipitation of growing cycle (mm)
#' \item WghAv - Relative humidity growing cycle (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 2 rows and 8 columns
#' @name TOMATOWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/TOMATOWater.R |
#' Watermelon soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Watermelon.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC - Organic carbon (\%)
#' \item ECedS - ECe (dS/m)
#' \item ESP - ESP (\%)
#' \item SoilTe - nan
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 10 rows and 8 columns
#' @name WATERMELONSoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/WATERMELONSoil.R |
#' Watermelon temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Watermelon.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TgAv - Mean temperature of the growing cycle (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 1 rows and 8 columns
#' @name WATERMELONTemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/WATERMELONTemp.R |
#' Watermelon terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Watermelon.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' \item SlopeD - Slope (degree, 6 classes)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 7 rows and 8 columns
#' @name WATERMELONTerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/WATERMELONTerrain.R |
#' Watermelon water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Watermelon.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WgAv - Precipitation of growing cycle (mm)
#' \item WghAv - Relative humidity growing cycle (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 2 rows and 8 columns
#' @name WATERMELONWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/WATERMELONWater.R |
#' Wheat soil requirement for land evaluation
#'
#' A dataset containing the soil characteristics of the crop requirements for farming Wheat.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item CFragm - Coarse fragment (Vol.\%)
#' \item SoilDpt - Soil depth (cm)
#' \item CaCO3 - CaCO3 (\%)
#' \item Gyps - Gypsum (\%)
#' \item CECc - Apparent CEC Clay (cmol (+)/kg clay)
#' \item BS - Base Saturation (\%)
#' \item SumBCs - Sum of basic caions (cmol (+)/kg soil)
#' \item pHH2O - pH H2O
#' \item OC - Organic carbon (\%)
#' \item OC6 - Organic carbon (\%) - Kaolinitic materials
#' \item OC7 - Organic carbon (\%) - Non Kaolinitic, Non calcareous materials
#' \item OC8 - Organic carbon (\%) - Calcareous materials
#' \item ECedS - ECe (dS/m)
#' \item ESP - ESP (\%)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 14 rows and 8 columns
#' @name WHEATSoil
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/WHEATSoil.R |
#' Wheat temp requirement for land evaluation
#'
#' A dataset containing the temp characteristics of the crop requirements for farming Wheat.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item TgAv - Mean temperature of the growing cycle (°C)
#' \item TmAv2 - Mean temp. crop development stage (2nd month) (°C)
#' \item TmAv3 - Mean temp. of the flowering stage (°C)
#' \item TmAv4 - Mean temp. of the ripening stage (°C)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 4 rows and 8 columns
#' @name WHEATTemp
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/WHEATTemp.R |
#' Wheat terrain requirement for land evaluation
#'
#' A dataset containing the terrain characteristics of the crop requirements for farming Wheat.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item Slope1 - Slope (\%) (1. Irrigrated agriculture, basin furrow irrigation)
#' \item Slope2 - Slope (\%) (2. High level of managemnet with full mechanization. )
#' \item Slope3 - Slope (\%) (3. Low level of managemnet animal traction or handwork.)
#' \item Flood - Flooding
#' \item Drainage4 - Drainage (Medium and fine textured soils)
#' \item Drainage5 - Drainage (Coarse textured soils - Sandy families)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 6 rows and 8 columns
#' @name WHEATTerrain
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/WHEATTerrain.R |
#' Wheat water requirement for land evaluation
#'
#' A dataset containing the water characteristics of the crop requirements for farming Wheat.
#'
#' @details
#' The following are the factors for evaluation:
#'
#' \itemize{
#' \item WgAv - Precipitation of growing cycle (mm)
#' \item WmAv2 - Mean precipitation of second month (mm)
#' \item WmAv3 - Mean precipitation of third month (mm)
#' \item WmAv4 - Mean precipitation of fourth month (mm)
#' }
#' @seealso
#' \itemize{
#' \item Yen, B. T., Pheng, K. S., and Hoanh, C. T. (2006). \emph{LUSET: Land Use Suitability Evaluation Tool User's Guide}. International Rice Research Institute.
#' }
#'
#' @docType data
#' @keywords dataset
#' @format A data frame with 4 rows and 8 columns
#' @name WHEATWater
NULL | /scratch/gouwar.j/cran-all/cranData/ALUES/R/WHEATWater.R |
#' Overall Suitability Scores/Class of the Land Units
#' @export
#'
#' @description
#' This function computes the overall suitability scores and class of the land units.
#'
#' @param suit an object of class suitability.
#' @param method a character for the method for computing the overall suitability, choices are:
#' \code{"minimum"}, \code{"maximum"}, and
#' \code{"average"}. If \code{NULL}, method is set to \code{"minimum"}.
#' @param interval if \code{NULL}, the interval of the suitability class are the following: 0\% - 25\% (Not
#' suitable, N), 25\% - 50\% (Marginally Suitable, S3), 50\% - 75\% (Moderately Suitable, S2), and
#' 75\% - 100\% (Highly Suitable, S1). But users can assign custom intervals by specifying
#' the values of the end points of the intervals. Say for intervals: 0\% - 20\% (Not
#' suitable, N), 20\% - 50\% (Marginally Suitable, S3), 50\% - 80\% (Moderately Suitable, S2), and
#' 80\% - 100\% (Highly Suitable, S1), is equivalent to \code{interval = c(0, 0.2, 0.5, 0.8, 1)}.
#'
#' @return
#' A data frame with columns:
#' \itemize{
#' \item \code{Score} - the overall suitability scores
#' \item \code{Class} - the overall suitability classes
#' }
#'
#' @seealso
#' \code{\link{suit}}, \code{https://alstat.github.io/ALUES/}
#'
#' @examples
#' library(ALUES)
#' out <- suit("ricebr", terrain=MarinduqueLT, water=MarinduqueWater, temp=MarinduqueTemp, sow_month=1)
#' out[["terrain"]]
#'
#' # Soil Overall Suitability
#' head(overall_suit(out[["soil"]]))
#' head(overall_suit(out[["soil"]], "average"))
#' head(overall_suit(out[["soil"]], "maximum"))
#' head(overall_suit(out[["soil"]], "average", c(0, 0.3, 0.35, 0.6, 1.0)))
#'
#' # Water Overall Suitability
#' head(overall_suit(out[["water"]], "average"))
#' head(overall_suit(out[["water"]], "maximum"))
#' head(overall_suit(out[["water"]], "average", c(0, 0.3, 0.35, 0.6, 1.0)))
#'
#' # Temperature Overall Suitability
#' head(overall_suit(out[["temp"]], "average"))
#' head(overall_suit(out[["temp"]], "maximum"))
#' head(overall_suit(out[["temp"]], "average", c(0, 0.3, 0.35, 0.6, 1.0)))
overall_suit <- function(suit, method = NULL, interval = NULL) {
if (class(suit) != "suitability")
stop("suit should be an object of class suitability.")
if (ncol(suit[[2L]]) == 1L) {
warning("No overall suitability computed since there is only one factor.")
return(data.frame("Score" = suit[[2L]][,1], "Class" = suit[[3L]][,1]))
}
x <- suit[[2L]]; wts <- suit[[6L]]
if (!is.character(method) && !is.null(method)) {
stop("method should be character, please choose either: 'minimum', 'maximum', 'sum', 'product', 'average'.")
}
if (is.character(interval)) {
stop("interval should be numeric if not NULL.")
}
if (sum(is.na(wts)) != length(wts)) {
wts[is.na(wts)] <- max(wts, na.rm = TRUE) + 1
new_wts <- (sum(wts) - wts)
new_wts <- new_wts/sum(new_wts)
}
if (is.null(method) || method == "minimum") {
suitScore <- apply(x, 1L, function(x) min(as.numeric(x), na.rm = TRUE))
} else if (!is.null(method) && method == "maximum") {
suitScore <- apply(x, 1L, function(x) max(as.numeric(x), na.rm = TRUE))
} else if (!is.null(method) && method == "average") {
if (sum(is.na(wts)) == length(wts)) {
suitScore <- apply(x, 1L, function(x) mean(as.numeric(x), na.rm = TRUE))
} else {
suitScore <- apply(x, 1L, function (x) sum(as.numeric(x) * new_wts, na.rm = TRUE))
}
} else {
stop("method available are 'minimum', 'maximum' and 'average'.")
}
if (is.null(interval)) {
l1 = 0; l2 = 0.25; l3 = 0.5; l4 = 0.75; l5 = 1L;
} else if (is.numeric(interval)) {
if (length(interval) != 5L) {
stop("interval should have 5 limits in ascending order from 0 to 1.")
} else {
if (interval[1] != 0) {
stop("minimum limit should be 0.")
} else if (interval[5] != 1) {
stop("maximum limit should be 1.")
} else {
l1 = interval[1L]; l2 = interval[2L]; l3 = interval[3L]; l4 = interval[4L]; l5 = interval[5L]
}
}
}
sclassFun <- function (x) {
if ((x >= l1) && (x < l2))
return("N")
if ((x >= l2) && (x < l3))
return("S3")
if ((x >= l3) && (x < l4))
return("S2")
if ((x >= l4) && (x <= l5))
return("S1")
}
suitClass <- sapply(suitScore, sclassFun)
return(data.frame("Score" = suitScore, "Class" = suitClass))
} | /scratch/gouwar.j/cran-all/cranData/ALUES/R/overall_suit.R |
#' Suitability Scores/Class of the Land Units
#' @export
#'
#' @description
#' This function calculates the suitability scores and class of the land units.
#'
#' @param crop a string for the name of the crop;
#' @param terrain a data frame for the terrain characteristics of the input land units;
#' @param water a data frame for the water characteristics of the input land units;
#' @param temp a data frame for the temperature characteristics of the input land units;
#' @param mf membership function with default assigned to \code{"triangular"}
#' fuzzy model. Other fuzzy models included are \code{"trapezoidal"} and
#' \code{"gaussian"}.
#' @param sow_month sowing month of the crop. Takes integers from 1 to 12
#' (inclusive), representing the twelve months of the year.
#' So if sets to 1, the function assumes sowing month to be
#' January.
#' @param minimum factor's minimum value. If \code{NULL} (default), \code{minimum} is
#' set to 0. But if numeric of length one, say 0.5, then minimum
#' is set to 0.5, for all factors. To set multiple minimums for multiple factors,
#' simply concatenate these into a numeric vector, the length of this vector should be equal
#' to the number of factors in input land units parameters. However, it can also be set to
#' \code{"average"}, please refer to the online documentation for more, link in the "See Also" section below.
#'
#' @param maximum maximum value for factors. To set multiple maximums for multiple factors,
#' simply concatenate these into a numeric vector, the length of this vector should be equal
#' to the number of factors in input land units parameters. However, it can also be set to
#' \code{"average"}, please refer to the online documentation for more, link in the "See Also" section below.
#'
#' @param interval domains for every suitability class (S1, S2, S3). If fixed (\code{NULL}), the
#' interval would be 0 to 25\% for N (Not Suitable), 25\% to 50\% for S3 (Marginally Suitable),
#' 50\% to 75\% for S2 (Moderately Suitable), and 75\% to 100\% for (Highly Suitable). If \code{"unbias"},
#' the package will take into account the shape of the membership function, and provide the
#' appropriate suitability class intervals. However, it can also be customized by specifying the
#' limits of the suitability classes. Please refer to the online documentation for more, link in the "See Also" section below.
#' @param sigma If \code{mf = "gaussian"}, then sigma represents the constant sigma in the
#' Gaussian formula.
#'
#' @return
#' A list of outputs of target characteristics, with the following components:
#' \itemize{
#' \item \code{"terrain"} - a list of outputs for terrain characteristics
#' \item \code{"soil"} - a list of outputs for soil characteristics
#' \item \code{"water"} - a list of outputs for water characteristics
#' \item \code{"temp"} - a list of outputs for temperature characteristics
#' }
#' These components are only available when specified as the target characteristics in either
#' of the arguments above, that is, if \code{terrain} argument is specified above, then the \code{"terrain"}
#' and \code{"soil"} components will be available in the output list. This is also true if \code{water} and \code{temp}
#' are specified in the arguments above.
#'
#' Each of the components returned above contains a list of outputs as well
#' with the following components:
#' \itemize{
#' \item \code{"Factors Evaluated"} - a character of factors that matched between the input land units factor and the targetted crop requirement factor
#' \item \code{"Suitability Score"} - a data frame of suitability scores for each of the matched factors
#' \item \code{"Suitability Class"} - a data frame of suitability classes for each of the matched factors
#' \item \code{"Factors' Minimum Values"} - a numeric of minimum values used in the membership function for computing the suitability scores
#' \item \code{"Factors' Minimum Values"} - a numeric of maximum values used in the membership function for computing the suitability scores
#' \item \code{"Factors' Weights"} - a numeric of weights of the factors specified in the input crop requirements
#' \item \code{"Crop Evaluated"} - a character of the name of the targetted crop requirement dataset
#' }
#'
#' @seealso
#' \code{https://alstat.github.io/ALUES/}
#'
#' @examples
#' library(ALUES)
#'
#' rice_suit <- suit("ricebr", water=MarinduqueWater, temp=MarinduqueTemp, sow_month = 1)
#' lapply(rice_suit[["water"]], function(x) head(x)) # access results for water suitability
#' lapply(rice_suit[["temp"]], function(x) head(x)) # access results for temperature suitability
#' rice_suit <- suit("ricebr", terrain=MarinduqueLT)
#' lapply(rice_suit[["terrain"]], function(x) head(x))
#' lapply(rice_suit[["soil"]], function(x) head(x))
suit <- function (crop, terrain=NULL, water=NULL, temp=NULL, mf = "triangular", sow_month = NULL, minimum = NULL, maximum = "average", interval = NULL, sigma = NULL) {
if (is.null(terrain) && is.null(water) && is.null(temp)) {
stop("Please specify at least one land characteristics: terrain, water, or temp.")
}
if (!is.character(crop) && is.data.frame(crop)) {
if (!is.null(terrain)) {
suit_terrain <- tryCatch({
suit_terrain <- suitability(terrain, crop, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- "Custom Crop for Terrain"
suit_terrain
},
warning=function(w) {
suit_terrain <- suitability(terrain, crop, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- "Custom Crop for Terrain"
suit_terrain[["Warning"]] <- w$message
suit_terrain
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("terrain" = suit_terrain))
} else if (!is.null(water)) {
suit_water <- tryCatch({
suit_water <- suitability(water, crop, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- "Custom Crop for Water"
suit_water
},
warning=function(w) {
suit_water <- suitability(water, crop, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- "Custom Crop for Water"
suit_water[["Warning"]] <- w$message
suit_water
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("water" = suit_water))
} else if (!is.null(temp)) {
suit_temp <- tryCatch({
suit_temp <- suitability(temp, crop, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- "Custom Crop for Temperature"
suit_temp
},
warning=function(w) {
suit_temp <- suitability(temp, crop, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- "Custom Crop for Temperature"
suit_temp[["Warning"]] <- w$message
suit_temp
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("temp" = suit_temp))
}
} else if (is.character(crop)) {
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
if (toupper(crop) %in% crop_data) {
crop <- toupper(crop)
} else {
if (crop == "rice") {
warning("Defaulting to 'ricebr', other options for rice: 'riceiw', 'ricenf', and 'riceur'. Specify accordingly.")
crop <- toupper("ricebr")
} else if (crop == "coffee") {
warning("Defaulting to 'coffeear', other options for coffee: 'coffeero'. Specify accordingly.")
crop <- toupper("coffeear")
} else {
stop(paste("Input crop='", crop, "' is not available in the database, see docs for list of ALUES data.", sep=""))
}
}
if (!is.null(terrain) && !is.null(water) && !is.null(temp)) {
if (is.null(sow_month)) {
stop("Please specify sowing month to match the corresponding factors in input land units.")
}
crop_terrain <- eval(parse(text=paste(crop, "Terrain", sep="")), envir=.GlobalEnv)
crop_soil <- eval(parse(text=paste(crop, "Soil", sep="")), envir=.GlobalEnv)
crop_water <- eval(parse(text=paste(crop, "Water", sep="")), envir=.GlobalEnv)
crop_temp <- eval(parse(text=paste(crop, "Temp", sep="")), envir=.GlobalEnv)
suit_terrain <- tryCatch(
{
suit_terrain <- suitability(terrain, crop_terrain, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- paste(crop, "Terrain", sep="")
suit_terrain
},
warning=function(w) {
suit_terrain <- suitability(terrain, crop_terrain, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- paste(crop, "Terrain", sep="")
suit_terrain[["Warning"]] <- w$message
suit_terrain
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
suit_soil <- tryCatch(
{
suit_soil <- suitability(terrain, crop_soil, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_soil[["Crop Evaluated"]] <- paste(crop, "Soil", sep="")
suit_soil
},
warning=function(w) {
suit_soil <- suitability(terrain, crop_soil, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_soil[["Crop Evaluated"]] <- paste(crop, "Soil", sep="")
suit_soil[["Warning"]] <- w$message
suit_soil
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
suit_water <- tryCatch(
{
suit_water <- suitability(water, crop_water, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- paste(crop, "Water", sep="")
suit_water
},
warning=function(w) {
suit_water <- suitability(water, crop_water, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- paste(crop, "Water", sep="")
suit_water[["Warning"]] <- w$message
suit_water
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
suit_temp <- tryCatch(
{
suit_temp <- suitability(temp, crop_temp, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- paste(crop, "Temp", sep="")
suit_temp
},
warning=function(w) {
suit_temp <- suitability(temp, crop_temp, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- paste(crop, "Temp", sep="")
suit_temp[["Warning"]] <- w$message
suit_temp
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("terrain" = suit_terrain, "soil" = suit_soil, "water" = suit_water, "temp" = suit_temp))
} else if (!is.null(terrain) && !is.null(water)) {
if (is.null(sow_month)) {
stop("Please specify sowing month to match the corresponding factors in input land units.")
}
crop_terrain <- eval(parse(text=paste(crop, "Terrain", sep="")), envir=.GlobalEnv)
crop_soil <- eval(parse(text=paste(crop, "Soil", sep="")), envir=.GlobalEnv)
crop_water <- eval(parse(text=paste(crop, "Water", sep="")), envir=.GlobalEnv)
suit_terrain <- tryCatch(
{
suit_terrain <- suitability(terrain, crop_terrain, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- paste(crop, "Terrain", sep="")
suit_terrain
},
warning=function(w) {
suit_terrain <- suitability(terrain, crop_terrain, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- paste(crop, "Terrain", sep="")
suit_terrain[["Warning"]] <- w$message
suit_terrain
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
suit_soil <- tryCatch(
{
suit_soil <- suitability(terrain, crop_soil, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_soil[["Crop Evaluated"]] <- paste(crop, "Soil", sep="")
suit_soil
},
warning=function(w) {
suit_soil <- suitability(terrain, crop_soil, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_soil[["Crop Evaluated"]] <- paste(crop, "Soil", sep="")
suit_soil[["Warning"]] <- w$message
suit_soil
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
suit_water <- tryCatch(
{
suit_water <- suitability(water, crop_water, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- paste(crop, "Water", sep="")
suit_water
},
warning=function(w) {
suit_water <- suitability(water, crop_water, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- paste(crop, "Water", sep="")
suit_water[["Warning"]] <- w$message
suit_water
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("terrain" = suit_terrain, "soil" = suit_soil, "water" = suit_water))
} else if (!is.null(terrain) && !is.null(temp)) {
if (is.null(sow_month)) {
stop("Please specify sowing month to match the corresponding factors in input land units.")
}
crop_terrain <- eval(parse(text=paste(crop, "Terrain", sep="")), envir=.GlobalEnv)
crop_soil <- eval(parse(text=paste(crop, "Soil", sep="")), envir=.GlobalEnv)
crop_temp <- eval(parse(text=paste(crop, "Temp", sep="")), envir=.GlobalEnv)
suit_terrain <- tryCatch(
{
suit_terrain <- suitability(terrain, crop_terrain, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- paste(crop, "Terrain", sep="")
suit_terrain
},
warning=function(w) {
suit_terrain <- suitability(terrain, crop_terrain, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- paste(crop, "Terrain", sep="")
suit_terrain[["Warning"]] <- w$message
suit_terrain
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
suit_soil <- tryCatch(
{
suit_soil <- suitability(terrain, crop_soil, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_soil[["Crop Evaluated"]] <- paste(crop, "Soil", sep="")
suit_soil
},
warning=function(w) {
suit_soil <- suitability(terrain, crop_soil, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_soil[["Crop Evaluated"]] <- paste(crop, "Soil", sep="")
suit_soil[["Warning"]] <- w$message
suit_soil
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
suit_temp <- tryCatch(
{
suit_temp <- suitability(temp, crop_temp, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- paste(crop, "Temp", sep="")
suit_temp
},
warning=function(w) {
suit_temp <- suitability(temp, crop_temp, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- paste(crop, "Temp", sep="")
suit_temp[["Warning"]] <- w$message
suit_temp
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("terrain" = suit_terrain, "soil" = suit_soil, "temp" = suit_temp))
} else if (!is.null(water) && !is.null(temp)) {
if (is.null(sow_month)) {
stop("Please specify sowing month to match the corresponding factors in input land units.")
}
crop_water <- eval(parse(text=paste(crop, "Water", sep="")), envir=.GlobalEnv)
suit_water <- tryCatch(
{
suit_water <- suitability(water, crop_water, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- paste(crop, "Water", sep="")
suit_water
},
warning=function(w) {
suit_water <- suitability(water, crop_water, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- paste(crop, "Water", sep="")
suit_water[["Warning"]] <- w$message
suit_water
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
crop_temp <- eval(parse(text=paste(crop, "Temp", sep="")), envir=.GlobalEnv)
suit_temp <- tryCatch(
{
suit_temp <- suitability(temp, crop_temp, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- paste(crop, "Temp", sep="")
suit_temp
},
warning=function(w) {
suit_temp <- suitability(temp, crop_temp, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- paste(crop, "Temp", sep="")
suit_temp[["Warning"]] <- w$message
suit_temp
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("water" = suit_water, "temp" = suit_temp))
} else if (!is.null(terrain)) {
crop_terrain <- eval(parse(text=paste(crop, "Terrain", sep="")), envir=.GlobalEnv)
crop_soil <- eval(parse(text=paste(crop, "Soil", sep="")), envir=.GlobalEnv)
suit_terrain <- tryCatch(
{
suit_terrain <- suitability(terrain, crop_terrain, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- paste(crop, "Terrain", sep="")
suit_terrain
},
warning=function(w) {
suit_terrain <- suitability(terrain, crop_terrain, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_terrain[["Crop Evaluated"]] <- paste(crop, "Terrain", sep="")
suit_terrain[["Warning"]] <- w$message
suit_terrain
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
suit_soil <- tryCatch(
{
suit_soil <- suitability(terrain, crop_soil, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_soil[["Crop Evaluated"]] <- paste(crop, "Soil", sep="")
suit_soil
},
warning=function(w) {
suit_soil <- suitability(terrain, crop_soil, mf=mf, sow_month=NULL, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_soil[["Crop Evaluated"]] <- paste(crop, "Soil", sep="")
suit_soil[["Warning"]] <- w$message
suit_soil
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("terrain" = suit_terrain, "soil" = suit_soil))
} else if (!is.null(water)) {
if (is.null(sow_month)) {
stop("Please specify sowing month to match the corresponding factors in input land units.")
}
crop_water <- eval(parse(text=paste(crop, "Water", sep="")), envir=.GlobalEnv)
suit_water <- tryCatch(
{
suit_water <- suitability(water, crop_water, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- paste(crop, "Water", sep="")
suit_water
},
warning=function(w) {
suit_water <- suitability(water, crop_water, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_water[["Crop Evaluated"]] <- paste(crop, "Water", sep="")
suit_water[["Warning"]] <- w$message
suit_water
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("water" = suit_water))
} else if (!is.null(temp)) {
if (is.null(sow_month)) {
stop("Please specify sowing month to match the corresponding factors in input land units.")
}
crop_temp <- eval(parse(text=paste(crop, "Temp", sep="")), envir=.GlobalEnv)
suit_temp <- tryCatch(
{
suit_temp <- suitability(temp, crop_temp, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- paste(crop, "Temp", sep="")
suit_temp
},
warning=function(w) {
suit_temp <- suitability(temp, crop_temp, mf=mf, sow_month=sow_month, minimum=minimum, maximum=maximum, interval=interval, sigma=sigma)
suit_temp[["Crop Evaluated"]] <- paste(crop, "Temp", sep="")
suit_temp[["Warning"]] <- w$message
suit_temp
},
error = function(x) {
return(paste("Error: ", x$message, sep=""))
}
)
return(list("temp" = suit_temp))
}
}
}
| /scratch/gouwar.j/cran-all/cranData/ALUES/R/suit.R |
#' Suitability Scores/Class of the Land Units
#'
#' @description
#' This function calculates the suitability scores and class of the land units.
#'
#' @param x a data frame consisting the properties of the land units;
#' @param y a data frame consisting the requirements of a given
#' characteristics (terrain, soil, water and temperature) for a
#' given crop (e.g. coconut, cassava, etc.);
#' @param mf membership function with default assigned to \code{"triangular"}
#' fuzzy model. Other fuzzy models included are \code{"trapezoidal"} and
#' \code{"gaussian"}.
#' @param sow_month sowing month of the crop. Takes integers from 1 to 12
#' (inclusive), representing the twelve months of the year.
#' So if sets to 1, the function assumes sowing month to be
#' January.
#' @param minimum factor's minimum value. If \code{NULL} (default), \code{minimum} is
#' set to 0. But if numeric of length one, say 0.5, then minimum
#' is set to 0.5, for all factors. To set multiple minimums for multiple factors,
#' simply concatenate these into a numeric vector, the length of this vector should be equal
#' to the number of factors in input land units parameters. However, it can also be set to
#' \code{"average"}, please refer to the online documentation for more, link in the "See Also" section below.
#'
#' @param maximum maximum value for factors. To set multiple maximums for multiple factors,
#' simply concatenate these into a numeric vector, the length of this vector should be equal
#' to the number of factors in input land units parameters. However, it can also be set to
#' \code{"average"}, please refer to the online documentation for more, link in the "See Also" section below.
#'
#' @param interval domains for every suitability class (S1, S2, S3). If fixed (\code{NULL}), the
#' interval would be 0 to 25\% for N (Not Suitable), 25\% to 50\% for S3 (Marginally Suitable),
#' 50\% to 75\% for S2 (Moderately Suitable), and 75\% to 100\% for (Highly Suitable). If \code{"unbias"},
#' the package will take into account the shape of the membership function, and provide the
#' appropriate suitability class intervals. However, it can also be customized by specifying the
#' limits of the suitability classes. Please refer to the online documentation for more, link in the "See Also" section below.
#' @param sigma If \code{mf = "gaussian"}, then sigma represents the constant sigma in the
#' Gaussian formula.
#'
#' @return
#' A list with the following components:
#' \itemize{
#' \item \code{"Factors Evaluated"} - a character of factors that matched between the input land units factor and the targetted crop requirement factor
#' \item \code{"Suitability Score"} - a data frame of suitability scores for each of the matched factors
#' \item \code{"Suitability Class"} - a data frame of suitability classes for each of the matched factors
#' \item \code{"Factors' Minimum Values"} - a numeric of minimum values used in the membership function for computing the suitability scores
#' \item \code{"Factors' Minimum Values"} - a numeric of maximum values used in the membership function for computing the suitability scores
#' \item \code{"Factors' Weights"} - a numeric of weights of the factors specified in the input crop requirements
#' \item \code{"Crop Evaluated"} - a character of the name of the targetted crop requirement dataset
#' }
#'
#' #' @seealso
#' \code{https://alstat.github.io/ALUES/}
#'
suitability <- function (x, y, mf = "triangular", sow_month = NULL, minimum = NULL, maximum = "average", interval = NULL, sigma = NULL) {
n1 <- length(names(x))
n2 <- nrow(y)
f1 <- f2 <- numeric()
if (is.numeric(sow_month)) {
f3 <- f4 <- typ <- numeric()
month <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
wmav <- c("WmAv1", "WmAv2", "WmAv3",
"WmAv4", "WmAv5", "WmAv6")
tmav <- c("TmAv1", "TmAv2", "TmAv3",
"TmAv4", "TmAv5", "TmAv6")
for (i in 1:nrow(y)) {
for (j in 1:length(wmav)) {
if (as.character(y[i, 1]) == wmav[j]) {
f3[i] <- j; f4[i] <- i; typ <- 0
} else if (as.character(y[i, 1]) == tmav[j]) {
f3[i] <- j; f4[i] <- i; typ <- 1
} else {
if (j < length(wmav)) {
next
} else {
if (i < nrow(y)) {
break
} else {
if (length(f3) == 0 && length(f4) == 0) {
stop("No factor(s) to be evaluated, since none matches with the crop requirements.")
} else {
break
}
}
}
}
}
}
f3 <- f3[stats::complete.cases(f3)]
if (typ == 0) {
idx <- as.numeric(unlist(strsplit(wmav[f3], "WmAv"))[2])
} else {
idx <- as.numeric(unlist(strsplit(tmav[f3], "TmAv"))[2])
}
if (idx > 1) {
sow_month <- month[sow_month + idx - 1]
} else {
sow_month <- month[sow_month]
}
y <- as.matrix(y)
for (i in 1:12) {
if (sow_month == month[i]) {
if ((i + length(f3) - 1) > 12) {
if (typ == 0) {
y[y[,1] %in% wmav[f3], 1] <- c(rev(rev(month)[1:(length(f3) - ((i + length(f3) - 1) - 12))]), month[1:((i + length(f3) - 1) - 12)])
} else {
y[y[,1] %in% tmav[f3], 1] <- c(rev(rev(month)[1:(length(f3) - ((i + length(f3) - 1) - 12))]), month[1:((i + length(f3) - 1) - 12)])
}
} else {
if (typ == 0) {
y[y[,1] %in% wmav[f3], 1] <- month[i:(i + length(f3) - 1)]
} else {
y[y[,1] %in% tmav[f3], 1] <- month[i:(i + length(f3) - 1)]
}
}
}
}
y <- as.data.frame(y)
}
# extract intersecting parameters between x and y
for (i in 1:n2) {
for (j in 1:n1) {
if (as.character(y[i, 1]) == names(x)[j]) {
f1[i] <- j; f2[i] <- i
}
}
}
# update x and y to only intersecting parameters
LU <- as.matrix(x[, f1[stats::complete.cases(f1)]])
CR <- as.matrix(y[f2[stats::complete.cases(f1)], ])
colnames(LU) <- names(x)[f1[stats::complete.cases(f1)]]
if (ncol(LU) == 0) {
stop("No factor(s) to be evaluated, since none matches with the crop requirements. If water or temp characteristics was specified then maybe you forgot to specify the sow_month argument, read doc for suit.")
}
# define empty matrix for score and class
score <- matrix(NA, nrow = nrow(LU), ncol = ncol(LU))
suiClass <- matrix(character(), nrow = nrow(LU), ncol = ncol(LU))
colnames(score) <- colnames(LU)
colnames(suiClass) <- colnames(LU)
k <- 1
if (is.null(interval)) {
l1 = 0; l2 = 0.25; l3 = 0.5; l4 = 0.75; l5 = 1; bias <- 0
} else if (is.numeric(interval) && !is.null(interval)) {
if (length(interval) != 5) {
stop("interval should have 5 limits, run ?suit for more.")
} else {
l1 = interval[1]; l2 = interval[2]; l3 = interval[3]; l4 = interval[4]; l5 = interval[5]; bias <- 0
}
} else if (!is.null(interval) && interval == "unbias") {
l1 = l2 = l3 = l4 = l5 = NA
bias <- 1
}
if (mf == "triangular") {
mfNum <- 1
} else if (mf == "trapezoidal") {
mfNum <- 2
} else if (mf == "gaussian") {
mfNum <- 3
} else {
stop(paste("Unrecognized mf='", mf, "', please choose either 'triangular', 'trapezoidal' or 'gaussian'.", sep=""))
}
if (is.null(sigma)) {
sigma <- 1
} else if (is.numeric(sigma)) {
if (mf != "gaussian") {
warning("sigma is only use for gaussian membership function. It defines the spread of the gaussian model.")
} else {
sigma <- sigma
}
}
minVals <- maxVals <- numeric()
for(j in 1:ncol(LU)){
rScore <- rev(as.numeric(CR[k, -1][1:6]))
reqScore <- rev(rScore[stats::complete.cases(rScore)])
n3 <- length(reqScore)
# if parameter has no entry, skip
if (n3 == 0) {
k <- k + 1
next
}
if (n3 == 3) {
if (reqScore[1] > reqScore[3]) {
reqScore <- rev(reqScore)
if ((!is.null(minimum)) && (minimum == "average")) {
Min <- reqScore[1] - ((diff(reqScore[1:2]) + diff(reqScore[2:3])) / 2)
} else if (is.numeric(minimum)){
if (length(minimum) == 1) {
Min <- minimum
} else if (length(minimum) > 1) {
if (length(minimum) == ncol(x)) {
Min <- minimum[f1[stats::complete.cases(f1)][j]]
} else if (length(minimum) != ncol(x)) {
stop("minimum length should be equal to the number of factors in x.")
}
}
} else if (is.null(minimum)) {
Min <- 0
}
if (!is.numeric(maximum)) {
if (maximum == "average") {
Max <- reqScore[3] + ((diff(reqScore[1:2]) + diff(reqScore[2:3])) / 2)
} else {
stop(paste("Cannot identify maximum='", maximum, "'. maximum can only take 'average' or numeric vector of maximum.", sep=""))
}
} else if (is.numeric(maximum)) {
if (length(maximum) == 1) {
Max <- maximum
} else if (length(maximum) > 1) {
if (length(maximum) == ncol(x)) {
Max <- maximum[f1[stats::complete.cases(f1)][j]]
} else if (length(maximum) != ncol(x)) {
stop("maximum length should be equal to the number of factors in the input land units.")
}
}
}
output <- case_a(df = as.matrix(LU), score = score, suiClass = suiClass, Min = Min, Max = Max, mfNum = mfNum,
bias = bias, j = j, a = reqScore[1], b = reqScore[2], c = reqScore[3], l1 = l1, l2 = l2, l3 = l3, l4 = l4, l5 = l5, sigma = sigma)
score <- output[[1]]; suiClass <- output[[2]]
} else if (reqScore[1] < reqScore[3]) {
if ((!is.null(minimum)) && (minimum == "average")) {
Min <- reqScore[1] - ((diff(reqScore[1:2]) + diff(reqScore[2:3])) / 2)
} else if (is.numeric(minimum)) {
if (length(minimum) == 1) {
Min <- minimum
} else if (length(minimum) > 1) {
if (length(minimum) == ncol(x)) {
Min <- minimum[f1[stats::complete.cases(f1)][j]]
} else if (length(minimum) != ncol(x)) {
stop("minimum length should be equal to the number of factors in x.")
}
}
} else if (is.null(minimum)) {
Min <- 0
}
if (!is.numeric(maximum)) {
if (maximum == "average") {
Max <- reqScore[3] + ((diff(reqScore[1:2]) + diff(reqScore[2:3])) / 2)
} else {
stop(paste("Cannot identify maximum='", maximum, "'. maximum can only take 'average' or numeric vector of maximum.", sep=""))
}
} else if (is.numeric(maximum)) {
if (length(maximum) == 1) {
Max <- maximum
} else if (length(maximum) > 1) {
if (length(maximum) == ncol(x)) {
Max <- maximum[f1[stats::complete.cases(f1)][j]]
} else if (length(maximum) != ncol(x)) {
stop("maximum length should be equal to the number of factors in x.")
}
}
}
output <- case_b(df = as.matrix(LU), score = score, suiClass = suiClass, Min = Min, Max = Max, mfNum = mfNum,
bias = bias, j = j, a = reqScore[1], b = reqScore[2], c = reqScore[3], l1 = l1, l2 = l2, l3 = l3, l4 = l4, l5 = l5, sigma = sigma)
score <- output[[1]]; suiClass <- output[[2]]
} else if ((reqScore[1] == reqScore[2]) &&
(reqScore[1] == reqScore[3]) &&
(reqScore[2] == reqScore[3])) {
if ((!is.null(minimum)) && (minimum == "average")) {
Min <- 0
warning(paste("minimum is set to zero for factor", colnames(score)[j],
"since all suitability class intervals are equal."))
} else if (is.numeric(minimum)) {
if (length(minimum) == 1) {
Min <- minimum
} else if (length(minimum) > 1) {
if (length(minimum) == ncol(x)) {
Min <- minimum[f1[stats::complete.cases(f1)][j]]
} else if (length(minimum) != ncol(x)) {
stop("minimum length should be equal to the number of factors in x.")
}
}
} else if (is.null(minimum)) {
Min <- 0
}
Max <- reqScore[3]
if (!is.numeric(maximum)) {
if (maximum == "average") {
Max <- reqScore[3]
warning(paste("maximum is set to", reqScore[3], "for factor", colnames(score)[j],
"since all parameter intervals are equal."))
} else {
stop(paste("Cannot identify maximum='", maximum, "'. maximum can only take 'average' or numeric vector of maximum.", sep=""))
}
} else if (is.numeric(maximum)) {
if (length(maximum) == 1) {
Max <- maximum
} else if (length(maximum) > 1) {
if (length(maximum) == ncol(x)) {
Max <- maximum[f1[stats::complete.cases(f1)][j]]
} else if (length(maximum) != ncol(x)) {
stop("maximum length should be equal to the number of factors in x.")
}
}
}
output <- case_b(df = as.matrix(LU), score = score, suiClass = suiClass, Min = Min, Max = Max, mfNum = mfNum,
bias = bias, j = j, a = reqScore[1], b = reqScore[2], c = reqScore[3], l1 = l1, l2 = l2, l3 = l3, l4 = l4, l5 = l5, sigma = sigma)
score <- output[[1]]; suiClass <- output[[2]]
}
} else if (n3 == 6) {
if ((!is.null(minimum)) && (minimum == "average")) {
Min <- reqScore[1] - ((diff(reqScore[1:2]) + diff(reqScore[2:3]) + diff(reqScore[3:4]) + diff(reqScore[4:5]) + diff(reqScore[5:6])) / 5)
} else if (is.numeric(minimum)){
if (length(minimum) == 1) {
Min <- minimum
} else if (length(minimum) > 1) {
if (length(minimum) == ncol(x)) {
Min <- minimum[f1[stats::complete.cases(f1)][j]]
} else if (length(minimum) != ncol(x)) {
stop("minimum length should be equal to the number of factors in x.")
}
}
} else if (is.null(minimum)) {
Min <- 0
}
Mid <- mean(reqScore[3:4])
if (!is.numeric(maximum)) {
if (maximum == "average") {
Max <- reqScore[6] + ((diff(reqScore[1:2]) + diff(reqScore[2:3]) + diff(reqScore[3:4]) + diff(reqScore[4:5]) + diff(reqScore[5:6])) / 5)
} else {
stop(paste("Cannot identify maximum='", maximum, "'. maximum can only take 'average' or numeric vector of maximum.", sep=""))
}
} else if (is.numeric(maximum)) {
if (length(maximum) == 1) {
Max <- maximum
} else if (length(maximum) > 1) {
if (length(maximum) == ncol(x)) {
Max <- maximum[f1[stats::complete.cases(f1)][j]]
} else if (length(maximum) != ncol(x)) {
stop("maximum length should be equal to the number of factors in x.")
}
}
}
output <- case_c(df = as.matrix(LU), score = score, suiClass = suiClass, Min = Min, Max = Max, Mid = Mid, mfNum = mfNum,
bias = bias, j = j, a = reqScore[1], b = reqScore[2], c = reqScore[3], d = reqScore[4], e = reqScore[5], f = reqScore[6],
l1 = l1, l2 = l2, l3 = l3, l4 = l4, l5 = l5, sigma = sigma)
score <- output[[1]]; suiClass <- output[[2]]
} else if (n3 == 5) {
if ((!is.null(minimum)) && (minimum == "average")) {
Min <- reqScore[1] - ((diff(reqScore[1:2]) + diff(reqScore[2:3]) + diff(reqScore[3:4]) + diff(reqScore[4:5])) / 4)
} else if (is.numeric(minimum)) {
if (length(minimum) == 1) {
Min <- minimum
} else if (length(minimum) > 1) {
if (length(minimum) == ncol(x)) {
Min <- minimum[f1[stats::complete.cases(f1)][j]]
} else if (length(minimum) != ncol(x)) {
stop("minimum length should be equal to the number of factors in x.")
}
}
} else if (is.null(minimum)) {
Min <- 0
}
Mid <- mean(reqScore[3:4])
if (!is.numeric(maximum)) {
if (maximum == "average") {
Max <- reqScore[5]
warning(paste("maximum is set to", reqScore[5], "for factor", colnames(score)[j],
"since there is a missing value on S3 class above optimum, run ?suit for more."))
} else {
stop(paste("Cannot identify maximum='", maximum, "'. maximum can only take 'average' or numeric vector of maximum.", sep=""))
}
} else if (is.numeric(maximum)) {
if (length(maximum) == 1) {
Max <- reqScore[5]
warning(paste("maximum is set to", reqScore[5], "for factor", colnames(score)[j],
"since there is a missing value on S3 class above optimum, run ?suit for more."))
} else if (length(maximum) > 1) {
if (length(maximum) == ncol(x)) {
Max <- reqScore[5]
warning(paste("maximum is set to", reqScore[5], "for factor", colnames(score)[j],
"since there is a missing value on S3 class above optimum, run ?suit for more."))
}
else if (length(maximum) != ncol(x)) {
stop("maximum length should be equal to the number of factors in x.")
}
}
}
output <- case_d(df = as.matrix(LU), score = score, suiClass = suiClass, Min = Min, Max = Max, Mid = Mid, mfNum = mfNum,
bias = bias, j = j, a = reqScore[1], b = reqScore[2], c = reqScore[3], d = reqScore[4], l1 = l1, l2 = l2, l3 = l3, l4 = l4, l5 = l5, sigma = sigma)
score <- output[[1]]; suiClass <- output[[2]]
} else if (n3 == 4) {
if ((!is.null(minimum)) && (minimum == "average")) {
Min <- reqScore[1] - ((diff(reqScore[1:2]) + diff(reqScore[2:3]) + diff(reqScore[3:4])) / 3)
} else if (is.numeric(minimum)){
if (length(minimum) == 1) {
Min <- minimum
} else if (length(minimum) > 1) {
if (length(minimum) == ncol(x)) {
Min <- minimum[f1[stats::complete.cases(f1)][j]]
} else if (length(minimum) != ncol(x)) {
stop("minimum length should be equal to the number of factors in x.")
}
}
} else if (is.null(minimum)) {
Min <- 0
}
Mid <- mean(reqScore[3:4])
if (!is.numeric(maximum)) {
if (maximum == "average") {
Max <- reqScore[4]
warning(paste("maximum is set to", reqScore[4], "for factor", colnames(score)[j],
"since there is a missing value on S2 class above optimum, run ?suit for more."))
} else {
stop(paste("Cannot identify maximum='", maximum, "'. maximum can only take 'average' or numeric vector of maximum.", sep=""))
}
} else if (is.numeric(maximum)) {
if (length(maximum) == 1) {
Max <- reqScore[4]
warning(paste("maximum is set to", reqScore[4], "for factor", colnames(score)[j],
"since there is a missing value on S2 class above optimum, run ?suit for more."))
}
else if (length(maximum) > 1) {
if (length(maximum) == ncol(x)) {
Max <- reqScore[4]
warning(paste("maximum is set to", reqScore[4], "for factor", colnames(score)[j],
"since there is a missing value on S2 class above optimum, run ?suit for more."))
}
else if (length(maximum) != ncol(x))
stop("maximum length should be equal to the number of factors in x.")
}
}
output <- case_e(df = as.matrix(LU), score = score, suiClass = suiClass, Min = Min, Max = Max, Mid = Mid, mfNum = mfNum,
bias = bias, j = j, a = reqScore[1], b = reqScore[2], c = reqScore[3], l1 = l1, l2 = l2, l3 = l3, l4 = l4, l5 = l5, sigma = sigma)
score <- output[[1]]; suiClass <- output[[2]]
}
k <- k + 1
minVals[j] <- Min; maxVals[j] <- Max
}
names(minVals) <- names(maxVals) <- names(x)[f1[stats::complete.cases(f1)]]
outf <- list("Factors Evaluated" = names(minVals),
"Suitability Score" = as.data.frame(score),
"Suitability Class" = as.data.frame(suiClass),
"Factors' Minimum Values" = minVals,
"Factors' Maximum Values" = maxVals,
"Factors' Weights" = as.numeric(CR[, 8L]))
class(outf) <- "suitability"
return(outf)
} | /scratch/gouwar.j/cran-all/cranData/ALUES/R/suitability.R |
## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
## -----------------------------------------------------------------------------
library(ALUES)
suit_banana <- suit("banana", terrain=MarinduqueLT)
head(suit_banana[["soil"]]$`Suitability Score`)
head(suit_banana[["soil"]]$`Suitability Class`)
## -----------------------------------------------------------------------------
osuit <- overall_suit(suit_banana[["soil"]], method="average")
head(osuit)
## -----------------------------------------------------------------------------
library(microbenchmark)
microbenchmark(
suppressWarnings(suit("banana", terrain=MarinduqueLT, interval="unbias"))
)
microbenchmark(
suppressWarnings(suit("banana", terrain=LaoCaiLT, interval="unbias"))
)
| /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/ALUES.R |
---
title: "Getting Started"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Getting Started}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Show me the code
To evaluate the soil characteristics of the land units of Marinduque, Philippines, for farming banana, use the `suit` function as follows:
```{r}
library(ALUES)
suit_banana <- suit("banana", terrain=MarinduqueLT)
head(suit_banana[["soil"]]$`Suitability Score`)
head(suit_banana[["soil"]]$`Suitability Class`)
```
To compute the overall suitability of the land units by averaging across factors, use the `overall_suit` as follows:
```{r}
osuit <- overall_suit(suit_banana[["soil"]], method="average")
head(osuit)
```
## Show me the speed
The elapsed time for computing the suitability scores and classes were recorded for the land units of Marinduque, which has 881 units (or observations) in total; and, for the region of Lao Cai, Vietnam, which has 2928 land units.
```{r}
library(microbenchmark)
microbenchmark(
suppressWarnings(suit("banana", terrain=MarinduqueLT, interval="unbias"))
)
microbenchmark(
suppressWarnings(suit("banana", terrain=LaoCaiLT, interval="unbias"))
)
``` | /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/ALUES.Rmd |
## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
## -----------------------------------------------------------------------------
library(ALUES)
head(MarinduqueLT)
head(LaoCaiLT)
## -----------------------------------------------------------------------------
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
crop_data
## -----------------------------------------------------------------------------
GUAVASoil
GUAVATemp
CINNAMONTerrain
CINNAMONWater
| /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a01_datasets.R |
---
title: "Article 1: ALUES datasets"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 1: ALUES datasets}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
There are two categories of datasets available in ALUES, *land units* and *crop requirements*.
## Input Land Units
The *land units* datasets are input land units with properties meant for evaluation for crop production. Two regions are available for these datasets: *Marinduque, Philippines*; and, *Lao Cai, Vietnam*. Further, these datasets are encoded into three characteristics: *land or soil and terrain* (LT), *water* and *temp* (for temperature). So that, for Marinduque, the following are the datasets:
- `MarinduqueLT`
- `MarinduqueWater`
- `MarinduqueTemp`
And for Lao Cai, Vietnam, the following are the datasets:
- `LaoCaiLT`
- `LaoCaiWater`
- `LaoCaiTemp`
Sample head of the datasets are as follows:
```{r}
library(ALUES)
head(MarinduqueLT)
head(LaoCaiLT)
```
The columns of the datasets correspond to the factors or parameters measured from the land units. These parameters are used to compare to the standard values required for the target crop. The score of the comparison is referred to as the suitability score.
## Crop Requirements
There are 56 crops available in ALUES, each of which encodes standard properties of the target crop. These crop datasets are further categorized into four characteristics: *terrain*, *soil*, *water* and *temp*. So that, for avocado, the datasets are encoded as
`AVOCADOTerrain`, `AVOCADOSoil`, `AVOCADOWater` and `AVOCADOTemp`. The list of crop datasets can be extracted as follows:
```{r}
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
crop_data
```
Sample crop requirement datasets are given below:
```{r}
GUAVASoil
GUAVATemp
CINNAMONTerrain
CINNAMONWater
```
Each datasets are well documented, so make sure to check it for details and descriptions of the parameters used. | /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a01_datasets.Rmd |
## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
## -----------------------------------------------------------------------------
library(ALUES)
BANANATerrain
## ---- out.width="100%", echo=FALSE--------------------------------------------
knitr::include_graphics("../vignettes/img/trimf.jpg")
## ---- out.width="100%", echo=FALSE--------------------------------------------
knitr::include_graphics("../vignettes/img/tramf.jpg")
## ---- out.width="100%", echo=FALSE--------------------------------------------
knitr::include_graphics("../vignettes/img/gaumf.jpg")
| /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a02_theory_of_suit.R |
---
title: "Article 2: Methodology used in ALUES"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 2: Methodology used in ALUES}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Introduction
It is important to understand the theory used for computing the suitability scores by ALUES, to better interpret the results provided by the APIs. In its simplest form, the task of evaluating land suitability is to map an input characteristics of the land unit into the suitability class of the target parameter or factor. This is done by checking whether the input characteristic is within any of the suitability classes. Consider for example the following data:
```{r}
library(ALUES)
BANANATerrain
```
If an input land unit has terrain with slope of 1 degree, then according to `BANANATerrain` crop requirement, the land unit is *highly suitable* (S1) for farming banana. In this example, the suitability score is the 1 degree slope, since this is the statistics of the land unit directly compared to the intervals of the suitability classes (the columns: s1 - highly suitable, s2 - suitable, s3 - marginally suitable) provided in `BANANATerrain`. Further, suppose the input land unit is known to flood, but only for a short period, then the Flood factor for this land unit is 2 (i.e. short time according to the metric of Flood factor), and according to `BANANATerrain`, the land unit is not *highly suitable* (S1) but rather *suitable* (S2). In this case, the suitability scores of the land unit for factors SlopeD and Flood are 1 and 2, respectively, with the corresponding classes of S1 and S2, respectively. However, these scores can be further summarized into a single value known as the *overall suitability score*, albeit it won't be easy. This is due to the units or metric of the suitability scores, SlopeD is in terms of degrees, so a score of 1, means 1 degree, whereas Flood is in terms of time, so a score of 2, means short time. Two different metrics cannot be combined into one, and this is where the concept of membership function comes in.
The limits of each suitability class specified for each factor in any crop requirement, example `BANANATerrain`, forms what is referred in here as the *unstandardized suitability class intervals*. The term *unstandardized* follows from the fact that the class intervals across factors or parameters have different units, as already emphasized earlier. It would be convenient, therefore, to have a uniform or standardized unit or metric across factors. In this article, this is referred to as the *standardized suitability scores* and *standardized class intervals*. For purpose of brevity and distinction, the *unstandardized suitability class intervals* are now referred to as the *parameter class intervals* or *parameter intervals*, since the former is specified across parameters of any crop requirement.
The idea of membership function is to standardize the parameter class intervals into a *standardized suitability class*. For purpose of brevity, the latter is now simply referred to as the *suitability class*. The standardization is done by mapping the parameter intervals into a space of unit interval, i.e. $\mathbb{R}_{[0,1]}$. More formally, Definitions 1-3 are the mathematical formulations of the concepts used in this article.
## Membership Function
The membership function (MF) is used to standardized the scores and the parameters intervals across factors. More formally, it is defined in Definition 1 below. There are choices for the shapes of MF, for ALUES there are three: triangular, trapezoidal and Gaussian. Each of the MF can take either *partial* or *complete* face. For triangular, refer to Definitions 4-6; for trapezoidal, refer to Definitions 7-9; and for Gaussian, refer to Definition 10.
## Computing Suitability Score
Referring back to `BANANATerrain`, the parameter intervals for the suitability classes of SlopeD can be written explicitly as follows: [min, 1) for S1; [1, 2) for S2; and [2, 3] for S3. This assignment is based on the classification used by Yen et al. (2006). The *not-suitable* (N) class is not indicated since it is understood that values greater than the S3's upper limit or less than the S1's lower limit (if exists), are assigned to class N. Given this ordering of crop's parameter interval limits, the appropriate MF is the right triangular MF (Fig. \ref{fig:trimf}b). This follows from the fact that the *most-suitable* (or *highly-suitable*) class S1 has interval limits less than the limits of other suitability classes. By doing so, the crop's parameter interval limits are arranged in ascending order in the $x$-axis on points $v_1$, $v_2$ and $v_3$, respectively, as shown in Fig. \ref{fig:trimf}b.
To complete the computation, the min and max limits, which are notated as $v_0$ and $v_p$ (in this case, $v_p=v_4$ since $p=4$), respectively, must therefore be specified. In ALUES, however, these values can be assigned by the users themselves based on their expert opinions. Otherwise, the package will set the $\mathrm{min}:=v_0=0$ and $\mathrm{max}:=v_p:=v_{p-1}+\gamma=v_3+\gamma$ ($\gamma$ is defined in Definition 4) by default. As an example (for SlopeD), the max is mathematically computed as follows:
\begin{align}
\gamma :=&\;\frac{(v_2-v_1)+(v_3-v_2)}{2}\nonumber\\
=&\;\frac{(2-1)+(3-2)}{2} = 1,
\end{align}
so that
\begin{align}
\mathrm{max}:=&\;v_p:=v_3+\gamma\nonumber\\
=&\;3+\frac{(2-1)+(3-2)}{2}=4.
\end{align}
## Mathematical Formulation
To present it more formally, this section presents the complete definitions of the theory used in the core algorithms of the package.
<br><br>
**Definition 1 (Membership Function)**. Let $\mathscr{X}\subseteq \mathbb{R}$ and $\mathscr{Y}\subseteq \mathbb{R}_{[0,1]}$, then $\mu:\mathscr{X}\rightarrow\mathscr{Y}$ is a *membership function* (MF).
<br>
*Remark 1*. In the context of land evaluation, $\mathscr{X}$ is the space of the parameter values of the input land unit, and $\mathscr{Y}$ is the space of the suitability scores.
<br><br>
**Definition 2 (Class Intervals)**. Let $u_i\in\mathbb{R}, \forall i\in\mathbb{N}_{[0,p-1]}$, then the partitions $[u_i,u_{i+1})\in\mathscr{U}$ are defined as the *suitability class intervals*.
<br><br>
**Definition 3 (Parameter Intervals)**. Let $v_i\in\mathbb{R}, \forall i\in\mathbb{N}_{[0,p-1]}$, then $[v_i,v_{i+1})\in \mathscr{V}$ are defined to be the *crop's parameter intervals*.
<br>
*Remark 2*. $v_i$ is the interval limit of the factor or parameter. $v_0$ and $v_p$ are the minimum and maximum factor limits, respectively, both needs to be computed.
### Triangular Membership Function
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/trimf.jpg")
```
<br><br>
**Definition 4 (Left Triangular)**. Let $x_{jk}\in\mathscr{X}$ be the $j$th land unit's actual value for any target factor $k$, $\forall j \in \mathbb{N}_{[1,n]}$ and $\forall k \in \mathbb{N}_{[1,m]}$, and let $[v_{i},v_{i+1})\in\mathscr{V}$ be the crop's parameter intervals, $\forall i\in\mathbb{N}_{[0,p-1]}$, then the *lower* or *left triangular* MF, herein notated as $\mu_{\triangle_{\downarrow}}$, is defined as follows:
\begin{equation}
\mu_{\triangle_{\downarrow}}(x_{jk}):=
\begin{cases}
\displaystyle\frac{x_{jk}-\mathrm{min}}{\mathrm{max}-\mathrm{min}},&\mathrm{min}\leq x_{jk}\leq\mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases}
\end{equation}
where $\mathrm{min}:= v_0:= v_1-\gamma$, $\mathrm{max}:= v_p:= v_{p-1}+\gamma$, and $\gamma:=\frac{1}{p-2}\sum_{i=1}^{p-2}(v_{i+1}-v_{i})$.
<br>
*Remark 3*. ALUES sets the $\mathrm{min}:=v_0=0$ for all MFs, unless specified by the user explicitly.
**Definition 5 (Right Triangular)**. From Definition 4, the *upper* or *right triangular* MF, herein notated as $\mu_{\triangle_{\uparrow}}$, is defined as follows:
\begin{equation}\label{eq:rtri}
\mu_{\triangle_{\uparrow}}(x_{jk}):=
\begin{cases}
\displaystyle\frac{\mathrm{max}-x_{jk}}{\mathrm{max}-\mathrm{min}},&\mathrm{min}\leq x_{jk}\leq\mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases}.
\end{equation}
**Definition 6 (Full Triangular)**. From Definition 4 and 5, the *full triangular* MF, herein notated as $\mu_{\triangle}$, is defined as follows:
\begin{equation}
\mu_{\triangle}(x_{jk}):=
\begin{cases}
0,&x_{jk}\leq 0\\
\mu_{\triangle_{\downarrow}}(x_{jk}),&\mathrm{min}\leq x_{jk}\leq\mathrm{m}\\
\mu_{\triangle_{\uparrow}}(x_{jk}),&\mathrm{m}<x_{jk}<\mathrm{max}\\
0,&x_{jk}\geq \mathrm{max}
\end{cases}
\end{equation}
where $\mathrm{m}:= \frac{v_{i}^{*}+v_{i+1}^*}{2}$ such that $v_i^*<\mathrm{m}<v_{i+1}^*$, and $v_i^{*}$ and $v_{i+1}^*$ are interval limits right next to m.
### Trapezoidal Membership Function
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/tramf.jpg")
```
<br><br>
**Definition 7 (Left Trapezoidal)**. From Definition 4, the *lower* or *left trapezoidal* MF, herein notated as $\mu_{\bigtriangledown_{\downarrow}}$, is defined as follows:
\begin{equation}
\mu_{\bigtriangledown_{\downarrow}}(x_{jk}):=
\begin{cases}
\displaystyle\frac{x_{jk}-\mathrm{min}}{\mathrm{max}-\mathrm{min}},&\mathrm{min}\leq x_{jk}\leq v_{p-1}\\
1,&v_{p-1}<x_{jk}\leq \mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases},
\end{equation}
where $\mathrm{min},\mathrm{max}$ and $\gamma$ are the same as in Definition 4.
**Definition 8 (Right Trapezoidal)**. From Definition 4, the *upper* or *right trapezoidal* MF, herein notated as $\mu_{\bigtriangledown_{\uparrow}}$, is defined as follows:
\begin{equation}
\mu_{\bigtriangledown_{\uparrow}}(x_{jk}):=\begin{cases}
1,&\mathrm{min}\leq x_{jk}\leq v_1\\
\displaystyle\frac{\mathrm{max}-x_{jk}}{\mathrm{max}-\mathrm{min}},&v_1<x_{jk}\leq\mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases}.
\end{equation}
**Definition 9 (Full Trapezoidal)**. From Definition 7 and 8, the *full trapezoidal* MF, herein notated as $\mu_{\bigtriangledown}$, is defined as follows:
\begin{equation}
\mu_{\bigtriangledown}(x_{jk}):=
\begin{cases}
\mu_{\bigtriangledown_{\downarrow}}(x_{jk}),&\mathrm{min}\leq x_{jk}\leq v_i^*\\
1,&v_i^*<x_{jk}\leq v_{i+1}^*\\
\mu_{\bigtriangledown_{\uparrow}}(x_{jk}),&v_{i+1}^*<x_{jk}\leq\mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases},
\end{equation}
where $v_i^*$ and $v_{i+1}^*$ are defined in Definition 6.
### Gaussain Membership Function
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/gaumf.jpg")
```
<br><br>
**Definition 10 (Gaussian MF)**. From Definition 4, the *full Gaussian* MF, herein notated as $\mu_{\curlywedge}$, is defined as follows:
\begin{equation}
\mu_{\curlywedge}(x_{jk}):=\exp\left[-\frac{(x_{jk}-\alpha)^2}{2\sigma^2}\right],
\end{equation}
where $\alpha\in(-\infty,\infty)$ and $\sigma\in(0,\infty)$.
*Remark 4*. For partial Gaussian MF, however, the adjustment is done using the location hyperparameter. In particular, if $\alpha=\mathrm{min}$, then the model is right Gaussian function. However, if $\alpha=\mathrm{max}$, then the model is left Gaussian function.
### Overall Suitability
**Definition 11 (Overall Suitability)**. Let $y_{jk}\in\mathscr{Y}$ be the $j$th land unit's suitability score for any target factor $k$, $\forall j\in \mathbb{N}_{[1,n]}$ and $\forall k\in\mathbb{N}_{[1,m]}$; and let $w_{k}\in\mathbb{N}_{[1,3]}$ be the weight of the $k$th factor; then, $\mathbf{y}_{j}:=[y_{j1},\cdots,y_{jm}]^{\text{T}}\in\mathbb{R}^m$ is the vector suitability scores of all target factors, and $\mathbf{w}:=[w_1,\cdots,w_m]^{\text{T}}\in\mathbb{N}^m$ is the corresponding weights vector. The *overall suitability using average aggregation*, herein notated as $\bar{\mu}$, of a given land unit is computed as follows:
\begin{equation}\label{eq:overallsuit}
\bar{\mu}(\mathbf{y}_j|\mathbf{w}):= \mathbf{y}_j^{\mathrm{T}}\lambda(\mathbf{w})=\sum_{\forall k}y_{jk}*\lambda (w_k),
\end{equation}
where $\lambda(w_k):= \frac{\eta-w_k}{\delta}, \eta:=\sum_{\forall k} w_k$ and $\delta:=\sum_{\forall k}(\eta - w_k)$. For *minimum* (notated as $\tilde{\mu}$) and *maximum* (notated as $\hat{\mu}$) aggragation functions, the following are the definitions:
\begin{equation}
\tilde{\mu}(\mathbf{y}_j):=\min(\{y_{j1}, \cdots,y_{jm}\}),
\end{equation}
and
\begin{equation}
\hat{\mu}(\mathbf{y}_j):=\max(\{y_{j1}, \cdots,y_{jm}\}).
\end{equation}
### References
* Yen, B., Pheng, K., & Hoanh, C. (2006). LUSET:Land Use Suitability Evaluation Tool User’s Guide.International Rice Research Institute | /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a02_theory_of_suit.Rmd |
## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
## ---- eval=FALSE--------------------------------------------------------------
# suit(
# crop,
# terrain = NULL,
# water = NULL,
# temp = NULL,
# mf = "triangular",
# sow_month = NULL,
# minimum = NULL,
# maximum = "average",
# interval = NULL,
# sigma = NULL
# )
## -----------------------------------------------------------------------------
library(ALUES)
banana_suit <- suit("banana", terrain=MarinduqueLT)
names(banana_suit)
## ---- eval=FALSE--------------------------------------------------------------
# banana_suit[["terrain"]]
# banana_suit[["soil"]]
## -----------------------------------------------------------------------------
names(banana_suit[["soil"]])
## -----------------------------------------------------------------------------
banana_suit[["soil"]][["Factors Evaluated"]]
## -----------------------------------------------------------------------------
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
crop_data
## ---- error=TRUE--------------------------------------------------------------
potato_suit1 <- suit("sweet potato", terrain=MarinduqueLT)
potato_suit2 <- suit("potatosw", terrain=MarinduqueLT)
## -----------------------------------------------------------------------------
head(MarinduqueLT)
## -----------------------------------------------------------------------------
BANANATerrain
BANANASoil
BANANAWater
BANANATemp
## -----------------------------------------------------------------------------
banana_suit[["terrain"]]
## -----------------------------------------------------------------------------
banana_multi <- suit("banana", terrain=MarinduqueLT, water=MarinduqueWater, temp=MarinduqueTemp, sow_month=2)
names(banana_multi)
## -----------------------------------------------------------------------------
banana_suit[["terrain"]]
banana_suit[["water"]]
banana_suit[["temp"]]
lapply(banana_suit[["soil"]], function(x) head(x))
## -----------------------------------------------------------------------------
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal")
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
## -----------------------------------------------------------------------------
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval=c(0, 0.3, 0.6, 0.9, 1))
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
## -----------------------------------------------------------------------------
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval="unbias")
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
## -----------------------------------------------------------------------------
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval="unbias")
banana_suit[["soil"]][["Factors Evaluated"]]
## -----------------------------------------------------------------------------
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval="unbias", maximum=c(60, 20, 9, 10))
banana_suit
## -----------------------------------------------------------------------------
MarinduqueLT2 <- MarinduqueLT[, 3:ncol(MarinduqueLT)]
banana_suit <- suit("banana", terrain=MarinduqueLT2, mf="trapezoidal", interval="unbias", maximum=c(60, 20, 9, 10))
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
| /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a03_understanding_suit.R |
---
title: "Article 3: Understanding the suit function"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 3: Understanding the suit function}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Introduction
The `suit` function is used for computing the suitability score and class of the land units for a given target crop. The function has the following usage:
```{r, eval=FALSE}
suit(
crop,
terrain = NULL,
water = NULL,
temp = NULL,
mf = "triangular",
sow_month = NULL,
minimum = NULL,
maximum = "average",
interval = NULL,
sigma = NULL
)
```
Check the documentation for details of the arguments. This article will focus on how to use this function. To evaluate the suitability score of Marinduque land units for terrain, soil, water and temperature characteristics, simply run the `suit` function for each of these characteristics. That is,
```{r}
library(ALUES)
banana_suit <- suit("banana", terrain=MarinduqueLT)
names(banana_suit)
```
The warning above simply tells the user that one of the factor, CECc, in the target crop requirement, has parameter intervals for all suitability classes equal to 16, and the package used this value as the maximum constant for computing the suitability scores. For more, please refer to the **Article 2: Methodology used in ALUES** of the documentation.
The `suit` function returns a list of output of target characteristics, in this case `"terrain"` and `"soil"`. To access the output, simply run the following:
```{r, eval=FALSE}
banana_suit[["terrain"]]
banana_suit[["soil"]]
```
Each of these are lists, with the following names:
```{r}
names(banana_suit[["soil"]])
```
So that, to access the factors evaluated, simply run the following:
```{r}
banana_suit[["soil"]][["Factors Evaluated"]]
```
## Targetting Crop
There are 56 crops available in ALUES, and what we've illustrated above are for banana only. Other crops are listed below:
```{r}
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
crop_data
```
These are the names for the input string for the `suit` function. For example, to target sweet potato the input string is not `"sweet potato"` but rather `potatosw`. That is,
```{r, error=TRUE}
potato_suit1 <- suit("sweet potato", terrain=MarinduqueLT)
potato_suit2 <- suit("potatosw", terrain=MarinduqueLT)
```
## Targetting Crop Factors
The idea of evaluating a land unit is to match quality of the land against the standard value of the target factor. Therefore, if the crop does not include the factor you are targeting, then there won't be any matching to be done. For example, the land units evaluated above are those in Marindque, which has the following soil and terrain characteristics:
```{r}
head(MarinduqueLT)
```
The crop that we are trying to target is banana. The `suit` function simply require the user to input a string name for the target crop, and the function will look for the corresponding crop datasets. For example, for banana these are the crop requirements datasets for the four characteristics:
```{r}
BANANATerrain
BANANASoil
BANANAWater
BANANATemp
```
These datasets are used by the `suit` function depending on the specified characteristics of the input land units. So for `banana_suit` object above, the target crop datasets were `BANANATerrain` and `BANANASoil` since the input land unit specified is `terrain=MarinduqueLT`. However, input land unit only targetted the soil factors and not the terrain factors, since none of the factors in `MarinduqueLT` matched with the factors in `BANANATerrain`. That is why, accessing the output for the terrain characteristics for the `banana_suit` object will return the following:
```{r}
banana_suit[["terrain"]]
```
## Targetting Multiple Characteristics
The example above only targetted the terrain and soil characteristics, but the `suit` function allows user to also target water and temp simultaneously. This is done as follows:
```{r}
banana_multi <- suit("banana", terrain=MarinduqueLT, water=MarinduqueWater, temp=MarinduqueTemp, sow_month=2)
names(banana_multi)
```
It is necessary to specify the sowing month when specifying the water and temperature characteristics of the input land units. In this case, we are saying that the first sowing month for both water and temperature characteristics correspond to February. No factors were targetted by input land unit for banana for terrain, water and temperature characteristics.
```{r}
banana_suit[["terrain"]]
banana_suit[["water"]]
banana_suit[["temp"]]
lapply(banana_suit[["soil"]], function(x) head(x))
```
Only the head (first six) of the output of the items in the soil characteristics are shown.
## Membership Function
There are three membership functions (MFs) available in the `suit` function, namely *triangular*, *trapezoidal* and *Gaussian*. For example, the following computes the suitability scores and classes using trapezoidal MF.
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal")
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
```
## Intervals
Another option available in the `suit` function is the `interval`. By default, ALUES uses an equally spaced suitability class intervals for deriving the suitability class. That is, for N [0, 0.25), S3 [0.25, 0.50), S2 [0.50, 0.75), and S1 [0.75, 1].
### Custom Intervals
Users can modify the default equally spaced intervals, for example:
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval=c(0, 0.3, 0.6, 0.9, 1))
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
```
The above code sets the new suitability class intervals into: N [0, 0.3), S3 [0.3, 0.6), S2 [0.6, 0.9), and S1 [0.9, 1].
### Unbias Intervals
The problem with the fixed interval is that the said intervals does not take into account the shape of the membership function and the spacing of the parameter interval limits (*See* Article 2 for parameter intervals). Custom intervals might be able to capture this if the user computed the interval limits manually, but ALUES provides an option just for this, by setting `interval="unbias"`. That is,
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval="unbias")
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
```
By setting the `interval="unbias"`, the `suit` function will generate a different likely unequally spaced suitability class intervals, but the interval limits are mathematically correct, in terms of the mapping of the parameter interval limits to suitability class limits via the membership function.
## Maximum and Minimum
Another parameter that can be set for `suit` are the `minimum` and `maximum`. These are the constants used by the membership function for computing the suitability score.
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval="unbias")
banana_suit[["soil"]][["Factors Evaluated"]]
```
From the above result, there are four factors targetted by the input land unit, these are CFragm, CECc, pHH2O and SoilTe. Suppose we know the maximum value that these factors can take, say 60 for CFragm, 20 for CECc, 9 for pHH2O, and 10 for SoilTe. We can specify these as follows:
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval="unbias", maximum=c(60, 20, 9, 10))
banana_suit
```
The result gave us an error. We understand the error for terrain characteristics, but for soil it says the argument maximum must be equal in length with the target factors specified in the input land units dataset. We know that there should be 4 factors, but upon checking we see that the `MarinduqueLT` also have Lon and Lat columns, which ALUES assumes to be a target factor as well. Indeed, we need to exclude these columns (those that are not the target factors) when specifying `minimum` or `maximum` constants. Thus, it should be:
```{r}
MarinduqueLT2 <- MarinduqueLT[, 3:ncol(MarinduqueLT)]
banana_suit <- suit("banana", terrain=MarinduqueLT2, mf="trapezoidal", interval="unbias", maximum=c(60, 20, 9, 10))
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
```
## Sigma of Gaussian
The `sigma` argument is used to specify scale of the Gaussian membership function. That is, it is only applicable for `mf="gaussian"`. | /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a03_understanding_suit.Rmd |
## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
## -----------------------------------------------------------------------------
library(ALUES)
banana_suit <- suit("banana", terrain=MarinduqueLT)
class(banana_suit[["terrain"]])
class(banana_suit[["soil"]])
## -----------------------------------------------------------------------------
ovsuit <- overall_suit(banana_suit[["soil"]])
head(ovsuit)
## -----------------------------------------------------------------------------
ovsuit <- overall_suit(banana_suit[["soil"]], method="average")
head(ovsuit)
## -----------------------------------------------------------------------------
ovsuit <- overall_suit(banana_suit[["soil"]], method="average", interval=c(0, 0.6, 0.7, 0.9, 1))
head(ovsuit)
| /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a04_understanding_overall_suit.R |
---
title: "Article 4: Understanding the overall_suit function"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 4: Understanding the overall_suit function}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
The overall suitability can be computed using the `overall_suit` function, which takes an object of class suitability. For example,
```{r}
library(ALUES)
banana_suit <- suit("banana", terrain=MarinduqueLT)
class(banana_suit[["terrain"]])
class(banana_suit[["soil"]])
```
There are no factors that were targetted for the terrain characteristics, hence the returned value is a string error. Thus, only the soil characteristics can have an overall suitability, and is computed as follows:
```{r}
ovsuit <- overall_suit(banana_suit[["soil"]])
head(ovsuit)
```
By default, the `overall_suit` function uses minimum as a summary statistics, hence the 0 scores and N classes across land units. To adjust this to average aggregation, use the `method` argument to specify.
```{r}
ovsuit <- overall_suit(banana_suit[["soil"]], method="average")
head(ovsuit)
```
## Intervals
By default, the `overall_suit` uses an equally spaced interval for the suitability classes, that is, N [0, 0.25), S3 [0.25, 0.50), S2 [0.50, 0.75), and S1 [0.75, 1]. This can be changed using the `interval` argument, for example
```{r}
ovsuit <- overall_suit(banana_suit[["soil"]], method="average", interval=c(0, 0.6, 0.7, 0.9, 1))
head(ovsuit)
```
The above code sets the suitability class intervals into: N [0, 0.60), S3 [0.60, 0.70), S2 [0.70, 0.90), and S1 [0.90, 1]. It should be emphasized that the `interval` argument cannot be set to `unbias` as in the case of the `interval` argument of the `suit` function. This follows from the fact that the `overall_suit` function is not using a membership function for computing the score, but an aggregation function. | /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a04_understanding_overall_suit.Rmd |
## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
## -----------------------------------------------------------------------------
terrain_input <- data.frame(
Flood = c(1, 2, 2, 2, 3),
SlopeD = c(3, 4, 5, 1, 2),
CFragm = c(10, 30, 50, 60, 40),
SoilDpt = c(45, 60, 90, 70, 30)
)
## -----------------------------------------------------------------------------
library(ALUES)
AVOCADOTerrain
AVOCADOSoil
avocado_suit <- suit("avocado", terrain=terrain_input)
head(avocado_suit[["terrain"]][["Suitability Score"]])
head(avocado_suit[["terrain"]][["Suitability Class"]])
head(avocado_suit[["soil"]][["Suitability Score"]])
head(avocado_suit[["soil"]][["Suitability Class"]])
## -----------------------------------------------------------------------------
water_input <- data.frame(
Apr = c(150, 140, 120),
May = c(70, 90, 100),
Jun = c(85, 90, 105)
)
water_input
## -----------------------------------------------------------------------------
RICEBRWater
water_suit <- suit("ricebr", water=water_input, sow_month=1)
water_suit
## -----------------------------------------------------------------------------
water_suit <- suit("ricebr", water=water_input, sow_month=3)
water_suit
## -----------------------------------------------------------------------------
temp_input <- data.frame(
Sep = c(34.2, 35.5, 33.4),
Oct = c(32.5, 34.2, 32.0),
Nov = c(30.3, 32.2, 31.1)
)
RICEBRTemp
temp_suit <- suit("ricebr", temp=temp_input, sow_month=9)
## -----------------------------------------------------------------------------
temp_suit
| /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a05_custom_land_units_input.R |
---
title: "Article 5: Custom input land units"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 5: Custom input land units}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
ALUES comes with two datasets for input land units. These are the land units of Marinduque, Philippines; and, Lao Cai, Vietnam. However, users will likely have their own region of interest. As such, this article will illustrate how to prepare the data.
For any region of interest, users must specify the properties of the land units into three categories:
- terrain and soil
- water
- temperature
Note that both terrain and soil factors must be specified as one dataframe, not separate. Suppose there are 5 units under study, the three characteristics can be specified as follows:
## Terrain and soil
Suppose for terrain, we want to target the following factors: Flood and SlopeD; and, suppose for soil we have CFragm and SoilDpt. The dataframe can be prepared as follows:
```{r}
terrain_input <- data.frame(
Flood = c(1, 2, 2, 2, 3),
SlopeD = c(3, 4, 5, 1, 2),
CFragm = c(10, 30, 50, 60, 40),
SoilDpt = c(45, 60, 90, 70, 30)
)
```
**Note: the column names must be the same with the naming convention used by the crop requirements datasets.**
So that, if this input is assessed for avocado, then the suitability score for these land units are computed as follows:
```{r}
library(ALUES)
AVOCADOTerrain
AVOCADOSoil
avocado_suit <- suit("avocado", terrain=terrain_input)
head(avocado_suit[["terrain"]][["Suitability Score"]])
head(avocado_suit[["terrain"]][["Suitability Class"]])
head(avocado_suit[["soil"]][["Suitability Score"]])
head(avocado_suit[["soil"]][["Suitability Class"]])
```
## Water
For water characteristics, suppose the average rainfall for 3 land units were recorded for four months with the following data:
```{r}
water_input <- data.frame(
Apr = c(150, 140, 120),
May = c(70, 90, 100),
Jun = c(85, 90, 105)
)
water_input
```
Note that when specifying the factors for water chacteristics, the month must be specified in three characters (correct case) only, that is, it shouldn't be specified as January, February, etc.
The suitability scores for rainfed bunded rice water requirement are computed as follows:
```{r}
RICEBRWater
water_suit <- suit("ricebr", water=water_input, sow_month=1)
water_suit
```
Setting the `sow_month=1` indicates that the factors for `RICEBRWater`'s `WmAv1` correspond to January, `WmAv2` to February, `WmAv3` to March, and `WmAv4` to April. Thus, the only factors that were targetted by the `water_input` is April. So that, setting the `sow_month=3`, would make `WmAv1` of `RICEBRWater` as March, `WmAv2` as April, etc. This in turn targets the months April to Jun.
```{r}
water_suit <- suit("ricebr", water=water_input, sow_month=3)
water_suit
```
## Temperature
Another characteristics that can be targetted is the temperature.
```{r}
temp_input <- data.frame(
Sep = c(34.2, 35.5, 33.4),
Oct = c(32.5, 34.2, 32.0),
Nov = c(30.3, 32.2, 31.1)
)
RICEBRTemp
temp_suit <- suit("ricebr", temp=temp_input, sow_month=9)
```
The `RICEBRTemp` crop requirement has factor `TmAv2`, which is the mean temperature for the 2nd month. Thus, setting the sowing month to 9 suggest that the sowing month started at September, and thus sets `TmAv2` to October. Hence, the factor that was targetted by the input land units is the October as seen below:
```{r}
temp_suit
``` | /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a05_custom_land_units_input.Rmd |
## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
## -----------------------------------------------------------------------------
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
crop_data
## -----------------------------------------------------------------------------
library(ALUES)
COFFEEARSoil
## -----------------------------------------------------------------------------
new_crop <- data.frame(matrix(nrow=0, ncol=ncol(COFFEEARSoil)))
names(new_crop) <- names(COFFEEARSoil)
new_crop
## -----------------------------------------------------------------------------
new_crop[1, "code"] <- "CFragm"
new_crop[1, 2:4] <- c(60, 40, 20)
new_crop
## -----------------------------------------------------------------------------
new_crop[2, "code"] <- "pHH2O"
new_crop[2, 2:7] <- c(4.5, 5.0, 5.1, 5.6, 6.2, 6.9)
new_crop
## -----------------------------------------------------------------------------
new_crop[2, "wts"] <- 2
new_crop
## -----------------------------------------------------------------------------
newcrop_suit <- suit(new_crop, terrain=MarinduqueLT)
lapply(newcrop_suit[["terrain"]], function (x) head(x))
| /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a06_custom_crop_input.R |
---
title: "Article 6: Custom crop requirements input"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 6: Custom crop requirements input}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
As already emphasized in Article 2, the following are the crop datasets available in ALUES:
```{r}
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
crop_data
```
In cases were the target crop is not available in the ALUES database, users can specify their own by following the template of a crop requirement dataset. For example,
```{r}
library(ALUES)
COFFEEARSoil
```
The above data frame shows us the first column as the code of the target factors, and the remaining of the columns are the suitability classes with the last column for the weights if any.
## Crop Characteristics
It should be noted that apart from the proper templating of the dataframe for any new target crop, the categorization of the characteristics must be observed as well. That is, for any new crop, the four characteristics: terrain, soil, water, and temp, must be encoded separately as one dataframe. That is, for any target crop there will be four dataframes to expect for the four characteristics mentioned.
## Creating from a template
To create a custom crop dataset, use the following code to generate an empty row data frame with the appropriate column name
```{r}
new_crop <- data.frame(matrix(nrow=0, ncol=ncol(COFFEEARSoil)))
names(new_crop) <- names(COFFEEARSoil)
new_crop
```
Needless to say, any ALUES crop dataset can be used above in place of `COFFEEARSoil`, since all crop datasets have the same column names.
Next is to enter the name of the factors in the first column, and then the corresponding standard values for suitability classes. Suppose for example, the new crop demands a factor CFragm to be S3 (marginally suitable) if it is 60, S2 if it is 40, and S1 if it is 20; then this can be entered as follows:
```{r}
new_crop[1, "code"] <- "CFragm"
new_crop[1, 2:4] <- c(60, 40, 20)
new_crop
```
New factors can be added further in the succeeding rows, say for row 2 we have pHH2O with the following data
```{r}
new_crop[2, "code"] <- "pHH2O"
new_crop[2, 2:7] <- c(4.5, 5.0, 5.1, 5.6, 6.2, 6.9)
new_crop
```
Adding weight to pHH2O is done as follows:
```{r}
new_crop[2, "wts"] <- 2
new_crop
```
Now suppose we want to evaluate Marinduque land units for this new crop, we can do this as follows:
```{r}
newcrop_suit <- suit(new_crop, terrain=MarinduqueLT)
lapply(newcrop_suit[["terrain"]], function (x) head(x))
``` | /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a06_custom_crop_input.Rmd |
## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE)
## -----------------------------------------------------------------------------
library(ALUES)
y <- MarinduqueLT
banana_suit <- suit("banana", terrain=y)
banana_ovsuit <- overall_suit(banana_suit[["soil"]], method="average")
## ---- eval=FALSE--------------------------------------------------------------
# library(ggmap)
# library(raster)
# library(reshape2)
# map_lvl0 <- getData("GADM", country = "PHL", level = 0)
# map_lvl2 <- getData("GADM", country = "PHL", level = 2)
#
# prov <- map_lvl2[map_lvl2$NAME_1 == as.character("Marinduque"),]
# munic_coord <- coordinates(prov)
# munic_coord <- data.frame(munic_coord)
# munic_coord$label <- prov@data$NAME_2
#
# val <- banana_suit[["soil"]][[2]]
# val["Overall Suitability"] <- banana_ovsuit[,1]
# d_map <- melt(as.matrix(val))
# d_map$Lon <- rep(y$Lon, ncol(val)); d_map$Lat <- rep(y$Lat, ncol(val))
#
# fill <- "#FFF7BC"; shadow <- "#9ECAE1"; ncol <- 3; size <- 3; alpha <- 1
# text_opts <- list(alpha = 1, angle = 0, colour = "black", family = "sans", fontface = 1, lineheight = 1, size = 3)
# labels <- list(title = "", xlab = "", ylab = "")
#
# p1 <- ggplot() + geom_polygon(data = prov, aes(long + 0.008, lat - 0.005, group = group), fill = shadow) +
# geom_polygon(data = prov, aes(long, lat, group = group), colour = "grey50", fill = fill) +
# geom_tile(aes(x = Lat, y = Lon, fill = value), data = d_map, size = size, alpha = alpha) +
# facet_wrap(~ Var2, ncol = ncol) +
# geom_polygon(data = prov, aes(long, lat, group = group), colour = "#4E4E4C", alpha = 0) +
# geom_label(data = munic_coord, aes(x = X1, y = X2, label = label), alpha = 0.5,
# angle = text_opts$angle, colour = "white", fill = "black", family = text_opts$family,
# fontface = text_opts$fontface,
# lineheight = text_opts$lineheight, size = text_opts$size) +
# coord_equal() + ggtitle(as.character(labels$title)) + xlab(as.character(labels$xlab)) + ylab(as.character(labels$ylab)) +
# scale_fill_gradientn(name = "Score\n", colors = c("red", "#FFDF00")) +
# scale_x_continuous(breaks = round(seq(min(d_map$Lat) + 0.05, max(d_map$Lat), len = 3), 2)) +
# theme(panel.background = element_rect(fill = '#F7E7CE'),
# strip.background = element_rect(fill = "#D4BF96"),
# strip.text.x = element_text(size = 12),
# axis.text.x = element_text(size=12),
# legend.text=element_text(size=12),
# legend.title=element_text(size=12),
# axis.text.y = element_text(size=12), legend.position = c(0.85, 0.25))
# p1
## ---- out.width="100%", echo=FALSE--------------------------------------------
knitr::include_graphics("../vignettes/img/scores1.jpg")
## ---- eval=FALSE--------------------------------------------------------------
# val <- banana_suit[["soil"]][[3]]
# val["Overall Suitability"] <- banana_ovsuit[,2]
# d_map <- melt(as.matrix(val))
# d_map$Lon <- rep(y$Lon, ncol(val)); d_map$Lat <- rep(y$Lat, ncol(val))
#
# d_map$Class <- factor(d_map$value, levels=c("N", "S3", "S2", "S1"))
#
# p1 <- ggplot() + geom_polygon(data = prov, aes(long + 0.008, lat - 0.005, group = group), fill = shadow) +
# geom_polygon(data = prov, aes(long, lat, group = group), colour = "grey50", fill = fill) +
# geom_tile(aes(x = Lat, y = Lon, fill = Class), data = d_map, size = size, alpha = alpha) +
# facet_wrap(~ Var2, ncol = ncol) +
# geom_polygon(data = prov, aes(long, lat, group = group), colour = "#4E4E4C", alpha = 0) +
# geom_label(data = munic_coord, aes(x = X1, y = X2, label = label), alpha = 0.5,
# angle = text_opts$angle, colour = "white", fill = "black", family = text_opts$family,
# fontface = text_opts$fontface,
# lineheight = text_opts$lineheight, size = text_opts$size) +
# coord_equal() + ggtitle(as.character(labels$title)) + xlab(as.character(labels$xlab)) + ylab(as.character(labels$ylab)) +
# scale_colour_discrete(name = "Class\n", breaks=c("N", "S3", "S2", "S1"), labels=c("N", "S3", "S2", "S1")) +
# scale_x_continuous(breaks = round(seq(min(d_map$Lat) + 0.05, max(d_map$Lat), len = 3), 2)) +
# theme(panel.background = element_rect(fill = '#F7E7CE'),
# strip.background = element_rect(fill = "#D4BF96"),
# strip.text.x = element_text(size = 12),
# axis.text.x = element_text(size=12),
# legend.text=element_text(size=12),
# legend.title=element_text(size=12),
# axis.text.y = element_text(size=12), legend.position = c(0.85, 0.25))
# p1
## ---- out.width="100%", echo=FALSE--------------------------------------------
knitr::include_graphics("../vignettes/img/classes1.jpg")
| /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a07_visual_maps.R |
---
title: "Article 7: Visualizing with maps"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 7: Visualizing with maps}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
While ALUES can generate tables for suitability scores and classes, it would be best to visualize it via maps. The main requirement of course is the availability of the longitude and latitude for each of the land units. This is possible for Marinduque as it has spatial variables (longitude and latitude).
## Suitability scores and classes
Suppose we want to evaluate the land units for banana, then:
```{r}
library(ALUES)
y <- MarinduqueLT
banana_suit <- suit("banana", terrain=y)
banana_ovsuit <- overall_suit(banana_suit[["soil"]], method="average")
```
## Generate maps
There are several ways to generate maps in R, but the following uses ggmap library:
```{r, eval=FALSE}
library(ggmap)
library(raster)
library(reshape2)
map_lvl0 <- getData("GADM", country = "PHL", level = 0)
map_lvl2 <- getData("GADM", country = "PHL", level = 2)
prov <- map_lvl2[map_lvl2$NAME_1 == as.character("Marinduque"),]
munic_coord <- coordinates(prov)
munic_coord <- data.frame(munic_coord)
munic_coord$label <- prov@data$NAME_2
val <- banana_suit[["soil"]][[2]]
val["Overall Suitability"] <- banana_ovsuit[,1]
d_map <- melt(as.matrix(val))
d_map$Lon <- rep(y$Lon, ncol(val)); d_map$Lat <- rep(y$Lat, ncol(val))
fill <- "#FFF7BC"; shadow <- "#9ECAE1"; ncol <- 3; size <- 3; alpha <- 1
text_opts <- list(alpha = 1, angle = 0, colour = "black", family = "sans", fontface = 1, lineheight = 1, size = 3)
labels <- list(title = "", xlab = "", ylab = "")
p1 <- ggplot() + geom_polygon(data = prov, aes(long + 0.008, lat - 0.005, group = group), fill = shadow) +
geom_polygon(data = prov, aes(long, lat, group = group), colour = "grey50", fill = fill) +
geom_tile(aes(x = Lat, y = Lon, fill = value), data = d_map, size = size, alpha = alpha) +
facet_wrap(~ Var2, ncol = ncol) +
geom_polygon(data = prov, aes(long, lat, group = group), colour = "#4E4E4C", alpha = 0) +
geom_label(data = munic_coord, aes(x = X1, y = X2, label = label), alpha = 0.5,
angle = text_opts$angle, colour = "white", fill = "black", family = text_opts$family,
fontface = text_opts$fontface,
lineheight = text_opts$lineheight, size = text_opts$size) +
coord_equal() + ggtitle(as.character(labels$title)) + xlab(as.character(labels$xlab)) + ylab(as.character(labels$ylab)) +
scale_fill_gradientn(name = "Score\n", colors = c("red", "#FFDF00")) +
scale_x_continuous(breaks = round(seq(min(d_map$Lat) + 0.05, max(d_map$Lat), len = 3), 2)) +
theme(panel.background = element_rect(fill = '#F7E7CE'),
strip.background = element_rect(fill = "#D4BF96"),
strip.text.x = element_text(size = 12),
axis.text.x = element_text(size=12),
legend.text=element_text(size=12),
legend.title=element_text(size=12),
axis.text.y = element_text(size=12), legend.position = c(0.85, 0.25))
p1
```
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/scores1.jpg")
```
And for suitability classes:
```{r, eval=FALSE}
val <- banana_suit[["soil"]][[3]]
val["Overall Suitability"] <- banana_ovsuit[,2]
d_map <- melt(as.matrix(val))
d_map$Lon <- rep(y$Lon, ncol(val)); d_map$Lat <- rep(y$Lat, ncol(val))
d_map$Class <- factor(d_map$value, levels=c("N", "S3", "S2", "S1"))
p1 <- ggplot() + geom_polygon(data = prov, aes(long + 0.008, lat - 0.005, group = group), fill = shadow) +
geom_polygon(data = prov, aes(long, lat, group = group), colour = "grey50", fill = fill) +
geom_tile(aes(x = Lat, y = Lon, fill = Class), data = d_map, size = size, alpha = alpha) +
facet_wrap(~ Var2, ncol = ncol) +
geom_polygon(data = prov, aes(long, lat, group = group), colour = "#4E4E4C", alpha = 0) +
geom_label(data = munic_coord, aes(x = X1, y = X2, label = label), alpha = 0.5,
angle = text_opts$angle, colour = "white", fill = "black", family = text_opts$family,
fontface = text_opts$fontface,
lineheight = text_opts$lineheight, size = text_opts$size) +
coord_equal() + ggtitle(as.character(labels$title)) + xlab(as.character(labels$xlab)) + ylab(as.character(labels$ylab)) +
scale_colour_discrete(name = "Class\n", breaks=c("N", "S3", "S2", "S1"), labels=c("N", "S3", "S2", "S1")) +
scale_x_continuous(breaks = round(seq(min(d_map$Lat) + 0.05, max(d_map$Lat), len = 3), 2)) +
theme(panel.background = element_rect(fill = '#F7E7CE'),
strip.background = element_rect(fill = "#D4BF96"),
strip.text.x = element_text(size = 12),
axis.text.x = element_text(size=12),
legend.text=element_text(size=12),
legend.title=element_text(size=12),
axis.text.y = element_text(size=12), legend.position = c(0.85, 0.25))
p1
```
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/classes1.jpg")
``` | /scratch/gouwar.j/cran-all/cranData/ALUES/inst/doc/a07_visual_maps.Rmd |
---
title: "Getting Started"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Getting Started}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Show me the code
To evaluate the soil characteristics of the land units of Marinduque, Philippines, for farming banana, use the `suit` function as follows:
```{r}
library(ALUES)
suit_banana <- suit("banana", terrain=MarinduqueLT)
head(suit_banana[["soil"]]$`Suitability Score`)
head(suit_banana[["soil"]]$`Suitability Class`)
```
To compute the overall suitability of the land units by averaging across factors, use the `overall_suit` as follows:
```{r}
osuit <- overall_suit(suit_banana[["soil"]], method="average")
head(osuit)
```
## Show me the speed
The elapsed time for computing the suitability scores and classes were recorded for the land units of Marinduque, which has 881 units (or observations) in total; and, for the region of Lao Cai, Vietnam, which has 2928 land units.
```{r}
library(microbenchmark)
microbenchmark(
suppressWarnings(suit("banana", terrain=MarinduqueLT, interval="unbias"))
)
microbenchmark(
suppressWarnings(suit("banana", terrain=LaoCaiLT, interval="unbias"))
)
``` | /scratch/gouwar.j/cran-all/cranData/ALUES/vignettes/ALUES.Rmd |
---
title: "Article 1: ALUES datasets"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 1: ALUES datasets}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
There are two categories of datasets available in ALUES, *land units* and *crop requirements*.
## Input Land Units
The *land units* datasets are input land units with properties meant for evaluation for crop production. Two regions are available for these datasets: *Marinduque, Philippines*; and, *Lao Cai, Vietnam*. Further, these datasets are encoded into three characteristics: *land or soil and terrain* (LT), *water* and *temp* (for temperature). So that, for Marinduque, the following are the datasets:
- `MarinduqueLT`
- `MarinduqueWater`
- `MarinduqueTemp`
And for Lao Cai, Vietnam, the following are the datasets:
- `LaoCaiLT`
- `LaoCaiWater`
- `LaoCaiTemp`
Sample head of the datasets are as follows:
```{r}
library(ALUES)
head(MarinduqueLT)
head(LaoCaiLT)
```
The columns of the datasets correspond to the factors or parameters measured from the land units. These parameters are used to compare to the standard values required for the target crop. The score of the comparison is referred to as the suitability score.
## Crop Requirements
There are 56 crops available in ALUES, each of which encodes standard properties of the target crop. These crop datasets are further categorized into four characteristics: *terrain*, *soil*, *water* and *temp*. So that, for avocado, the datasets are encoded as
`AVOCADOTerrain`, `AVOCADOSoil`, `AVOCADOWater` and `AVOCADOTemp`. The list of crop datasets can be extracted as follows:
```{r}
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
crop_data
```
Sample crop requirement datasets are given below:
```{r}
GUAVASoil
GUAVATemp
CINNAMONTerrain
CINNAMONWater
```
Each datasets are well documented, so make sure to check it for details and descriptions of the parameters used. | /scratch/gouwar.j/cran-all/cranData/ALUES/vignettes/a01_datasets.Rmd |
---
title: "Article 2: Methodology used in ALUES"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 2: Methodology used in ALUES}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Introduction
It is important to understand the theory used for computing the suitability scores by ALUES, to better interpret the results provided by the APIs. In its simplest form, the task of evaluating land suitability is to map an input characteristics of the land unit into the suitability class of the target parameter or factor. This is done by checking whether the input characteristic is within any of the suitability classes. Consider for example the following data:
```{r}
library(ALUES)
BANANATerrain
```
If an input land unit has terrain with slope of 1 degree, then according to `BANANATerrain` crop requirement, the land unit is *highly suitable* (S1) for farming banana. In this example, the suitability score is the 1 degree slope, since this is the statistics of the land unit directly compared to the intervals of the suitability classes (the columns: s1 - highly suitable, s2 - suitable, s3 - marginally suitable) provided in `BANANATerrain`. Further, suppose the input land unit is known to flood, but only for a short period, then the Flood factor for this land unit is 2 (i.e. short time according to the metric of Flood factor), and according to `BANANATerrain`, the land unit is not *highly suitable* (S1) but rather *suitable* (S2). In this case, the suitability scores of the land unit for factors SlopeD and Flood are 1 and 2, respectively, with the corresponding classes of S1 and S2, respectively. However, these scores can be further summarized into a single value known as the *overall suitability score*, albeit it won't be easy. This is due to the units or metric of the suitability scores, SlopeD is in terms of degrees, so a score of 1, means 1 degree, whereas Flood is in terms of time, so a score of 2, means short time. Two different metrics cannot be combined into one, and this is where the concept of membership function comes in.
The limits of each suitability class specified for each factor in any crop requirement, example `BANANATerrain`, forms what is referred in here as the *unstandardized suitability class intervals*. The term *unstandardized* follows from the fact that the class intervals across factors or parameters have different units, as already emphasized earlier. It would be convenient, therefore, to have a uniform or standardized unit or metric across factors. In this article, this is referred to as the *standardized suitability scores* and *standardized class intervals*. For purpose of brevity and distinction, the *unstandardized suitability class intervals* are now referred to as the *parameter class intervals* or *parameter intervals*, since the former is specified across parameters of any crop requirement.
The idea of membership function is to standardize the parameter class intervals into a *standardized suitability class*. For purpose of brevity, the latter is now simply referred to as the *suitability class*. The standardization is done by mapping the parameter intervals into a space of unit interval, i.e. $\mathbb{R}_{[0,1]}$. More formally, Definitions 1-3 are the mathematical formulations of the concepts used in this article.
## Membership Function
The membership function (MF) is used to standardized the scores and the parameters intervals across factors. More formally, it is defined in Definition 1 below. There are choices for the shapes of MF, for ALUES there are three: triangular, trapezoidal and Gaussian. Each of the MF can take either *partial* or *complete* face. For triangular, refer to Definitions 4-6; for trapezoidal, refer to Definitions 7-9; and for Gaussian, refer to Definition 10.
## Computing Suitability Score
Referring back to `BANANATerrain`, the parameter intervals for the suitability classes of SlopeD can be written explicitly as follows: [min, 1) for S1; [1, 2) for S2; and [2, 3] for S3. This assignment is based on the classification used by Yen et al. (2006). The *not-suitable* (N) class is not indicated since it is understood that values greater than the S3's upper limit or less than the S1's lower limit (if exists), are assigned to class N. Given this ordering of crop's parameter interval limits, the appropriate MF is the right triangular MF (Fig. \ref{fig:trimf}b). This follows from the fact that the *most-suitable* (or *highly-suitable*) class S1 has interval limits less than the limits of other suitability classes. By doing so, the crop's parameter interval limits are arranged in ascending order in the $x$-axis on points $v_1$, $v_2$ and $v_3$, respectively, as shown in Fig. \ref{fig:trimf}b.
To complete the computation, the min and max limits, which are notated as $v_0$ and $v_p$ (in this case, $v_p=v_4$ since $p=4$), respectively, must therefore be specified. In ALUES, however, these values can be assigned by the users themselves based on their expert opinions. Otherwise, the package will set the $\mathrm{min}:=v_0=0$ and $\mathrm{max}:=v_p:=v_{p-1}+\gamma=v_3+\gamma$ ($\gamma$ is defined in Definition 4) by default. As an example (for SlopeD), the max is mathematically computed as follows:
\begin{align}
\gamma :=&\;\frac{(v_2-v_1)+(v_3-v_2)}{2}\nonumber\\
=&\;\frac{(2-1)+(3-2)}{2} = 1,
\end{align}
so that
\begin{align}
\mathrm{max}:=&\;v_p:=v_3+\gamma\nonumber\\
=&\;3+\frac{(2-1)+(3-2)}{2}=4.
\end{align}
## Mathematical Formulation
To present it more formally, this section presents the complete definitions of the theory used in the core algorithms of the package.
<br><br>
**Definition 1 (Membership Function)**. Let $\mathscr{X}\subseteq \mathbb{R}$ and $\mathscr{Y}\subseteq \mathbb{R}_{[0,1]}$, then $\mu:\mathscr{X}\rightarrow\mathscr{Y}$ is a *membership function* (MF).
<br>
*Remark 1*. In the context of land evaluation, $\mathscr{X}$ is the space of the parameter values of the input land unit, and $\mathscr{Y}$ is the space of the suitability scores.
<br><br>
**Definition 2 (Class Intervals)**. Let $u_i\in\mathbb{R}, \forall i\in\mathbb{N}_{[0,p-1]}$, then the partitions $[u_i,u_{i+1})\in\mathscr{U}$ are defined as the *suitability class intervals*.
<br><br>
**Definition 3 (Parameter Intervals)**. Let $v_i\in\mathbb{R}, \forall i\in\mathbb{N}_{[0,p-1]}$, then $[v_i,v_{i+1})\in \mathscr{V}$ are defined to be the *crop's parameter intervals*.
<br>
*Remark 2*. $v_i$ is the interval limit of the factor or parameter. $v_0$ and $v_p$ are the minimum and maximum factor limits, respectively, both needs to be computed.
### Triangular Membership Function
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/trimf.jpg")
```
<br><br>
**Definition 4 (Left Triangular)**. Let $x_{jk}\in\mathscr{X}$ be the $j$th land unit's actual value for any target factor $k$, $\forall j \in \mathbb{N}_{[1,n]}$ and $\forall k \in \mathbb{N}_{[1,m]}$, and let $[v_{i},v_{i+1})\in\mathscr{V}$ be the crop's parameter intervals, $\forall i\in\mathbb{N}_{[0,p-1]}$, then the *lower* or *left triangular* MF, herein notated as $\mu_{\triangle_{\downarrow}}$, is defined as follows:
\begin{equation}
\mu_{\triangle_{\downarrow}}(x_{jk}):=
\begin{cases}
\displaystyle\frac{x_{jk}-\mathrm{min}}{\mathrm{max}-\mathrm{min}},&\mathrm{min}\leq x_{jk}\leq\mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases}
\end{equation}
where $\mathrm{min}:= v_0:= v_1-\gamma$, $\mathrm{max}:= v_p:= v_{p-1}+\gamma$, and $\gamma:=\frac{1}{p-2}\sum_{i=1}^{p-2}(v_{i+1}-v_{i})$.
<br>
*Remark 3*. ALUES sets the $\mathrm{min}:=v_0=0$ for all MFs, unless specified by the user explicitly.
**Definition 5 (Right Triangular)**. From Definition 4, the *upper* or *right triangular* MF, herein notated as $\mu_{\triangle_{\uparrow}}$, is defined as follows:
\begin{equation}\label{eq:rtri}
\mu_{\triangle_{\uparrow}}(x_{jk}):=
\begin{cases}
\displaystyle\frac{\mathrm{max}-x_{jk}}{\mathrm{max}-\mathrm{min}},&\mathrm{min}\leq x_{jk}\leq\mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases}.
\end{equation}
**Definition 6 (Full Triangular)**. From Definition 4 and 5, the *full triangular* MF, herein notated as $\mu_{\triangle}$, is defined as follows:
\begin{equation}
\mu_{\triangle}(x_{jk}):=
\begin{cases}
0,&x_{jk}\leq 0\\
\mu_{\triangle_{\downarrow}}(x_{jk}),&\mathrm{min}\leq x_{jk}\leq\mathrm{m}\\
\mu_{\triangle_{\uparrow}}(x_{jk}),&\mathrm{m}<x_{jk}<\mathrm{max}\\
0,&x_{jk}\geq \mathrm{max}
\end{cases}
\end{equation}
where $\mathrm{m}:= \frac{v_{i}^{*}+v_{i+1}^*}{2}$ such that $v_i^*<\mathrm{m}<v_{i+1}^*$, and $v_i^{*}$ and $v_{i+1}^*$ are interval limits right next to m.
### Trapezoidal Membership Function
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/tramf.jpg")
```
<br><br>
**Definition 7 (Left Trapezoidal)**. From Definition 4, the *lower* or *left trapezoidal* MF, herein notated as $\mu_{\bigtriangledown_{\downarrow}}$, is defined as follows:
\begin{equation}
\mu_{\bigtriangledown_{\downarrow}}(x_{jk}):=
\begin{cases}
\displaystyle\frac{x_{jk}-\mathrm{min}}{\mathrm{max}-\mathrm{min}},&\mathrm{min}\leq x_{jk}\leq v_{p-1}\\
1,&v_{p-1}<x_{jk}\leq \mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases},
\end{equation}
where $\mathrm{min},\mathrm{max}$ and $\gamma$ are the same as in Definition 4.
**Definition 8 (Right Trapezoidal)**. From Definition 4, the *upper* or *right trapezoidal* MF, herein notated as $\mu_{\bigtriangledown_{\uparrow}}$, is defined as follows:
\begin{equation}
\mu_{\bigtriangledown_{\uparrow}}(x_{jk}):=\begin{cases}
1,&\mathrm{min}\leq x_{jk}\leq v_1\\
\displaystyle\frac{\mathrm{max}-x_{jk}}{\mathrm{max}-\mathrm{min}},&v_1<x_{jk}\leq\mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases}.
\end{equation}
**Definition 9 (Full Trapezoidal)**. From Definition 7 and 8, the *full trapezoidal* MF, herein notated as $\mu_{\bigtriangledown}$, is defined as follows:
\begin{equation}
\mu_{\bigtriangledown}(x_{jk}):=
\begin{cases}
\mu_{\bigtriangledown_{\downarrow}}(x_{jk}),&\mathrm{min}\leq x_{jk}\leq v_i^*\\
1,&v_i^*<x_{jk}\leq v_{i+1}^*\\
\mu_{\bigtriangledown_{\uparrow}}(x_{jk}),&v_{i+1}^*<x_{jk}\leq\mathrm{max}\\
0,&\mathrm{otherwise}
\end{cases},
\end{equation}
where $v_i^*$ and $v_{i+1}^*$ are defined in Definition 6.
### Gaussain Membership Function
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/gaumf.jpg")
```
<br><br>
**Definition 10 (Gaussian MF)**. From Definition 4, the *full Gaussian* MF, herein notated as $\mu_{\curlywedge}$, is defined as follows:
\begin{equation}
\mu_{\curlywedge}(x_{jk}):=\exp\left[-\frac{(x_{jk}-\alpha)^2}{2\sigma^2}\right],
\end{equation}
where $\alpha\in(-\infty,\infty)$ and $\sigma\in(0,\infty)$.
*Remark 4*. For partial Gaussian MF, however, the adjustment is done using the location hyperparameter. In particular, if $\alpha=\mathrm{min}$, then the model is right Gaussian function. However, if $\alpha=\mathrm{max}$, then the model is left Gaussian function.
### Overall Suitability
**Definition 11 (Overall Suitability)**. Let $y_{jk}\in\mathscr{Y}$ be the $j$th land unit's suitability score for any target factor $k$, $\forall j\in \mathbb{N}_{[1,n]}$ and $\forall k\in\mathbb{N}_{[1,m]}$; and let $w_{k}\in\mathbb{N}_{[1,3]}$ be the weight of the $k$th factor; then, $\mathbf{y}_{j}:=[y_{j1},\cdots,y_{jm}]^{\text{T}}\in\mathbb{R}^m$ is the vector suitability scores of all target factors, and $\mathbf{w}:=[w_1,\cdots,w_m]^{\text{T}}\in\mathbb{N}^m$ is the corresponding weights vector. The *overall suitability using average aggregation*, herein notated as $\bar{\mu}$, of a given land unit is computed as follows:
\begin{equation}\label{eq:overallsuit}
\bar{\mu}(\mathbf{y}_j|\mathbf{w}):= \mathbf{y}_j^{\mathrm{T}}\lambda(\mathbf{w})=\sum_{\forall k}y_{jk}*\lambda (w_k),
\end{equation}
where $\lambda(w_k):= \frac{\eta-w_k}{\delta}, \eta:=\sum_{\forall k} w_k$ and $\delta:=\sum_{\forall k}(\eta - w_k)$. For *minimum* (notated as $\tilde{\mu}$) and *maximum* (notated as $\hat{\mu}$) aggragation functions, the following are the definitions:
\begin{equation}
\tilde{\mu}(\mathbf{y}_j):=\min(\{y_{j1}, \cdots,y_{jm}\}),
\end{equation}
and
\begin{equation}
\hat{\mu}(\mathbf{y}_j):=\max(\{y_{j1}, \cdots,y_{jm}\}).
\end{equation}
### References
* Yen, B., Pheng, K., & Hoanh, C. (2006). LUSET:Land Use Suitability Evaluation Tool User’s Guide.International Rice Research Institute | /scratch/gouwar.j/cran-all/cranData/ALUES/vignettes/a02_theory_of_suit.Rmd |
---
title: "Article 3: Understanding the suit function"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 3: Understanding the suit function}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Introduction
The `suit` function is used for computing the suitability score and class of the land units for a given target crop. The function has the following usage:
```{r, eval=FALSE}
suit(
crop,
terrain = NULL,
water = NULL,
temp = NULL,
mf = "triangular",
sow_month = NULL,
minimum = NULL,
maximum = "average",
interval = NULL,
sigma = NULL
)
```
Check the documentation for details of the arguments. This article will focus on how to use this function. To evaluate the suitability score of Marinduque land units for terrain, soil, water and temperature characteristics, simply run the `suit` function for each of these characteristics. That is,
```{r}
library(ALUES)
banana_suit <- suit("banana", terrain=MarinduqueLT)
names(banana_suit)
```
The warning above simply tells the user that one of the factor, CECc, in the target crop requirement, has parameter intervals for all suitability classes equal to 16, and the package used this value as the maximum constant for computing the suitability scores. For more, please refer to the **Article 2: Methodology used in ALUES** of the documentation.
The `suit` function returns a list of output of target characteristics, in this case `"terrain"` and `"soil"`. To access the output, simply run the following:
```{r, eval=FALSE}
banana_suit[["terrain"]]
banana_suit[["soil"]]
```
Each of these are lists, with the following names:
```{r}
names(banana_suit[["soil"]])
```
So that, to access the factors evaluated, simply run the following:
```{r}
banana_suit[["soil"]][["Factors Evaluated"]]
```
## Targetting Crop
There are 56 crops available in ALUES, and what we've illustrated above are for banana only. Other crops are listed below:
```{r}
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
crop_data
```
These are the names for the input string for the `suit` function. For example, to target sweet potato the input string is not `"sweet potato"` but rather `potatosw`. That is,
```{r, error=TRUE}
potato_suit1 <- suit("sweet potato", terrain=MarinduqueLT)
potato_suit2 <- suit("potatosw", terrain=MarinduqueLT)
```
## Targetting Crop Factors
The idea of evaluating a land unit is to match quality of the land against the standard value of the target factor. Therefore, if the crop does not include the factor you are targeting, then there won't be any matching to be done. For example, the land units evaluated above are those in Marindque, which has the following soil and terrain characteristics:
```{r}
head(MarinduqueLT)
```
The crop that we are trying to target is banana. The `suit` function simply require the user to input a string name for the target crop, and the function will look for the corresponding crop datasets. For example, for banana these are the crop requirements datasets for the four characteristics:
```{r}
BANANATerrain
BANANASoil
BANANAWater
BANANATemp
```
These datasets are used by the `suit` function depending on the specified characteristics of the input land units. So for `banana_suit` object above, the target crop datasets were `BANANATerrain` and `BANANASoil` since the input land unit specified is `terrain=MarinduqueLT`. However, input land unit only targetted the soil factors and not the terrain factors, since none of the factors in `MarinduqueLT` matched with the factors in `BANANATerrain`. That is why, accessing the output for the terrain characteristics for the `banana_suit` object will return the following:
```{r}
banana_suit[["terrain"]]
```
## Targetting Multiple Characteristics
The example above only targetted the terrain and soil characteristics, but the `suit` function allows user to also target water and temp simultaneously. This is done as follows:
```{r}
banana_multi <- suit("banana", terrain=MarinduqueLT, water=MarinduqueWater, temp=MarinduqueTemp, sow_month=2)
names(banana_multi)
```
It is necessary to specify the sowing month when specifying the water and temperature characteristics of the input land units. In this case, we are saying that the first sowing month for both water and temperature characteristics correspond to February. No factors were targetted by input land unit for banana for terrain, water and temperature characteristics.
```{r}
banana_suit[["terrain"]]
banana_suit[["water"]]
banana_suit[["temp"]]
lapply(banana_suit[["soil"]], function(x) head(x))
```
Only the head (first six) of the output of the items in the soil characteristics are shown.
## Membership Function
There are three membership functions (MFs) available in the `suit` function, namely *triangular*, *trapezoidal* and *Gaussian*. For example, the following computes the suitability scores and classes using trapezoidal MF.
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal")
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
```
## Intervals
Another option available in the `suit` function is the `interval`. By default, ALUES uses an equally spaced suitability class intervals for deriving the suitability class. That is, for N [0, 0.25), S3 [0.25, 0.50), S2 [0.50, 0.75), and S1 [0.75, 1].
### Custom Intervals
Users can modify the default equally spaced intervals, for example:
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval=c(0, 0.3, 0.6, 0.9, 1))
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
```
The above code sets the new suitability class intervals into: N [0, 0.3), S3 [0.3, 0.6), S2 [0.6, 0.9), and S1 [0.9, 1].
### Unbias Intervals
The problem with the fixed interval is that the said intervals does not take into account the shape of the membership function and the spacing of the parameter interval limits (*See* Article 2 for parameter intervals). Custom intervals might be able to capture this if the user computed the interval limits manually, but ALUES provides an option just for this, by setting `interval="unbias"`. That is,
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval="unbias")
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
```
By setting the `interval="unbias"`, the `suit` function will generate a different likely unequally spaced suitability class intervals, but the interval limits are mathematically correct, in terms of the mapping of the parameter interval limits to suitability class limits via the membership function.
## Maximum and Minimum
Another parameter that can be set for `suit` are the `minimum` and `maximum`. These are the constants used by the membership function for computing the suitability score.
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval="unbias")
banana_suit[["soil"]][["Factors Evaluated"]]
```
From the above result, there are four factors targetted by the input land unit, these are CFragm, CECc, pHH2O and SoilTe. Suppose we know the maximum value that these factors can take, say 60 for CFragm, 20 for CECc, 9 for pHH2O, and 10 for SoilTe. We can specify these as follows:
```{r}
banana_suit <- suit("banana", terrain=MarinduqueLT, mf="trapezoidal", interval="unbias", maximum=c(60, 20, 9, 10))
banana_suit
```
The result gave us an error. We understand the error for terrain characteristics, but for soil it says the argument maximum must be equal in length with the target factors specified in the input land units dataset. We know that there should be 4 factors, but upon checking we see that the `MarinduqueLT` also have Lon and Lat columns, which ALUES assumes to be a target factor as well. Indeed, we need to exclude these columns (those that are not the target factors) when specifying `minimum` or `maximum` constants. Thus, it should be:
```{r}
MarinduqueLT2 <- MarinduqueLT[, 3:ncol(MarinduqueLT)]
banana_suit <- suit("banana", terrain=MarinduqueLT2, mf="trapezoidal", interval="unbias", maximum=c(60, 20, 9, 10))
head(banana_suit[["soil"]][["Suitability Score"]])
head(banana_suit[["soil"]][["Suitability Class"]])
```
## Sigma of Gaussian
The `sigma` argument is used to specify scale of the Gaussian membership function. That is, it is only applicable for `mf="gaussian"`. | /scratch/gouwar.j/cran-all/cranData/ALUES/vignettes/a03_understanding_suit.Rmd |
---
title: "Article 4: Understanding the overall_suit function"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 4: Understanding the overall_suit function}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
The overall suitability can be computed using the `overall_suit` function, which takes an object of class suitability. For example,
```{r}
library(ALUES)
banana_suit <- suit("banana", terrain=MarinduqueLT)
class(banana_suit[["terrain"]])
class(banana_suit[["soil"]])
```
There are no factors that were targetted for the terrain characteristics, hence the returned value is a string error. Thus, only the soil characteristics can have an overall suitability, and is computed as follows:
```{r}
ovsuit <- overall_suit(banana_suit[["soil"]])
head(ovsuit)
```
By default, the `overall_suit` function uses minimum as a summary statistics, hence the 0 scores and N classes across land units. To adjust this to average aggregation, use the `method` argument to specify.
```{r}
ovsuit <- overall_suit(banana_suit[["soil"]], method="average")
head(ovsuit)
```
## Intervals
By default, the `overall_suit` uses an equally spaced interval for the suitability classes, that is, N [0, 0.25), S3 [0.25, 0.50), S2 [0.50, 0.75), and S1 [0.75, 1]. This can be changed using the `interval` argument, for example
```{r}
ovsuit <- overall_suit(banana_suit[["soil"]], method="average", interval=c(0, 0.6, 0.7, 0.9, 1))
head(ovsuit)
```
The above code sets the suitability class intervals into: N [0, 0.60), S3 [0.60, 0.70), S2 [0.70, 0.90), and S1 [0.90, 1]. It should be emphasized that the `interval` argument cannot be set to `unbias` as in the case of the `interval` argument of the `suit` function. This follows from the fact that the `overall_suit` function is not using a membership function for computing the score, but an aggregation function. | /scratch/gouwar.j/cran-all/cranData/ALUES/vignettes/a04_understanding_overall_suit.Rmd |
---
title: "Article 5: Custom input land units"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 5: Custom input land units}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
ALUES comes with two datasets for input land units. These are the land units of Marinduque, Philippines; and, Lao Cai, Vietnam. However, users will likely have their own region of interest. As such, this article will illustrate how to prepare the data.
For any region of interest, users must specify the properties of the land units into three categories:
- terrain and soil
- water
- temperature
Note that both terrain and soil factors must be specified as one dataframe, not separate. Suppose there are 5 units under study, the three characteristics can be specified as follows:
## Terrain and soil
Suppose for terrain, we want to target the following factors: Flood and SlopeD; and, suppose for soil we have CFragm and SoilDpt. The dataframe can be prepared as follows:
```{r}
terrain_input <- data.frame(
Flood = c(1, 2, 2, 2, 3),
SlopeD = c(3, 4, 5, 1, 2),
CFragm = c(10, 30, 50, 60, 40),
SoilDpt = c(45, 60, 90, 70, 30)
)
```
**Note: the column names must be the same with the naming convention used by the crop requirements datasets.**
So that, if this input is assessed for avocado, then the suitability score for these land units are computed as follows:
```{r}
library(ALUES)
AVOCADOTerrain
AVOCADOSoil
avocado_suit <- suit("avocado", terrain=terrain_input)
head(avocado_suit[["terrain"]][["Suitability Score"]])
head(avocado_suit[["terrain"]][["Suitability Class"]])
head(avocado_suit[["soil"]][["Suitability Score"]])
head(avocado_suit[["soil"]][["Suitability Class"]])
```
## Water
For water characteristics, suppose the average rainfall for 3 land units were recorded for four months with the following data:
```{r}
water_input <- data.frame(
Apr = c(150, 140, 120),
May = c(70, 90, 100),
Jun = c(85, 90, 105)
)
water_input
```
Note that when specifying the factors for water chacteristics, the month must be specified in three characters (correct case) only, that is, it shouldn't be specified as January, February, etc.
The suitability scores for rainfed bunded rice water requirement are computed as follows:
```{r}
RICEBRWater
water_suit <- suit("ricebr", water=water_input, sow_month=1)
water_suit
```
Setting the `sow_month=1` indicates that the factors for `RICEBRWater`'s `WmAv1` correspond to January, `WmAv2` to February, `WmAv3` to March, and `WmAv4` to April. Thus, the only factors that were targetted by the `water_input` is April. So that, setting the `sow_month=3`, would make `WmAv1` of `RICEBRWater` as March, `WmAv2` as April, etc. This in turn targets the months April to Jun.
```{r}
water_suit <- suit("ricebr", water=water_input, sow_month=3)
water_suit
```
## Temperature
Another characteristics that can be targetted is the temperature.
```{r}
temp_input <- data.frame(
Sep = c(34.2, 35.5, 33.4),
Oct = c(32.5, 34.2, 32.0),
Nov = c(30.3, 32.2, 31.1)
)
RICEBRTemp
temp_suit <- suit("ricebr", temp=temp_input, sow_month=9)
```
The `RICEBRTemp` crop requirement has factor `TmAv2`, which is the mean temperature for the 2nd month. Thus, setting the sowing month to 9 suggest that the sowing month started at September, and thus sets `TmAv2` to October. Hence, the factor that was targetted by the input land units is the October as seen below:
```{r}
temp_suit
``` | /scratch/gouwar.j/cran-all/cranData/ALUES/vignettes/a05_custom_land_units_input.Rmd |
---
title: "Article 6: Custom crop requirements input"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 6: Custom crop requirements input}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
As already emphasized in Article 2, the following are the crop datasets available in ALUES:
```{r}
d <- utils::data(package = "ALUES")
alues_data <- d$results[, "Item"]
crop_data <- regmatches(alues_data, gregexpr(paste0("^[A-Z]{2,}", collapse = "|"), alues_data))
crop_data <- unique(unlist(lapply(crop_data, function(x) substr(x, 1, nchar(x)-1))))
crop_data
```
In cases were the target crop is not available in the ALUES database, users can specify their own by following the template of a crop requirement dataset. For example,
```{r}
library(ALUES)
COFFEEARSoil
```
The above data frame shows us the first column as the code of the target factors, and the remaining of the columns are the suitability classes with the last column for the weights if any.
## Crop Characteristics
It should be noted that apart from the proper templating of the dataframe for any new target crop, the categorization of the characteristics must be observed as well. That is, for any new crop, the four characteristics: terrain, soil, water, and temp, must be encoded separately as one dataframe. That is, for any target crop there will be four dataframes to expect for the four characteristics mentioned.
## Creating from a template
To create a custom crop dataset, use the following code to generate an empty row data frame with the appropriate column name
```{r}
new_crop <- data.frame(matrix(nrow=0, ncol=ncol(COFFEEARSoil)))
names(new_crop) <- names(COFFEEARSoil)
new_crop
```
Needless to say, any ALUES crop dataset can be used above in place of `COFFEEARSoil`, since all crop datasets have the same column names.
Next is to enter the name of the factors in the first column, and then the corresponding standard values for suitability classes. Suppose for example, the new crop demands a factor CFragm to be S3 (marginally suitable) if it is 60, S2 if it is 40, and S1 if it is 20; then this can be entered as follows:
```{r}
new_crop[1, "code"] <- "CFragm"
new_crop[1, 2:4] <- c(60, 40, 20)
new_crop
```
New factors can be added further in the succeeding rows, say for row 2 we have pHH2O with the following data
```{r}
new_crop[2, "code"] <- "pHH2O"
new_crop[2, 2:7] <- c(4.5, 5.0, 5.1, 5.6, 6.2, 6.9)
new_crop
```
Adding weight to pHH2O is done as follows:
```{r}
new_crop[2, "wts"] <- 2
new_crop
```
Now suppose we want to evaluate Marinduque land units for this new crop, we can do this as follows:
```{r}
newcrop_suit <- suit(new_crop, terrain=MarinduqueLT)
lapply(newcrop_suit[["terrain"]], function (x) head(x))
``` | /scratch/gouwar.j/cran-all/cranData/ALUES/vignettes/a06_custom_crop_input.Rmd |
---
title: "Article 7: Visualizing with maps"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Article 7: Visualizing with maps}
%\usepackage[UTF-8]{inputenc}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
While ALUES can generate tables for suitability scores and classes, it would be best to visualize it via maps. The main requirement of course is the availability of the longitude and latitude for each of the land units. This is possible for Marinduque as it has spatial variables (longitude and latitude).
## Suitability scores and classes
Suppose we want to evaluate the land units for banana, then:
```{r}
library(ALUES)
y <- MarinduqueLT
banana_suit <- suit("banana", terrain=y)
banana_ovsuit <- overall_suit(banana_suit[["soil"]], method="average")
```
## Generate maps
There are several ways to generate maps in R, but the following uses ggmap library:
```{r, eval=FALSE}
library(ggmap)
library(raster)
library(reshape2)
map_lvl0 <- getData("GADM", country = "PHL", level = 0)
map_lvl2 <- getData("GADM", country = "PHL", level = 2)
prov <- map_lvl2[map_lvl2$NAME_1 == as.character("Marinduque"),]
munic_coord <- coordinates(prov)
munic_coord <- data.frame(munic_coord)
munic_coord$label <- prov@data$NAME_2
val <- banana_suit[["soil"]][[2]]
val["Overall Suitability"] <- banana_ovsuit[,1]
d_map <- melt(as.matrix(val))
d_map$Lon <- rep(y$Lon, ncol(val)); d_map$Lat <- rep(y$Lat, ncol(val))
fill <- "#FFF7BC"; shadow <- "#9ECAE1"; ncol <- 3; size <- 3; alpha <- 1
text_opts <- list(alpha = 1, angle = 0, colour = "black", family = "sans", fontface = 1, lineheight = 1, size = 3)
labels <- list(title = "", xlab = "", ylab = "")
p1 <- ggplot() + geom_polygon(data = prov, aes(long + 0.008, lat - 0.005, group = group), fill = shadow) +
geom_polygon(data = prov, aes(long, lat, group = group), colour = "grey50", fill = fill) +
geom_tile(aes(x = Lat, y = Lon, fill = value), data = d_map, size = size, alpha = alpha) +
facet_wrap(~ Var2, ncol = ncol) +
geom_polygon(data = prov, aes(long, lat, group = group), colour = "#4E4E4C", alpha = 0) +
geom_label(data = munic_coord, aes(x = X1, y = X2, label = label), alpha = 0.5,
angle = text_opts$angle, colour = "white", fill = "black", family = text_opts$family,
fontface = text_opts$fontface,
lineheight = text_opts$lineheight, size = text_opts$size) +
coord_equal() + ggtitle(as.character(labels$title)) + xlab(as.character(labels$xlab)) + ylab(as.character(labels$ylab)) +
scale_fill_gradientn(name = "Score\n", colors = c("red", "#FFDF00")) +
scale_x_continuous(breaks = round(seq(min(d_map$Lat) + 0.05, max(d_map$Lat), len = 3), 2)) +
theme(panel.background = element_rect(fill = '#F7E7CE'),
strip.background = element_rect(fill = "#D4BF96"),
strip.text.x = element_text(size = 12),
axis.text.x = element_text(size=12),
legend.text=element_text(size=12),
legend.title=element_text(size=12),
axis.text.y = element_text(size=12), legend.position = c(0.85, 0.25))
p1
```
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/scores1.jpg")
```
And for suitability classes:
```{r, eval=FALSE}
val <- banana_suit[["soil"]][[3]]
val["Overall Suitability"] <- banana_ovsuit[,2]
d_map <- melt(as.matrix(val))
d_map$Lon <- rep(y$Lon, ncol(val)); d_map$Lat <- rep(y$Lat, ncol(val))
d_map$Class <- factor(d_map$value, levels=c("N", "S3", "S2", "S1"))
p1 <- ggplot() + geom_polygon(data = prov, aes(long + 0.008, lat - 0.005, group = group), fill = shadow) +
geom_polygon(data = prov, aes(long, lat, group = group), colour = "grey50", fill = fill) +
geom_tile(aes(x = Lat, y = Lon, fill = Class), data = d_map, size = size, alpha = alpha) +
facet_wrap(~ Var2, ncol = ncol) +
geom_polygon(data = prov, aes(long, lat, group = group), colour = "#4E4E4C", alpha = 0) +
geom_label(data = munic_coord, aes(x = X1, y = X2, label = label), alpha = 0.5,
angle = text_opts$angle, colour = "white", fill = "black", family = text_opts$family,
fontface = text_opts$fontface,
lineheight = text_opts$lineheight, size = text_opts$size) +
coord_equal() + ggtitle(as.character(labels$title)) + xlab(as.character(labels$xlab)) + ylab(as.character(labels$ylab)) +
scale_colour_discrete(name = "Class\n", breaks=c("N", "S3", "S2", "S1"), labels=c("N", "S3", "S2", "S1")) +
scale_x_continuous(breaks = round(seq(min(d_map$Lat) + 0.05, max(d_map$Lat), len = 3), 2)) +
theme(panel.background = element_rect(fill = '#F7E7CE'),
strip.background = element_rect(fill = "#D4BF96"),
strip.text.x = element_text(size = 12),
axis.text.x = element_text(size=12),
legend.text=element_text(size=12),
legend.title=element_text(size=12),
axis.text.y = element_text(size=12), legend.position = c(0.85, 0.25))
p1
```
```{r, out.width="100%", echo=FALSE}
knitr::include_graphics("../vignettes/img/classes1.jpg")
``` | /scratch/gouwar.j/cran-all/cranData/ALUES/vignettes/a07_visual_maps.Rmd |
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
fun_hcross <- function(x) {
.Call('_ALassoSurvIC_fun_hcross', PACKAGE = 'ALassoSurvIC', x)
}
fun_subless <- function(u, lessthan) {
.Call('_ALassoSurvIC_fun_subless', PACKAGE = 'ALassoSurvIC', u, lessthan)
}
fun_sublr <- function(u, l, r) {
.Call('_ALassoSurvIC_fun_sublr', PACKAGE = 'ALassoSurvIC', u, l, r)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/RcppExports.R |
alacoxIC <- function(...) UseMethod("alacoxIC")
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/alacoxIC.R |
alacoxIC.default <- function(lowerIC, upperIC, X, trunc, theta, normalize.X = TRUE, cl = NULL, max.theta = 1e3, tol = 1e-3, niter = 1e5, string.cen = Inf, string.missing = NA, ...) {
match.call()
if(missing(trunc)) {
trunc <- NULL
ind.trunc <- FALSE
smallest.trunc <- 0
} else {
ind.trunc <- TRUE
smallest.trunc <- min(trunc)
}
if(missing(theta)) {
theta <- NULL
user.theta <- FALSE
} else {
user.theta <- TRUE
}
if(!any(is.numeric(theta), is.null(theta))) stop("The input for 'theta' is not numeric.")
if (!is.null(cl)) {
if (.Platform$OS.type == "windows") {
if (!inherits(cl, "cluster"))
cl <- NULL
} else {
if (inherits(cl, "cluster")) {
if (length(cl) < 2L)
cl <- NULL
} else {
if (cl < 2)
cl <- NULL
}
}
}
xnames <- colnames(X)
arglist <- fun_arglist(lowerIC, upperIC, X, trunc, normalize.X, tol, niter)
arglist$initial_lambda <- rep(1/nrow(arglist$set), nrow(arglist$set))
message(" Now: obtaining the unpenalized NPMLE")
initial <- fun_unpenSurvIC(rep(0, ncol(arglist$z)), arglist)
tilde_b <- initial$b
arglist$initial_lambda <- initial$lambda
if (is.null(theta)) {
bic_b_cvg <- fun_est_parallel(max.theta, tilde_b, arglist, cl)
} else {
message(" Now: estimating beta with the user input theta")
bic_b_cvg <- fun_penSurvIC(theta = theta, tilde_b, arglist)
can_b <- bic_b_cvg$b
log_pen <- log_penlikelihood(can_b, arglist)
n <- arglist$n
bic_b_cvg$bic <- -2 * log_pen + log(n) * sum(can_b != 0)
}
final.b.BIC <- bic_b_cvg$b
final.theta <- bic_b_cvg$theta
final.bic <- bic_b_cvg$bic
final.lambda <- bic_b_cvg$lambda
message(" Now: calculating the covariance matrix")
cov <- fun_cov_parallel(b = final.b.BIC, theta = final.theta, var.h = 5, arglist, cl)
message(" Done.")
if (!is.null(cl)) stopCluster(cl)
if (normalize.X == TRUE) {
atrue_sd <- arglist$true_sd
atrue_mu <- arglist$true_mu # added
final.b <- final.b.BIC/atrue_sd
final.cov <- cov / (atrue_sd %*%t(atrue_sd))
final.lambda <- final.lambda/exp(sum(final.b * atrue_mu)) # added
} else {
final.b <- final.b.BIC
final.cov <- cov
}
results <- list()
results$xnames <- xnames
results$n <- nrow(X)
results$b <- final.b
results$se <- sqrt(diag(final.cov))
results$cov <- final.cov
results$theta <- final.theta
results$user.theta <- user.theta
results$bic <- final.bic
results$lambda <- final.lambda
results$lambda.set <- arglist$set
results$unpen.b <- tilde_b
results$convergence <- bic_b_cvg$convergence
results$iteration <- bic_b_cvg$iteration
results$ind.trunc <- ind.trunc
results$smallest.trunc <- smallest.trunc
results$normalize.X <- normalize.X
class(results) <- "alacoxIC"
return(results)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/alacoxIC.default.R |
baseline <- function(...) UseMethod("baseline")
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/baseline.R |
baseline.default <- function(object, ...) {
match.call()
if(!(class(object) %in% c("alacoxIC", "unpencoxIC"))) stop("Please input the object returned by 'alacoxIC' or 'unpencoxIC'.")
lambda <- object$lambda
nlambda <- length(lambda)
lambda.set <- object$lambda.set
result <- data.frame(lambda.set, lambda, cumsum(lambda))
colnames(result) <- c("lower.set", "upper.set", "lambda", "clambda")
class(result) <- "baseline"
return(result)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/baseline.default.R |
canon <- function(x, len) {
xx <- rep(0, len)
xx[x] <- 1
xx
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/canon.R |
fun_arglist <- function(lowerIC, upperIC, X, trunc, normalize, tol, niter) {
l <- as.numeric(lowerIC)
r <- as.numeric(upperIC)
if(!is.null(trunc)) trunc <- as.numeric(trunc)
n <- length(l)
lr <- cbind(l, r)
X <- as.matrix(X)
true_mu <- colMeans(X) #added
if (normalize == TRUE) {
z <- apply(X,2, function(x) (x-mean(x))/sqrt(sum((x-mean(x))^2)/n))
true_sd <- sqrt(apply(X,2,var)*(n-1)/n)
} else {
z <- X
true_sd <- 1
}
if (is.null(trunc)) {
olr <- order(c(l + 1e-10, r))
int0 <- rbind(cbind(0, l), cbind(1, r))[olr,]
} else {
olr <- order(c(l + 1e-10, r, trunc - 1e-10))
int0 <- rbind(cbind(0, l), cbind(1, r), cbind(1, trunc))[olr,]
}
int <- cbind(cbind(int0[-nrow(int0), 1], c(int0[-1, 1])), cbind(int0[-nrow(int0), 2], c(int0[-1, 2])))
set0 <- int[(int[, 1]==0)&(int[, 2]==1),c(3,4)]
set <- set0[!is.infinite(rowSums(set0)), ]
args <- list()
args$l <- l
args$r <- r
args$trunc <- trunc
args$n <- n
args$z <- z
args$true_mu <- true_mu # added
args$true_sd <- true_sd
args$set <- set
args$tol <- tol
args$niter <- niter
return(args)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_arglist.R |
fun_bic <- function(x, tilde_b, arglist, tol) {
if(missing(tol)) tol <- arglist$tol
can_results <- fun_penSurvIC(theta = x, tilde_b, arglist, tol)
can_b <- can_results$b
can_convergence <- can_results$convergence
log_pen <- log_penlikelihood(can_b, arglist)
n <- arglist$n
bic_value <- -2 * log_pen + log(n) * sum(can_b != 0)
return(c(bic_value, can_convergence, can_b))
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_bic.R |
fun_cov_parallel <- function(b, theta, var.h, arglist, cl) {
n <- arglist$n
length_b <- length(b)
profile_hess <- matrix(NA, length_b, length_b)
bone <- matrix(NA, nrow = length_b*(length_b+1)/2, ncol = 2)
com_ele <- 1
for ( ej in 1:length_b) {
for (ek in 1:ej) {
bone[com_ele,] <- c(ej, ek)
com_ele <- com_ele + 1
}
}
h <- var.h * n^(-1/2)
if (is.null(cl)) {
vbone <- t(apply(bone, 1, fun_covij, b = b, length_b = length_b, h = h, arglist = arglist))
} else {
lbone <- split(bone, row(bone))
if (inherits(cl, "cluster")) {
parallel_fun <- if (isTRUE(getOption("pboptions")$use_lb)) parLapplyLB else parLapply
vbone0 <- parallel_fun(cl, lbone, fun_covij, b = b, length_b = length_b, h = h, arglist = arglist)
} else {
vbone0 <- mclapply(lbone, fun_covij, b = b, length_b = length_b, h = h, arglist = arglist)
}
vbone <- t(sapply(vbone0, function(x) x))
}
for (i in 1:nrow(bone)) {
profile_hess[vbone[i,1], vbone[i,2]] <- vbone[i,3]
}
profile_hess[upper.tri(profile_hess)] <- t(profile_hess)[upper.tri(profile_hess)]
#variance computation
vbeta <- abeta <- numeric(length_b)
abeta[abs(b) > 0] <- 1/abs((b[abs(b) > 0])^2)
abeta[b == 0] <- 10e10
part1 <- profile_hess + diag(n*theta*abeta)
inv_part1 <- solve(part1)
vbeta[abs(b) > 0] <- 1/abs((b[abs(b) > 0])^2)
vbeta[b == 0] = 0.0
part2 <- profile_hess + diag(n*theta*vbeta)
inv_hess <- solve(profile_hess)
cov <- inv_part1 %*% part2 %*% inv_hess %*% part2 %*% inv_part1
return(cov)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_cov_parallel.R |
fun_covij <- function(x, b, length_b, h, arglist) {
ej <- x[1]
ek <- x[2]
b_ej <- b + h*canon(ej, len = length_b)
b_ek <- b + h*canon(ek, len = length_b)
b_ej_ek <- b + h*canon(ek, len = length_b) + h*canon(ej, len = length_b)
pen_lik_b <- log_penlikelihood(b, arglist)
if (ej == ek) {
pen_lik_b_ek <- pen_lik_b_ej <- log_penlikelihood(b_ej, arglist)
} else {
pen_lik_b_ej <- log_penlikelihood(b_ej, arglist)
pen_lik_b_ek <- log_penlikelihood(b_ek, arglist)
}
pen_lik_b_ej_ek <- log_penlikelihood(b_ej_ek, arglist)
value <- - (pen_lik_b_ej_ek - pen_lik_b_ej - pen_lik_b_ek + pen_lik_b)/h^2
return(c(ej, ek, value))
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_covij.R |
fun_ddq <- function(b, ew, arglist) {
l <- arglist$l
r <- arglist$r
lr <- cbind(l, r)
u <- arglist$set[,2]
n <- arglist$n
z <- arglist$z
len_z <- ncol(z)
trunc <-arglist$trunc
zb <- z %*% b
exp_zb <- exp(z %*% b)
r_star <- r
r_star[is.infinite(r)] <- l[is.infinite(r)]
# target_set <- fun_subless(u = u, lessthan = r_star)
if (is.null(trunc)) {
target_set <- fun_subless(u = u, lessthan = r_star)
} else {
target_set <- fun_sublr(u = u, l = trunc-1e-10, r = r_star)
}
zero_part <- target_set * ew
first_part1 <- t(fun_hcross(z) %*% (target_set * as.numeric(exp_zb)))
first_part2 <- fun_hcross(t(target_set * as.numeric(exp_zb)) %*% z)
second_part <- colSums(target_set * as.numeric(exp_zb))
cvalue_temp1 <- - first_part1/second_part + t(first_part2)/(second_part^2)
cvalue <- zero_part %*% cvalue_temp1
value <- matrix(0, len_z, len_z)
value[upper.tri(value, diag = TRUE)] <- colSums(cvalue)
value[lower.tri(value)] <- t(value)[lower.tri(value)]
return(value)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_ddq.R |
fun_dq <- function(b, ew, arglist) {
l <- arglist$l
r <- arglist$r
lr <- cbind(l, r)
u <- arglist$set[,2]
n <- arglist$n
z <- arglist$z
trunc <-arglist$trunc
zb <- z %*% b
exp_zb <- exp(z %*% b)
r_star <- r
r_star[is.infinite(r)] <- l[is.infinite(r)]
# target_set <- fun_subless(u = u, lessthan = r_star)
if (is.null(trunc)) {
target_set <- fun_subless(u = u, lessthan = r_star)
} else {
target_set <- fun_sublr(u = u, l = trunc-1e-10, r = r_star)
}
zero_part <- target_set * ew
first_part <- t(target_set * as.numeric(exp_zb)) %*% z
second_part <- colSums(target_set * as.numeric(exp_zb))
value <- colSums(zero_part %*% (- first_part/second_part) + rowSums(zero_part)*z)
return(value)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_dq.R |
fun_est_parallel <- function(max.theta, tilde_b, arglist, cl) {
raw.max.theta <- max.theta1 <- 10^ceiling(log(max.theta, base = 10))
theta.dec <- 1
seq.theta <- ceiling(seq(from = max.theta1, to = 0, by = - max.theta1/10))
stop.rule <- 1
depth <- 1
while (stop.rule >= 1) {
several.fits <- fun_penSurvIC(theta = seq.theta[depth], tilde_b, arglist, tol = 0.01)$b
if(any(several.fits != 0)) {
if(depth == 1) stop("Please increase 'max.theta1'.")
max.theta1 <- seq.theta[depth - 1]
min.theta <- seq.theta[depth]
seq.theta <- seq(from = max.theta1, to = min.theta, by = -raw.max.theta/(10^(theta.dec+1)))
stop.rule <- raw.max.theta/(10^(theta.dec + 1))
theta.dec <- theta.dec + 1
depth <- 1
} else {
depth <- depth + 1
}
}
upper.theta <- max.theta1
e <- 0.0001; rr <- 100
lower.theta <- e * upper.theta
set.theta <- upper.theta*(lower.theta/upper.theta)^((0:rr)/rr)
set.theta <- matrix(set.theta, ncol = 1)
if (is.null(cl)) {
bic_b <- t(apply(set.theta, 1, fun_bic, tilde_b = tilde_b, arglist = arglist, tol = 0.01))
} else {
if (inherits(cl, "cluster")) {
parallel_fun <- if (isTRUE(getOption("pboptions")$use_lb)) parLapplyLB else parLapply
bic_b0 <- parallel_fun(cl, set.theta, fun_bic, tilde_b = tilde_b, arglist = arglist, tol = 0.01)
} else {
bic_b0 <- mclapply(set.theta, fun_bic, tilde_b = tilde_b, arglist = arglist, tol = 0.01)
}
bic_b <- t(sapply(bic_b0, function(x) x))
}
o.bic <- which.min(bic_b[,1])
final.bic <- bic_b[o.bic, 1]
final.theta <- set.theta[o.bic]
results <- fun_penSurvIC(final.theta, tilde_b, arglist)
results$bic <- final.bic
return(results)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_est_parallel.R |
fun_ew <- function(b, lambda, arglist) {
l <- arglist$l
r <- arglist$r
lr <- cbind(l, r)
u <- arglist$set[,2]
z <- arglist$z
exp_zb <- exp(z %*% b)
lambda_exp_zb <- exp_zb %*% t(lambda)
target_set <- fun_sublr(u = u, l = l, r = r)
denom <- 1 - exp(-rowSums(lambda_exp_zb * target_set))
ew <- target_set * lambda_exp_zb/denom
ew[is.infinite(r), ] <- 0
return(ew)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_ew.R |
fun_less <- function(x, ...) {
nx <- as.numeric(x)
ax <- c()
for (i in 1:length(x)) {
ax[i] <- ifelse(nx[i] < 1e-04, paste("<0.0001"), x[i])
}
return(ax)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_less.R |
fun_penSurvIC <- function(theta, tilde_b, arglist, tol) {
n <- arglist$n
npmle_set <- arglist$set
u <- npmle_set[,2]
if(missing(tol)) tol <- arglist$tol
niter <- arglist$niter
old_b <- tilde_b
old_lambda <- arglist$initial_lambda
all_b_info <- old_b
all_lambda_info <- old_lambda
all_distance <- NA
distance <- tol + 1000
iter <- 0
while ((distance > tol) & (iter < niter)) {
ew <- fun_ew(old_b, old_lambda, arglist)
neg_gradient <- fun_dq(old_b, ew, arglist) * (-1)
neg_hess <- fun_ddq(old_b, ew, arglist) * (-1)
x <- chol(neg_hess)
y <- solve(t(x)) %*% (as.numeric(neg_hess %*% old_b) - neg_gradient)
new_b <- fun_shooting_algorithm(x, y, theta, tilde_b, arglist)
new_lambda <- fun_updatelambda(new_b, ew, arglist)
distance <- max(abs(c(new_b, new_lambda) - c(old_b, old_lambda)))
all_b_info <- rbind(all_b_info, new_b)
all_lambda_info <- rbind(all_lambda_info, new_lambda)
all_distance <- c(all_distance, distance)
old_b <- new_b
old_lambda <- new_lambda
iter <- iter + 1
}
results <- list()
results$b <- new_b
results$lambda <- new_lambda
results$theta <- theta
results$iteration <- iter
results$convergence <- ifelse(iter < niter, TRUE, FALSE)
results$distance <- distance
results$tol <- tol
results$niter <- niter
return(results)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_penSurvIC.R |
fun_shooting_algorithm <- function(x, y, theta, tilde_b, arglist) {
xx <- t(x)%*%x
xy <- t(x)%*%y
z <- arglist$z
num_p <- ncol(z)
tol <- arglist$tol
niter <- arglist$niter
old_b <- tilde_b
temp_b <- old_b
weighted_theta <- theta/abs(tilde_b)
distance <- tol + 1000
iter <- 1
while ((distance > tol) & (iter < niter)) {
for (p in 1:num_p) {
ss2 <- 2*(sum(temp_b*xx[,p]) - temp_b[p]*xx[p,p] - xy[p])
if (ss2 > weighted_theta[p]) temp_b[p] <- (weighted_theta[p] - ss2)/(2*xx[p,p])
if (ss2 < -weighted_theta[p]) temp_b[p] <- (-weighted_theta[p] - ss2)/(2*xx[p,p])
if (abs(ss2) <= weighted_theta[p]) temp_b[p] <- 0
}
distance <- max(abs(temp_b - old_b))
old_b <- temp_b
iter <- iter + 1
}
return(temp_b)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_shooting_algorithm.R |
fun_unpenSurvIC <- function(b, arglist) {
n <- arglist$n
npmle_set <- arglist$set
tol <- arglist$tol
niter <- arglist$niter
old_b <- b
old_lambda <- arglist$initial_lambda
all_b_info <- old_b
all_lambda_info <- old_lambda
all_distance <- NA
distance <- tol + 1000
iter <- 0
while ((distance > tol) & (iter < niter)) {
ew <- fun_ew(old_b, old_lambda, arglist)
neg_gradient <- fun_dq(old_b, ew, arglist) * (-1)
neg_hess <- fun_ddq(old_b, ew, arglist) * (-1)
x <- chol(neg_hess)
y <- solve(t(x)) %*% (as.numeric(neg_hess %*% old_b) - neg_gradient)
new_b <- as.numeric(solve(t(x)%*%x)%*%t(x)%*%y)
new_lambda <- fun_updatelambda(new_b, ew, arglist)
distance <- max(abs(c(new_b, new_lambda) - c(old_b, old_lambda)))
all_b_info <- rbind(all_b_info, new_b)
all_lambda_info <- rbind(all_lambda_info, new_lambda)
all_distance <- c(all_distance, distance)
old_b <- new_b
old_lambda <- new_lambda
iter <- iter + 1
}
results <- NULL
results <- list()
results$b <- new_b
results$lambda <- new_lambda
results$iteration <- iter
results$convergence <- ifelse(iter < niter, TRUE, FALSE)
results$distance <- distance
results$tol <- tol
results$niter <- niter
return(results)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_unpenSurvIC.R |
fun_updatelambda <- function(b, ew, arglist) {
l <- arglist$l
r <- arglist$r
u <- arglist$set[,2]
z <- arglist$z
trunc <-arglist$trunc
exp_zb <- exp(z %*% b)
r_star <- r
r_star[is.infinite(r)] <- l[is.infinite(r)]
# target_set <- fun_subless(u = u, lessthan = r_star)
if (is.null(trunc)) {
target_set <- fun_subless(u = u, lessthan = r_star)
} else {
target_set <- fun_sublr(u = u, l = trunc-1e-10, r = r_star)
}
numer <- colSums(target_set * ew)
denom <- colSums(target_set * as.numeric(exp_zb))
update_lambda <- numer/denom
return(update_lambda)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/fun_updatelambda.R |
log_penlikelihood <- function(b, arglist) {
n <- arglist$n
npmle_set <- arglist$set
u <- npmle_set[,2]
l <- arglist$l
r <- arglist$r
r_cen <- is.infinite(r)
lr <- cbind(l, r)
z <- arglist$z
trunc <- arglist$trunc
tol <- arglist$tol
niter <- arglist$niter
distance <- tol + 1000
iter <- 1
old_lambda <- arglist$initial_lambda
while ((distance > tol) & (iter < niter)) {
ew <- fun_ew(b, old_lambda, arglist)
new_lambda <- fun_updatelambda(b, ew, arglist)
distance <- max(abs(new_lambda - old_lambda))
old_lambda <- new_lambda
iter <- iter + 1
}
exp_zb <- exp(z %*% b)
lambda_exp_zb <- exp_zb %x% t(new_lambda)
if (is.null(trunc)) {
target_set1 <- fun_subless(u = u, lessthan = l)
} else {
target_set1 <- fun_sublr(u = u, l = trunc-1e-10, r = l)
}
target_set2 <- fun_sublr(u = u, l = l, r = r)
value <- sum(-rowSums(target_set1 * lambda_exp_zb)) + sum(log((1 - exp(- rowSums(target_set2 * lambda_exp_zb)))[!r_cen]))
return(value)
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/log_penlikelihood.R |
plot.alacoxIC <- function(x, what = "cum.hazard", xlim, ylim, xlab, ylab, axes = FALSE, ...) {
match.call()
smallest.trunc <- x$smallest.trunc
dotnames <- names(list(...))
if (any(dotnames == "type")) stop("The graphical argument 'type' is not allowed.")
if (missing(what)) {
what <- "cum.hazard"
} else {
if(!(what %in% c("cum.hazard", "survival"))) stop("The 'what' argument must be 'cum.hazard' or 'survival'.")
}
lambda <- x$lambda
nlambda <- length(lambda)
lambda.set <- x$lambda.set
x.coordinate <- c(smallest.trunc, c(lambda.set[, 2]))
if (missing(xlab)) xlab <- "Time"
if(what == "cum.hazard") {
y.coordinate <- c(0, cumsum(lambda))
if (missing(ylab)) ylab <- "Baseline Cumulative Hazard Function"
}
if(what == "survival") {
y.coordinate <- c(1, exp(-cumsum(lambda)))
if (missing(ylab)) ylab <- "Baseline Survival Function"
}
if(missing(xlim)) xlim <- c(smallest.trunc, max(x.coordinate))
if(missing(ylim)) ylim <- c(0, max(y.coordinate))
x.max <- xlim[2]
y.max <- ylim[2]
plot(x.coordinate, y.coordinate, type = "s", xlim = xlim, ylim = ylim,
xlab = xlab, ylab = ylab, axes = axes, ...)
if(axes == FALSE) {
x.axis0 <- signif(seq(from = smallest.trunc, to = x.max, length.out = 6),2)
x.axis <- c(x.axis0[x.axis0 <= signif(x.max, 2)], signif(x.max, 2))
y.axis0 <- signif(seq(from = 0, to = y.max, length.out = 6),2)
y.axis <- c(y.axis0[y.axis0 <= signif(y.max, 2)], signif(y.max, 2))
axis(1, x.axis)
axis(2, y.axis)
}
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/plot.alacoxIC.R |
plot.unpencoxIC <- function(x, what = "cum.hazard", xlim, ylim, xlab, ylab, axes = FALSE, ...) {
match.call()
smallest.trunc <- x$smallest.trunc
dotnames <- names(list(...))
if (any(dotnames == "type")) stop("The graphical argument 'type' is not allowed.")
if (missing(what)) {
what <- "cum.hazard"
} else {
if(!(what %in% c("cum.hazard", "survival"))) stop("The 'what' argument must be 'cum.hazard' or 'survival'.")
}
lambda <- x$lambda
nlambda <- length(lambda)
lambda.set <- x$lambda.set
x.coordinate <- c(smallest.trunc, c(lambda.set[, 2]))
if (missing(xlab)) xlab <- "Time"
if(what == "cum.hazard") {
y.coordinate <- c(0, cumsum(lambda))
if (missing(ylab)) ylab <- "Baseline Cumulative Hazard Function"
}
if(what == "survival") {
y.coordinate <- c(1, exp(-cumsum(lambda)))
if (missing(ylab)) ylab <- "Baseline Survival Function"
}
if(missing(xlim)) xlim <- c(smallest.trunc, max(x.coordinate))
if(missing(ylim)) ylim <- c(0, max(y.coordinate))
x.max <- xlim[2]
y.max <- ylim[2]
plot(x.coordinate, y.coordinate, type = "s", xlim = xlim, ylim = ylim,
xlab = xlab, ylab = ylab, axes = axes, ...)
if(axes == FALSE) {
x.axis0 <- signif(seq(from = smallest.trunc, to = x.max, length.out = 6),2)
x.axis <- c(x.axis0[x.axis0 <= signif(x.max, 2)], signif(x.max, 2))
y.axis0 <- signif(seq(from = 0, to = y.max, length.out = 6),2)
y.axis <- c(y.axis0[y.axis0 <= signif(y.max, 2)], signif(y.max, 2))
axis(1, x.axis)
axis(2, y.axis)
}
}
| /scratch/gouwar.j/cran-all/cranData/ALassoSurvIC/R/plot.unpencoxIC.R |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.