Learn R Programming

emdi (version 2.2.1)

write.excel: Exports an emdiObject to an Excel File or OpenDocument Spreadsheet

Description

Function write.excel enables the user to export point and MSE estimates as well as diagnostics from the summary to an Excel file. The user can choose if the results should be reported in one or several Excel sheets. Furthermore, a selection of indicators can be specified. Respectively the function write.ods enables the export to OpenDocument Spreadsheets. Note that while write.exel will create a single document write.ods will create a group of files.

Usage

write.excel(
  object,
  file = "excel_output.xlsx",
  indicator = "all",
  MSE = FALSE,
  CV = FALSE,
  split = FALSE
)

write.ods( object, file = "ods_output.ods", indicator = "all", MSE = FALSE, CV = FALSE, split = FALSE )

Value

An Excel file is created in your working directory, or at the given path. Alternatively multiple ODS files are created at the given path.

Arguments

object

an object of type "emdi", representing point and MSE estimates.

file

path and filename of the spreadsheet to create. It should end on .xlsx or .ods respectively.

indicator

optional character vector that selects which indicators shall be returned: (i) all calculated indicators ("all"); (ii) each indicator name: "Mean", "Quantile_10", "Quantile_25", "Median", "Quantile_75", "Quantile_90", "Head_Count", "Poverty_Gap", "Gini", "Quintile_Share" or the function name/s of "custom_indicator/s"; (iii) groups of indicators: "Quantiles", "Poverty" or "Inequality". Note, additional custom indicators can be defined as argument for model-based approaches (see also ebp) and do not appear in groups of indicators even though these might belong to one of the groups. If the model argument is of type "fh", indicator can be set to "all", "Direct", FH", or "FH_Bench" (if emdi object is overwritten by function benchmark). Defaults to "all".

MSE

logical. If TRUE, the MSE of the emdiObject is exported. Defaults to FALSE.

CV

logical. If TRUE, the CV of the emdiObject is exported. Defaults to FALSE.

split

logical. If TRUE, point estimates, MSE and CV are written to different sheets in the Excel file. In write.ods TRUE will result in different files for point estimates and their precisions. Defaults to FALSE.

Details

These functions create an Excel file via the package openxlsx and ODS files via the package readODS. Both packages require a zip application to be available to R. If this is not the case the authors of openxlsx suggest the first of the following two ways.

  • Install Rtools from: http://cran.r-project.org/bin/windows/Rtools/ and modify the system PATH during installation.

  • If Rtools is installed, but no system path variable is set. One can set such a variable temporarily to R by a command like: Sys.setenv("R_ZIPCMD" = "PathToTheRToolsFolder/bin/zip.exe").

To check if a zip application is available they recommend the command shell("zip").

See Also

direct, emdiObject, ebp, fh

Examples

Run this code
if (FALSE) {
# Loading data - population and sample data
data("eusilcA_pop")
data("eusilcA_smp")

# Generate emdi object with two additional indicators; here via function
# ebp()
emdi_model <- ebp(
  fixed = eqIncome ~ gender + eqsize + cash +
    self_empl + unempl_ben + age_ben + surv_ben + sick_ben + dis_ben + rent +
    fam_allow + house_allow + cap_inv + tax_adj, pop_data = eusilcA_pop,
  pop_domains = "district", smp_data = eusilcA_smp, smp_domains = "district",
  threshold = function(y) {
    0.6 * median(y)
  }, L = 50, MSE = TRUE, B = 50,
  custom_indicator = list(
    my_max = function(y) {
      max(y)
    },
    my_min = function(y) {
      min(y)
    }
  ), na.rm = TRUE, cpus = 1
)

# Example 1: Export estimates for all indicators and uncertainty measures
# and diagnostics to Excel
write.excel(emdi_model,
  file = "excel_output_all.xlsx", indicator = "all",
  MSE = TRUE, CV = TRUE
)

# Example 2: Single Excel sheets for point, MSE and CV estimates
write.excel(emdi_model,
  file = "excel_output_all_split.xlsx",
  indicator = "all", MSE = TRUE, CV = TRUE, split = TRUE
)

# Example 3: Same as example 1 but for an ODS output
write.ods(emdi_model,
  file = "ods_output_all.ods", indicator = "all",
  MSE = TRUE, CV = TRUE
)
}

Run the code above in your browser using DataLab