0% found this document useful (0 votes)
88 views50 pages

Tutorial DeaR English

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views50 pages

Tutorial DeaR English

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

 

 
 
 
Tutorial 

Data Envelopment Analysis with deaR 

 
Version 1.0 (English) 
(Noviembre 2018) 
 
 
 
 
Vicente Coll‐Serrano(1) 
Rafael Benítez(2) 
Vicente J. Bolós(3) 
(1) Department of Applied Economics. [email protected]  
Quantitative Methods for Measuring Culture (MC2) 
(2) Department of Business Mathematics. [email protected]  
(3) Department of Business Mathematics. [email protected]  

School of Economics (www.uv.es/economia) 
University of Valencia (Spain) 
 
 
 
Index 
  Page 
1. Introduction……………………………………………………………………………….………………………….  1 
2. Download and install R and RStudio………………………………………………..……………………..  1 
2.1. R installation…………………………………………………………………………………………….  1 
a) Installing R on Windows……………………………………………………………………….  2 
b) Installing R on Mac………………………………………………………………………………  2 
2.2. RStudio installation………………………………………………………………………………….  3 
3. Getting started with RStudio………………………………………………………………………………….  4 
3.1. How to create a script………………………………………………………………………………  4 
4. How to create and work with projects in RStudio…………………………………………………..  5 
4.1. Creating a project…………………………………………………………………………………….  5 
4.2. Opening a project…………………………………………………………………………………….  6 
4.3. Additional information…………………………………………………………………………….  6 
4.4. How to create a project. An example……………………………………………………….  6 
5. How to install and load deaR…………………..…………………………………………………...………..  7 
5.1. Installing deaR……………………………….…………………………………………………….  7 
5.2. Loading deaR.............................…………………………………………………………..  8 
6. Save the script and close the working session………………………………………………………..  9 
7. Data Envelopment Analysis with deaR………………………………………………………………..  10 
7.1. Importing data into RStudio….…………………………………………………………………  11 
7.2. Adapting the data to deaR……………………………………………………………………….  16 
7.2.1. Getting help from deaR………………………………………………………………….  16 
7.2.2. read_data() function……………………………………………………………………  18 
7.2.3. read_malmquist() function………………………………………………………….  20 
7.2.4. read_data_fuzzy() function………………………………………………………….  24 
7.3. Select and run a DEA model………………………………………………………………….  27 
7.4. Extracting the main results……………………………………………………………………  32 
7.5. summary() function………………………………………………………………………………  34 
7.6. Graphical results: The plot() function……………………………………………………  41 
Acknowledgements…………………………………………………………………………………………………..  48 
 
Data Envelopment Analysis with deaR 

1. INTRODUCTION. 
deaR is a new and versatile R package (free software) that allows to run a wide variety of 
models based on Data Envelopment Analysis. 
This  tutorial  is  written  so  that  non‐R  users  can  use  deaR,  but  it  is  not  a  manual  of 
introduction to R1.  
If you are an R user, you can directly go to section 5 and 7. 
We want deaR to become the reference software tool for those researchers, practitioners, 
teachers, students and users of the Data Envelopment Analysis methodology. For this, any 
comments  and  suggestions  to  improve  deaR  will  be  really  appreciated.  We  also  accept 
suggestions of DEA models to be considered for being programmed in new versions of deaR. 
In this sense, we like to anticipate that a new version of deaR will include models or features 
not  currently  covered  such  as:  stochastic  DEA,  network  DEA,  Malmquist  index  (other 
decompositions  and  bootstrapping),  negative  values  and  extension  of  undesirable 
inputs/outputs to other models in which they are not available now, etc. 
We  will  release  a  deaR  shiny  version  (an  interactive  web  app)  soon.  We  will  inform  you 
when it available.  

2. Download and Install R and RStudio. 
To use deaR, firstly we have to download and install R and Rstudio. 
2.1. R installation. 
To install R, we go to the R‐project website: http://www.r‐project.org (see Figure 1). 

Figure 1. R‐project website. 

To download R, we click the CRAN link and select the “mirror site” nearest to our location.  
Now, depending on the operating system of our computer, we select the appropriate option 
(see Figure 2).   

                                                            
1
Manual of introduction to R:  https://cran.r‐project.org/doc/manuals/r‐release/R‐intro.pdf 
  1
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 2. Versions of R. 

 
a) Installing R on Windows. 
By clicking the Download R for Windows link, we will go to the webpage shown in the Figure 
below. We click on install R for the first time (see Figure 3). 

Figure 3. R for Windows. 

Next, we click on Download R 3.5.1 for Windows and save the installation file (see Figure 4) 

Figure 4. Download R for Windows. 

 
Now, we open the downloaded file (by double‐clicking on the file) to install R. 

b) Installing R on Mac. 
By  clicking  the  Download  R  for  (Mac)  OS  X  link,  we  will  go  to  the  webpage  shown  in  the 
Figure below. We click on R‐3.5.1.pkg to download the installation file (see Figure 5). 
   

  2
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 5. R for Mac. 

 
We open R‐3.5.1.pkg and follow the instructions to install R.  

2.2. RStudio installation. 
Once we have installed R, we download RStudio from the following link (see Figure 6): 
https://www.rstudio.com/products/rstudio/download/#download 

Figure 6. Download RStudio. 

 
To download the executable file, we select the option according to our operating system: 
 RStudio 1.1.463 ‐ Windows Vista/7/8/10  
 RStudio 1.1.463 ‐ Mac OS X 10.6+ (64‐bit)  

  3
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

First,  we  save  the  file.  Then,  we  open  it  to  install  RStudio.  We  follow  the  installation 
instructions. 

3. Getting started with RStudio. 
In general, we use RStudio instead of R because of the friendly interface of the former. 
To boot up RStudio, we click on the RStudio icon:   
By opening RStudio, we should see something like the Figure 7: 

Figure 7. The RStudio interface. 

By default, the Console is in the left side. After a brief informative text, the system prompt 
appears (“>”). Can you see the flashing cursor? Here is where we can write the commands or 
instructions to be run (by R). To execute an instruction in the Console and get the result we 
press Enter. 
3.1. How to create a script. 
Working  in  the  Console  is  very  limited  since  in  the  Console  the  instructions  are  generally 
written  and  executed  one  by  one.  For  this  reason,  it  is  usual  working  with  scripts  or 
instructions files. These files have the extension “.R”. 
To create a script we select File > New File > R Script. 
Now, the script is the top left panel and the Console is the bottom left panel. By default, the 
name of the script is “Untitled1” (see Figure 8). 
In a script we can write the instructions line by line. The instructions can be run one by one 
or we can select all (or some) of them and run the selection. We click on              to run them. 
   

  4
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 8. Script. 

4. How to create and work with projects in RStudio. 
Once  we  boot  up  RStudio,  we  should  set  the  working  directory  to  indicate  R  and  RStudio 
where  our  data,  scripts,  etc.  are.  However,  in  our  opinion,  the  best  option  is  to  create  a 
project in RStudio. Creating a project, all the files (data, scripts, etc.) and directories inside 
the project are directly linked to the project. That is to say, all the work on a project will be 
self‐contained  in  the  directory  of  the  project.  In  this  way,  we  can  easily  share  the  project 
with someone else or copy‐paste the project in another computer, etc.  

Important note: 
We  create  a  project  for  each  activity/work  (for  example,  for  each 
article/paper). 
To  organize  a  project  properly,  we  recommend  to  create  specific 
directories for raw data, results, text documents, etc. 

4.1. Creating a project. 
To create a project in RStudio, we select File > New project... We should see something
similar as the Figure below:
 

  5
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 9. Create a project. 

To create a project in a new directory, we click on the New Directory button. Then, we select 
the type of project. In our case, New Project. Now, we name the directory (or folder) that we 
are  creating.    It  will  also  be  the  name  of  the  project.  Finally,  we  click  on  Create  Project. 
Following this process, a folder in Documents will be created, and inside it we will find the 
file: "folder_name.Rproj".  
To  create  a  project  in  an  existing  directory,  we  click  on  the  Existing  Directory  button,  and 
then we select the directory or folder by clicking on the Browse… button. Finally, we click on 
Create Project. 

4.2. Opening a project. 
To open a Project we double click on the file with extension “.Rproj”. We can also open the 
project from the RStudio menu: File > Open Project… 
Advantage of projects: any file we save while we are working in a project will be saved inside 
the project’s directory. 

4.3. Additional information. 
Here  you  have  two  readings  about  projects  in  RStudio.  The  second  reading  includes 
information about how to create projects.  
 https://www.r‐bloggers.com/managing‐projects‐using‐rstudio/ 
 https://www.ssc.wisc.edu/sscc/pubs/RFR/RFR_Projects.html#projects 
4.4. How to create a project. 
Step 1. Open RStudio 
Step 2. Select File > New Project 
Step 3. Select New Directory 
Step 4. Project Type: select New Project 
Step 5. Directory name: Paper_1 
Step 6: Create project as subdirectory of: by using the Browse, select the route where 
the project folder will be created. For example, select the Desktop folder. 
Step 7. Click on Create Project 

  6
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Result: The “Paper_1” folder will be created in the Desktop folder. This folder will have two 
files (see Figure 10).  
 Paper_1 (type: R Project) 
 .Rhistory (type: RHISTORY file) 

Figure 10. Project “Paper_1”. 

Important note: 

The working session with a project will be always opened 
double‐clicking on the file with extension “.Rproj” 
or 
File > Open Project and selecting the project 
Working simultaneously with several projects is not recommended. 

5. How to install and load deaR. 
Open RStudio or the project: “Paper_1”. 
Select File > New File > R script 

5.1. Installing deaR. 
To install deaR, we write into the script: 
install.packages(“deaR”) 
and we run the instruction. For that, we click on the Run button:              (see Figure 11). 
By clicking on the Packages menu in the bottom right window, a list of all installed packages 
will be shown. Now, deaR package should be listed. 
   

  7
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Important note: 
We have to install deaR only once. Then, we can get 
the new deaR versions updating the package. 

Figure 11. Install deaR. 

5.2. Loading deaR. 
Once we have installed deaR, or any other R package, to use it we have to load it first (see 
Figure 12). For that, we write into the script: 
library(“deaR”) 
and we run the instruction clicking on the Run button:   

Important note: 
It is necessary to load deaR package in each working session. 
   

  8
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 12. Load deaR. 

6. Save the script and close the working session. 
To save the script, we select File > Save as...   
Now, we name the file (for example: session_1) and click on the Save button. By default, the 
script  will  be  saved  in  the  project  folder:  “Paper_1”.  Remember,  this  is  an  advantage  of 
working with projects. 
Notice that the name of the R file (script) is “session_1.R” instead of “Untitled1” (see Figure 
13). This file is shown in the list of files that are part of the project Paper_1. 
Note: The content of this first script is completely irrelevant up to now. What is important is 
to remember that we can save a set of instructions in a script.  

    Important note:  
Give names to scripts that reflect their content. 
   

  9
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 13. Save script. 

 
If we want to close the project but not Rstudio: File > Close project 
If we want to close the project and Rstudio: File > Quit Session 

At this point, we save “session_1.R”, close the Project “Paper_1” and quit RStudio. 

7. Data Envelopment Analysis with deaR. 
We  start  by  opening  the  project  “Paper_1”.  For  that,  we  double  click  on  the  file 
“Paper_1.Rproj”. RStudio and the project will open. Remember, you can also open RStudio 
first and then the project (File > Open Project).  
Next,  we  create  a  new  script  (File  >  New  File  >  R  Script).  In  this  new  script  we  write  the 
instruction to load deaR:  
library(“deaR”) 
(Note: we execute the instruction by clicking on the Run button              ). 
In  the  flow  chart  below  (see  Figure  14),  we  can  see  the  steps  to  perform  any  DEA  (Data 
Envelopment Analysis) with deaR. 
   

  10
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 14. Steps to use deaR. 

 
7.1. Importing data into R. 
The first step is to import the data we are going to use to perform a DEA analysis. The non‐R 
user can use the Import dataset option. Let’s see how to import data with Example 1. 
 
Example 1. Import data into R data from an Excel file:  
1. Download the data of the example from www.uv.es/vcoll/Coll_Blasco_2006.xlsx 
and save the file into the folder of the project “Paper_1”. 
2. From RStudio Environment menu in the top left window, we select the option: 
Import Dataset < From Excel (see Figure 15). 
Figure 15. Import data from Excel. 

 
 
  11
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

3. The window Import Excel Data opens. We click on the Browse button to choose the 
Excel file (“Coll_Blasco_2006.xlsx”)2 and then on the Open button (see Figure 16). 

Figure 16. Import “Coll_Blasco_2006.xlsx”. 

 
4.  Now,  we  can  previsualize  “Coll_Blasco_2006.xlsx”  and  the  import  data  options 
used (see left side in Figure 17). As you can see in the Figure below, the R code used 
to import the data is shown in the bottom right side of this window (see Figure 17). 
Since the Open Data Viewer is selected3, the dataset will be opened when the import 
process concludes. For that, we click on the Import button. 

Figure 17. Data preview. 

 
 

                                                            
2
 Coll‐Serrano, V.; Blasco‐Blasco, O. (2006). Evaluación de la Eficiencia mediante el Análisis Envolvente de Datos. 
Introducción a los Modelos Básicos. www.eumed.net/libros/2006c/197/ 
3
 It corresponds to the R code: View(Coll_Blasco_2006) 
  12
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

5.  After  clicking  on  the  Import  button,  we  come  back  to  the  main  window  of  the 
project  “Paper_1”.  The  imported  data  are  shown  in  a  new  sheet  (it  has  the  same 
name  as  the  dataset)  (see  Figure  18).  Besides,  in  the  Environment  menu  (top  right 
panel) appears a list of all objects4 that we are creating in R. Right now, we only have 
one  object:  “Coll_Blasco_2006”.  Actually,  this  object  is  a  dataframe  with  6 
observations and 5 variables. 

Figure 18. Project “Paper_1”. 

 
We can see the R code used to import the data in the Console (see Figure 18): 
 library(readxl) → load the package: “readxl” 
 Coll_Blasco_2006 <‐ read_excel(“Coll_Blasco_2006.xlsx”) → the “read_excel” 
function  (from  the  readlx  package)  reads  the  data  file  and  assign  (“<‐  “)  the 
data to the object “Coll_Blasco_2006”. 
Very important:  
R terminology:  A <‐ B   This means that B (whatever B: a dataset, a function,  
a matrix, the result of a mathematical operation, etc.) is assigned (<‐) to the 
object A.  
 View(Coll_Blasco_2006) → visualize (View) the object “Coll_Blasco_2006”. 
6.  We  copy  the  above  code  into  the  script  “Untitled1”  and  save  it  with  the  name 
“session_2”.  
Our project should show something like that (see Figure 19). 
   

                                                            
4
 Everything in R is an object. An object can be a dataset, a function, an instruction, a matrix, etc.  
  13
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 19. Save script “session_2”. 

 
It  will  not  be  necessary  to  repeat  steps  1‐5  on  all  subsequent  sessions  because  we 
have  the  whole  code  in  the  file  “session_2.R”.  To  import  the  data  from 
“Coll_Blasco_2006.xlsx” again, we only have to execute the code in “session_2.R”. 
 
deaR also provides a large collection of datasets. These datasets come from articles already 
published and they are used to replicate the results of the articles. We think this is a great 
added  value  that  deaR  offers  both  researchers  and  practitioners,  since  it  can  be  an 
important  help  and  support  for  teaching  and  learning  DEA  methodology.  We  can  see  the 
structure and source of the data by getting help from deaR5. 
Let’s see how to load a dataset in Example 2. 
 
Example 2. Loading datasets available in deaR. 
To see what datasets are available in deaR, we write  
data(package=”deaR”) 
and run the instruction. 
   

                                                            
5
 Getting help with R: https://www.r‐project.org/help.html  
  14
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 20. Datasets proviede by deaR. 

 
To  load  a  dataset  we  use  the  data()  function.  For  example,  we  are  going  to  load  the  data 
from Tomkins and Green (1988)6. The name of this dataset is “Departments”. Therefore, we 
write into the script “session2.R” (see Figure 21): 
data(“Departments”) 
If we want to visualize the dataset, we write (see Figure 21):  
View(Departments) 

Figure 21. Load and view data. 

 
We execute the instructions by clicking on               (see Figure 22).   

                                                            
6
  Tomkins,  C.;  Green,  R.  (1988).  "An  Experiment  in  the  Use  of  Data  Envelopment  Analysis  for  Evaluating  the 
Efficiency of UK University Departments of Accounting", Financial Accountability and Management, 4(2), 147‐
164. https://doi.org/10.1111/j.1468‐0408.1988.tb00296.x 
  15
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 22. “Departments”. 

 
Notice  that  we  now  have  two  objects:  “Coll_Blasco_2006”  and  “Departments”. 
“Departments” is a dataframe consisting of 20 observations (DMUs) and 11 variables. 
 
Now, we save “session_2.R” and close the project “Paper_1”. Quit RStudio. 

7.2. Adapting the data to deaR 
Once  the  data  have  been  loaded,  the  next  step  is  to  adapt  them  to  the  format  that  deaR 
uses  to  read  them.  deaR  has  three  different data  reading  functions.  Each reading  function 
responds to a typology of DEA model. These reading functions are: 
Read_data(): if we are going to run a conventional DEA model. 
Read_malmquist(): if we want to perform the Malmquist productivity index. 
Read_data_fuzzy(): if we want to run a DEA model with uncertain data (fuzzy DEA). 

7.2.1. Getting help from deaR7. 
We  can  learn  how  to  use  a  specific  function  by  using  the  help  from  deaR.  In  the  help  for 
deaR we can read about the arguments of a function or examples about how to use it. Let’s 
see how to use the help function with Example 3. 
 
Example 3. Getting help for deaR. 
1.  We  open  the  project  “Paper_1”  and  create  a  new  script.  We  name  the  script: 
“example_read_data” 
2. We load deaR 
3. We load the dataset provided by deaR: “Coll_Blasco_2006” (see Figure 23). 
                                                            
7
 Getting help with R: https://www.r‐project.org/help.html 
  16
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 23. Load dataset: “Coll_Blasco_2006” 

 
To access the documentation for a function of the package deaR we use the help() 
function. We write:  
help(package="deaR") 
In  the  Help  menu  (see  bottom  right  window)  a  list  of  all  functions  and  datasets  in 
deaR will appear. It is the documentation for the package (see Figure 24).  

Figure 24. Help for deaR. 

 
 
   

  17
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

7.2.2. read_data() function: 
Once we have accessed the documentation (help) for deaR, if we clic on the “read_data” link 
we will get the specific help about this function. We can also get the same result if we write: 
help(read_data) (or ?read_data) 
into the script and run the instruction. 
All  the  arguments  of  the  read_data()  function  are  listed  in  the  Usage  section,  and  in  the 
Arguments section we can read a brief explanation of them (see Figure 25). 

Figure 25. Help for read_data() function. 

 
The read_data() function takes the following arguments: 
 datadea: It is the dataset (It must be a dataframe). 
 dmus: Number of the column where the DMUs are. By default, deaR considers DMUs 
are in the first column of the dataset. 
 ni: It is the number of inputs. 
 no: It is the number of outputs. 
 inputs: We can indicate the numbers of the columns where the inputs are instead of 
indicating the number of inputs. 
 Outputs: We can indicate the numbers of the columns where the outputs are instead 
of indicating the number of outputs. 
 nc_inputs: If we have non‐controllable inputs, we can indicate which are them. 
 nc_outputs: If we have non‐controllable outputs, we can indicate which are them. 
 nd_inputs: If we have non‐discretionary inputs, we can indicate which are them. 
 nd_outputs: If we have non‐discretionary outputs, we can indicate which are them. 
 ud_inputs: If we have undesirable (bad) inputs, we can indicate which are them. 

  18
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

 ud_outputs: If we have undesirable (bad) outputs, we can indicate which are them. 
Example  4  shows  how  to  use  the  read_data()  function.  The  documentation  for  deaR 
provides examples for the all functions in the package. 
 
Example 4. Using the read_data() function. 
Currently, we have loaded the dataset “Coll_Blasco_2006”. This dataset has 6 DMUs (column 
1), 2 inputs (columns 2 and 3) and 2 outputs (columns 4 and 5).  
Suppose that we want to measure the efficiency of these DMUs using the BCC DEA model. 
As BCC model is a conventional DEA model (it is not a fuzzy DEA model), we must use the 
read_data() function to adapt the original dataset to the format used by deaR. 
We write the following text into the script “example_read_data” (see Figure 26): 
data_example <‐ read_data(Coll_Blasco_2006, ni=2, no=2) 

Very important: Reading and understanding the instruction. 
The expression on the right side of the assignment symbol (<‐) means: read the 
data (read_data) in Coll_Blasco_2006; it has 2 inputs (ni=2) and 2 outputs(no=2). 
DMUs  are  in  column  1  (dmus=1).  This  argument  doesn’t  appear  since  it  is  the 
default value.  
Then, the result of this function is assigned (<‐) to the object data_example. 

We execute the instruction (             ). 
Notice  that  now  the  objects  “Coll_Blasco_2006”  and  “data_example”  appear  listed  in  the 
Environment menu. Notice also that “data_example” is  a  list of  9  components.  (see Figure 
26).  

Figure 26. Using the read_data() function. 

 
   

  19
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Now, the data are ready to be used with a conventional DEA model (see section 7.3.). For 
that, we should use the object we have created: “data_example”. 
Recommendation:  Practice  the  function  read_data()  with  the  examples  in  the 
documentation. 

Save “example_read_data.R”. 

7.2.3. read_malmquist() function. 
If we have time series data and we want to measure the Malmquist productivity index, we 
must use the read_malmquist() function first to adapt them to the format that deaR reads. 
deaR admits the time series data in two different formats: 
 Wide format: DMUs by column. Inputs and outputs of different periods of time 
by column. For example, see the dataset “Economy”8 in deaR (Figure 27). 
 Long format: Time by column. DMUs, inputs and outputs by column, but grouped 
by time. For example, see the dataset “EconomyLong” in deaR (Figure 28).  
In the following example we try to show the above explanation. 
 
Example 5. Wide and Long data formats. 
Now, we are going to show these different data formats. For that: 
1. We create a new script. Name it: “example_read_malmquist”.  
Note: If we have closed the working session, we open the project “Paper_1” and then 
create the new script. We also have to load deaR. 
2. We load the dataset in deaR: “Economy” (see Figure 27). 
3. Visualize  “Economy”.  This  object  (dataset)  has  31  DMUs  with  2  inputs  (Capital  and 
Labor) and 1 output (GIOV) for 5 years (from 2005 to 2009). “Economy” is a dataset in 
wide format. 
   

                                                            
8
  Wang,  Y.;  Lan,  Y.  (2011).  "Measuring  Malmquist  Productiviy  Index:  A  New  Approach  Based  on  Double 
Frontiers  Data  Envelopment  Analysis".  Mathematical  and  Computer  Modelling,  54,  2760‐
2771. https://doi.org/10.1016/j.mcm.2011.06.064 
  20
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 27. Wide data format: “Economy”. 

 
4. Now, load the dataset “EconomyLong”. 
5. We  visualize  “EconomyLong”  (see  Figure  28).  This  new  R  object  (actually,  it  is  a 
dataset) has 155 observations (31 DMUs x 5 years), with 2 inputs (Capital and Labor) 
and 1 output (GIOV). The Period column refers to the time period 2005‐2009. 

Figure 28. Long data format: “EconomyLong”. 

 
Note: Notice that all objects we are creating during the working session are listed in 
the Environment menu (top right window).  
   

  21
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

The read_malmquist() function takes the following arguments9: 
 datadea: It is the dataset (It must be a dataframe). 
 nper: It is the number of years (with data in wide format). 
 percol: It is the number of the column where the variable time is (with data in long 
format). 
 arrangement:  “horizontal”  with  data  in  wide  format  or  “vertical”  with  data  in  long 
format. 
 dmus: Number of the column where the DMUs are. By default, deaR considers DMUs 
are in the first column of the dataset. 
 ni: It is the number of inputs. 
 no: It is the number of outputs. 
 inputs: We can indicate the numbers of the columns where the inputs are instead of 
indicating the number of inputs. 
 Outputs: We can indicate the numbers of the columns where the outputs are instead 
of indicating the number of outputs. 
 nc_inputs: If we have non‐controllable inputs, we can indicate which are them. 
 nc_outputs: If we have non‐controllable outputs, we can indicate which are them. 
 nd_inputs: If we have non‐discretionary inputs, we can indicate which are them. 
 nd_outputs: If we have non‐discretionary outputs, we can indicate which are them. 
 ud_inputs: If we have undesirable (bad) inputs, we can indicate which are them. 
 ud_outputs: If we have undesirable (bad) outputs, we can indicate which are them. 
The  current  version  of  deaR  cannot  manage  undesirable  inputs/outputs  to  calculate  the 
Malmquist productivity index. This feature will be incorporated in a future version. 
In Examples 6 and 7 we can see how to use the  read_malmquist() function with  wide and 
long data respectively. 
 
Example 6. read_malmquist() function with wide data format. 
For this example, we are going to use the dataset “Economy”. This dataset is already loaded 
in the current working session. 
To  adapt  “Economy”  to  the  reading  format  used  by  deaR,  we  write  into  the  script 
(“example_read_malmquist”) the following text: 
data_example_1 <‐ read_malmquist(Economy,  
  nper=5, 
  arrangement=”horizontal”, 
  ni=2, 
  no=1)   

                                                            
9
 See help(read_malmquist). 
  22
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

By  running  the  instruction,  a  new  object  is  created  (“data_example_1”)  and  listed  in  the 
Environment (see Figure 29).  

Figure 29. read_malmquist() funtion with wide data format. 

 
As we can see, “data_example_1” is a list of 5 components. If we click on the icon     next to 
the name of the object, we can see the structure of this object (see Figure 30). 

Figure 30. Structure of “data_example_1”. 

 
 
   

  23
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

 
Example 7. read_malmquist() function with long data format. 
Now, we are going to use the dataset “EconomyLong”. The Figure 31 shows the instruction 
to adapt the dataset to the reading format in deaR. 

Figure 31. read_malmquist() function with long data format. 

 
Save “example_read_malmquist.R”. 

7.2.4. read_data_fuzzy() function. 
If we are working with uncertain data and we want to measure the efficiency with a fuzzy 
DEA model so that deaR can read the data, we have to use the read_data_fuzzy() function to 
adapt them first. 
deaR  can  manage  trapezoidal,  symmetric  triangular,  and  non‐symmetric  triangular  fuzzy 
numbers (see Figure 32). 
   

  24
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 32. Fuzzy numbers. 

 
 
The read_data_fuzzy() function takes the following arguments10: 
 datadea: It is the dataset (It must be a dataframe). 
 dmus: Number of the column where the DMUs are. By default, deaR considers DMUs 
are in the first column of the dataset. 
 Inputs.mL: Number of the columns where the mL values of the inputs are. 
 Inputs.mR: Number of the columns where the mR values of the inputs are. 
 Inputs.dL: Number of the columns where the dL values of the inputs are. 
 Inputs.dR: Number of the columns where the dR values of the inputs are  
 Outputs.mL: Number of the columns where the mL. values of the outputs are. 
 Outputs.mR: Number of the columns where the mR values of the outputs are. 
 Outputs.dL: Number of the columns where the dL values of the outputs are. 
 Outputs.dR: Number of the columns where the dR values of the outputs are. 
 nc_inputs: If we have non‐controllable inputs, we can indicate which are them. 
 nc_outputs: If we have non‐controllable outputs, we can indicate which are them. 
 nd_inputs: If we have non‐discretionary inputs, we can indicate which are them. 
 nd_outputs: If we have non‐discretionary outputs, we can indicate which are them. 
 ud_inputs: If we have undesirable (bad) inputs, we can indicate which are them. 

                                                            
10
 See help(read_data_fuzzy). 
  25
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

 ud_outputs: If we have undesirable (bad) outputs, we can indicate which are them. 
Currently,  deaR  only  considers  the  undesirable  inputs/outputs  in  the  fuzzy  DEA  models 
based on the BCC DEA model. 
Let’s see it in Example 8. 
 
Example 8. read_data_fuzzy() function. 
1. We create a new script. Name it: “example_read_data_fuzzy”.  
Note: If we have closed the working session, we open the project “Paper_1” and then 
create the new script. We also have to load deaR. 
2. We load the dataset “Leon2003”11:  
data(“Leon2003”). 
This  dataset  (see  Figure  33)  has  8  DMUs  with  1  symmetric  triangular  fuzzy  input 
(alpha is the spread of the input) and 1 symmetric triangular fuzzy output (beta is the 
spread of the output). 
Figure 33. Dataset: Leon2003. 

 
3. Now, we read_data_fuzzy() to adapt the data. For that, we write into the script: 
data_example_3 <‐ read_data_fuzzy(Leon2003,  
  inputs.mL=2, 
  inputs.dL=3, 
  outputs.mL=4, 
  outputs.dL=5) 
and run it. 

                                                            
11
  León,  T.;  Liern,  V.  Ruiz,  J.;  Sirvent,  I.  (2003).  "A  Possibilistic  Programming  Approach  to  the  Assessment  of 
Efficiency  with  DEA  Models",  Fuzzy  Sets  and  Systems,  139,  407–419.https://doi.org/10.1016/S0165‐
0114(02)00608‐5 
  26
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Our working session should look like the screenshot below (Figure 34): 

Figure 34. Using the read_data_fuzzy() function.  

 
In  this  example,  inputs.dL=alpha  and  ouputs.dL=beta.  Since  we  have  symmetric 
triangular fuzzy numbers: inputs.dL=inputs.dR and outputs.dL=outputs.dR 
We have created a new R object: “data_example_3”. This object will be the one we 
will use to run a given fuzzy DEA model. 
 
We save “example_read_data_fuzzy.R”, close the project and quit RStudio. 

7.3. Select and run a DEA model. 
Once we have adapted the data to the reading format in deaR, the next step is to select the 
DEA model and run it. 
In the current version of deaR (version 1.0), the following DEA models are available: 

Conventional DEA models 
Basic (radial) models (envelopment and multiplier forms) 
Directional distance function model 
(Weighted) Additive model 
Super‐efficiency additive model 
Radial Super‐efficiency model 
(Weighted) Non‐radial model 
Preference Structure model 
(Weighted) Slack‐based model 
(Weighted) Super‐efficiency slack‐based model 

  27
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Conventional DEA models 
Cross‐efficiency (crs12 and vrs13) 
Bootstrapping (Simar and Wilson algorithm) 
FDH model 
Productivity 
Malmquist index 
Fuzzy DEA models 
Kao and Liu model14 
Possibilistic model 
Guo and Tanaka model 
Fuzzy cross‐efficiency15 (only crs) 

In  the  documentation  for  deaR  we  can  find  all  the  details  about  how  to  use  the  different 
functions and examples putting them into practice. 
Although  the  DEA  models  available  in  deaR  are  the  listed  above,  given  the  flexibility  in 
programming  deaR  (here  is  an  important  strength  of  the  package),  the  user  himself  can 
experiment, try and implement variants of these models. For example, if the user defines the 
weights  appropriately  in  the  “Additive  model”,  MPI16  or  RAM17  models  can  be  obtained. 
Another  example  where  the  user  can  define  weights  and  obtain  different  models  is  from 
“Preference  Structure  Model”  (weighted  no  n  radial  model).  In  this  case,  the  user  can 
calculate the “Cost Efficiency”, “Revenue Efficiency” or “Profit Efficiency” models. 
Now, we are going how to use the model_basic() function to perform basic DEA models. For 
that: 
 Open  the  project  “Paper_1”  and  create  a  new  script.  Give  it  the  name: 
“example_basic”. 
 Load deaR. 
 Go to the help for deaR. 
 Clic on the model_basic link (see Figure 35). We can also write into the script: 
help(“model_basic”) 

   

                                                            
12
 crs = constant returns‐to‐scale. 
13
 vrs = variable returns‐to‐scale. 
14
  This  Fuzzy  DEA  model  has  been  extended  to  a  several  DEA  models.  See  the  help  for  the  package: 
help(“modelfuzzy_kaoliu”). 
15
 Based on Guo and Tanaka’s model. 
16
 Measure of Inefficiency Proportions (MPI). 
17
 Range Adjusted Measure (RAM). 
  28
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 35. Help for the model_basic() function. 

 
The model_basic() function takes the following arguments: 
 datadea: It is the dataset (It must be a dataframe). 
 dmu_ref: Selection of a subset of DMUs. 
 dmu_eval: DMUs to be evaluated from the selected subset. 
 orientation: Orientation of the DEA model: input‐oriented, output‐oriented o 
direccional. 
 dir_input: Input direction vector in directional models. 
 dir_output: Output direction vector in directional models. 
 rts: Returns to scale (constant, variable, non‐increasing, non‐decreasing, generalized). 
 L: If we select generalized rts, lower bound. 
 U: If we select generalized rts, upper bound. 
 Maxslack: By default, slacks are maximized in a second stage. 
 weight_slack_i: The user can set weights for the input slacks to be maximized in the 
second stage. 
 weight_slack_o: The user can set weights for the output slacks to be maximized in 
the second stage. 
 vtrans_i: With undesirable inputs and variable returns‐to‐scale, the user can set a 
translation vector. By default, the translation vector is (max + 1). 
 vtrans_o: With undesirable outputs and variable returns‐to‐scale, the user can set a 
translation vector. By default, the translation vector is (max + 1). 
 compute_target: To calculate the targets for the max slack solution. 
 compute_multiplier: It returns the multipliers (or weights) of the multiplier form. 

  29
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

 returnlp: For each DMU, this argument returns the linear problem of the first stage. 
Now, we are going to learn how to use the model_basic() function by doing Examples 9 and 
10. To follow these examples, we have to load the dataset in deaR: “PFT1981”18. The dataset 
has  70  DMUs  (school  sites)  with  5  inputs  (Education,  Occupation,  Parental,  Counseling, 
Teachers) and 3 outputs (Reading, Math, Coopersmith). The Figure below (Figure 36) shows 
the instructions that we should write into the script “example_basic” to load the data.  

Figure 36. Dataset: PTF1981. 

 
 
Example 9. model_basic() function. 
Of 70 DMUs (school sites) in “PTF1981”, there are 49 DMUs in Project Follow Through (PFT) 
and 21 DMUs in Non‐Follow Through (NFT). 
In this example, we are going to calculate the efficiency of the 49 DMUs in PFT by using the 
input‐oriented CCR DEA moldel. 
First,  we  have  to  use  the  read_data()  function  to  adapt  the  data  to  the  reading  format  in 
deaR (see section 7.2.2.). Run the instruction by clicking on  
Now, we have to use the model_basic() function because we want to measure the efficiency 
by  using  the  CCR  DEA  model  (a  conventional  DEA  model).  But  we  want  to  calculate  the 
efficiency of the first 49 DMUS; that is to say, the DMUs participating in PFT. To make this 
selection,  we  use  the  argument:  dmu_ref=1:49.  To  evaluate  all  these  units,  we  use  the 
argument: dmu_eval=1:49. Therefore, we have to write into the script “example_basic” the 
following text: 
 
                                                            
18
 Charnes, A.; Cooper, W.W.; Rhodes, E. (1981). "Evaluating Program and Managerial Efficiency: An Application 
of  Data  Envelopment  Analysis  to  Program  Follow  Through",  Management  Science,  27(6),  668‐697. 
https://pubsonline.informs.org/doi/abs/10.1287/mnsc.27.6.668 
  30
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

result_pft <‐ model_basci(PFT1981,  
    dmu_ref=1:49, 
    dmu_eval=1:49, 
    orientation=”io”, 
    rts=”crs”) 
and run it (see Figure 37). 
 
Note: We can also select all the instructions and run them instead of  
doing it instruction by instruction. 

Figure 37. Running the input‐oriented CCR DEA model for DMUS in PFT. 

 
 
 
Example 10. model_basic() function. 
At  this  point,  could  you  run  the  CCR  input‐oriented  DEA  model  for  the  DMUs  in  NFT?  
(DMUs in NFT are the DMUs from 50 to 70). 
 
The answer to this question is in next page (Figure 38) 
   

  31
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 38. Running the input‐oriented CCR DEA model for DMUs in NFT. 

 
 
Save  the script “example_basic”. 

7.4. Extracting the main results. 
In Examples 9 and 10, after running the model_basic() function, all the results are saved in 
the objects “result_pft” and “result_nft” respectively. We can see that these objects are a list 
of  11  components.  We  can  show  the  content  of  each  list  by  clicking  on  the  name  of  the 
object (see Figure 39) or its structure clicking on the blue arrow (     ). 

Figure 39. Structure of the results for a basic DEA model. 

 
  32
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

To extract the main results of the DEA analysis, deaR has a several specific functions. These 
functions are: 
 efficiencies(): To extract the efficiency scores. 
 slacks(): To extract input and output slacks. 
 targets(): To extract the input and output target values. 
 lambdas(): To extract the lambdas (or intensities). 
 references(): To extract the reference set for inefficient DMUs. 
 rts(): To extract the returns‐to‐scale. 
 multipliers():  To  extract  the  multipliers  (or  weights)  of  the  multiplier  DEA 
form. 
In the following Example 11 we are going to practice with these functions. 
 
Example 11. Extracting the results. 
To extract the efficiency scores from “result_pft”, we only have to write into the script the 
instruction: 
efficiencies(result_pft) 
and run it. 
The efficiency scores will be shown in the Console, as the following Figure shows. 

Figure 40. Efficiency scores of DMUs in PFT. 

 
Similarly,  to  extract  the  reference  set  of  the  inefficient  DMUs  we  write  and  execute  the 
instruction: 
references(result_pft) 
  33
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

The  remaining  functions  (slacks(),  targets(),  lambdas(),  rts(),  and  multipliers())  work  in  a 
similar way. Try and practice with these functions and pay attention to the results obtained. 

Save the script “example_basic..R”, close the project and quit RStudio. 

7.5. summary() function. 

In addition to the previous functions (efficiencies(), lambdas(), etc.), deaR has the summary() 
function, which summarizes the results of the DEA analysis. The summary() function serves 
to  summarize  the  results  of  both  conventional  DEA  models  and  fuzzy  DEA  models.  To  use 
this function we have to know that it has the following structure:19: 
summary(objet, exportExcel = TRUE, filename = NULL) 
The arguments of this function refer to: 
 object: It is the object to which we have assigned the results of a conventional DEA or 
fuzzy DEA model. 
 exportExcel: The default value for this argument is TRUE. Therefore, the summary() 
function will automatically create an Excel file with the main  results in the working 
directory. The user can choose not to create the Excel file (exportExcel = FALSE). 
 filename: By default, the value of the argument is NULL. Therefore, the default name 
of  the  Excel  file  will  be:  "ResutsDEAyear‐month‐dat_hour:minute:second.xlsx".  Of 
course, the user can give other name to the Excel file. 
As we have said, the way to use the summary() function to summarize the results of a DEA 
analysis is identical in both conventional DEA models and fuzzy DEA models. The difference 
is found in the summary of the Excel file generated. That is, the sheets of the Excel workbook 
created are different depending on the model. Let’s see this in Examples 12 and 13.  
 

Example 12. Summary of results: conventional DEA model. 
Follow the following steps: 
1. Open the project “Paper_1”. 
2. Create a new script: “Summary_DEA” 
3. Load deaR. 
Assumption:  Load  the  dataset  provided  by  deaR:  “Hua_Bian_2007”20.  This  dataset  has  30 
DMUs  with  2  inputs  (D‐Input1,  D‐Input2),  2  outputs  (D‐Output1,  D‐Output2)  and  1 
undesirable output (UD‐Output1) (in this same order). 
We want to get the summary of results from the output‐oriented BBC DEA model. As there is 
an undesirable output, to take this into account in the analysis we will use as the translation 
parameter the one used by Hua and Bian (2007): vtrans_o=1500. 
   

                                                            
19
 For more details: help(summary.dea) o help(summary.dea_fuzzy). 
20
 Hua Z.; Bian Y. (2007). DEA with Undesirable Factors. In: Zhu J., Cook W.D. (eds) Modeling Data Irregularities 
and Structural Complexities in Data Envelopment Analysis. Springer, Boston, MA. https://doi.org/10.1007/978‐
0‐387‐71607‐7_6 
  34
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Important: Remember the steps to use deaR.  
Step 1. Load the data. 
Step 2. Adapt the data to the format used by deaR. 
Step 3. Run the DEA model. 
Step 4. Extract the results. 
 

Try it!!! 
(the solution is shown in the next page) 

   

  35
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Solution: As we can see in Figure 41, to solve Example 12 we have to write into the script 
“Summary_DEA” the following instructions: 

Step 1. Load the data: 

data(“Hua_Bian_2007”) 

Step 2. Adapt the data: 
data_example_12 <‐ read_data(Hua_Bian_2007, 
        ni=2, 
                          no=3, 
  ud_output=3) 

Note: We have 3 outputs (no=3) and the third output  
is the undesirable output (ud_output=3) 

Step 3. Run the DEA model:  

result_example_12 <‐ model_basic(data_example_12, 
        orientation=”oo”, 
        rts=”vrs”, 
        vtrans_o= 1500) 

Figure 41. Example 12 solution. 

All the results of the output‐oriented BCC DEA model that we have executed can be found in 
the object "result_example_12", which is a list of 11 components (see Figure 42). 

  36
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 42. Structure of “result_example_12”. 

At this point, we can extract the partial results with the functions: efficiencies(), lambdas(), 
multipliers(),  rts(),  references(),  slacks(),  targets();  and  the  summary  of  results  with  the 
summary() function. 
As the Figure 43 shows, we extract the efficiency scores of the DMUs with the efficiencies() 
function. The efficiencies are listed in the Console and assigned to the object "eff". To obtain 
the same results as those obtained by Hua and Bian (2007), we write into the script: 
1/eff 
and run the instruction. 
Figure 43. Efficiency scores. 

  37
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

To get a summary of all the results obtained by running the output‐oriented BCC DEA model, 
we use the summary() function. We write into the script "Summary_DEA": 
summary(result_example_12) 
All results are dumped on the Console. Although there are not many DMUs (only 30), there 
are many results. It is not practical to use the summary() function to see the results on the 
screen. However, as we can see in Figure 44, deaR has also created an Excel file that has all 
these results. Notice the name that has been given to the file by default. 

Figure 44. Summary of results of the Example 12. 

Open the Excel file to see how the results are shown (see Figure 45). To do this, we click on 
the  file  "ResutsDEAyear‐month‐dat_hour:minute:second.xlsx  "  and  select  the  option  "View 
file". 

   

  38
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Figure 45. Summary results in Excel. 

We save the script “summary_DEA”. 
Now, in Example 13 we are going to replicate the results in León, et al. (2003)21. 

Example 13. Summary of results: Posibilistic fuzzy DEA model. 
León et al. (2013) use possibilistic programming techniques to measure the efficiency based 
on the envelopment form of the input‐oriented BCC model. Data used by the authors in their 
article can be found in the dataset "Leon2003", which is provided by deaR. 
We  create  a  new  script:  "Summary_DEA_fuzzy".  To  replicate  the  results  that  the  authors 
show in Table 2 (page 419), we write into the script: 
data("Leon2003")  
data_example <‐ read_data_fuzzy(Leon2003,  
dmus = 1,  
inputs.mL = 2,  
inputs.dL = 3,  
outputs.mL = 4,  
outputs.dL = 5) 
 
result <‐ modelfuzzy_possibilistic(data_example, 
  h= seq(0, 1, by = 0.1), 
  orientation = "io", 
  rts = "vrs") 
efficiencies(result) 
                                                            
21
  Léon,  T.;  Liern,  V.  Ruiz,  J.;  Sirvent,  I.  (2003).  "A  Possibilistic  Programming  Approach  to  the  Assessment  of 
Efficiency  with  DEA  Models",  Fuzzy  Sets  and  Systems,  139,  407–419. https://doi.org/10.1016/S0165‐
0114(02)00608‐5 
  39
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Note: h = seq (0, 1, by = 0.1) generates a sequence of  
values for the different levels of possibility: h = (0, 0.1, 0.2, ..., 1). 

We run the instructions. The efficiency scores of the BCC input‐oriented model will be shown 
for the different levels of possibility h in the Console (see Figure 46) 
Figure 46. Efficiency scores for different h‐levels. 

To get a summary of the results on the screen (see Figure 47) and export them to an Excel 
file, we write the following instruction into the script and run it: 
summary(result) 
Figure 47. Summary of results for the possibilistic input‐oriented BCC DEA model. 

  40
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

For the possibilistic model, the summary of results consists of: (1) the efficiency scores and 
(2)  the  reference  sets.  These  are  the  results  that  are  exported  to  the  Excel  workbook  (see 
Figure 48). 

Figure 48. Summary results in Excel. 

 
 
We save the script “Summary_DEA_fuzzy”. 

7.6. Graphical results. The plot() function. 
With  the  plot()  function  we  can  obtain  some  plots  of  the  results  from  a  conventional  DEA 
model, Malmquist index or cross‐efficiency model. This is shown in Examples 14, 15, and 16 
respectively.  
The plot() function is used in the following way: 
plot(x) 
where x is the object in which the result of a DEA model has been stored. 
After using the plot() function, we will get the plot in the Viewer (right bottom window). We 
can save a plot by clicking on the Export tag of the Viewer. It is possible to save the plot as an 
image in format: “png”, “jpeg” or “tiff”. We can copy the plot to the system clipboard and 
then paste it, for example, in a word document. 
Graphs for fuzzy DEA models are not available still in this version of deaR.  
We are currently working to improve the graphical results in deaR, which will be included in 
the next version.  
 
Example 14. Plot: Basic DEA model. 
We  open  the  script  “Summary_DEA”.  If  we  have  closed  the  working  session,  we  need  to 
open the project “Paper_1”, load deaR, and open the script.  

  41
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Our working session should be similar to the one shown in Figure 49. 
Figure 49. Script “Summary_DEA”. 

 
As  Figure  50  shows,  we  select  from  line  1,  library(deaR),  to  line  16  and  run  the  selection. 
Immediately,  three  objects  are  listed  in  the  Environment:  “data_example_12”, 
“Hua_Bian_2007” and “result_example_12”. 

Figure 50. Running the script. 

 
The results of the DEA model are assigned to (or stored in) the object “result_example_12”. 
To plot some of these results, we will write the following  instruction on the line 27 of the 
script: 
plot(result_example_12) 
  42
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

and run it. The following message will be displayed in the Console: 
Press [enter] to continue 
and a plot will be shown in the Viewer tag (right bottom window), as we can see in Figure 51. 

Figure 51. Example 12, Graphic 1. 

 
This  Graphic  1  shows  the  number  of  efficient  and  inefficient  DMUs  (right  graph),  and  the 
distribution of the efficiency score of the latter as well (left graph). If we click on the Zoom 
bottom, the plot will be enlarged (see Figure 52). 
Figura 52. Enlarge plot. 

  43
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

Now, if we press the Enter key, a second graphic will be displayed. On this occasion, what is 
depicted is the number of times an efficient DMU is part of the inefficient DMUs reference 
set. 

Figure 53. Example 12, Graphic 2. 

 
Finally, by pressing the Enter key again we can see the last graphic (see Figure 54). 

Figure 54. Example 12, Graphic 3. 

 
In Figure 54 we see a network graph in which the green circles represent the efficient DMUs 
and the red circles the inefficient ones. This graph shows how inefficient DMUs are related 
to  efficient  DMUs,  trying  to  convey  the  idea  that  the  efficient  ones  form  the  efficient 
frontier. In addition, notice that not all green circles have the same size. In this case, the size 
  44
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

of  the  circle  aims  to  convey  the  idea  of  how  important  is  the  efficient  DMU  for  the  set  of 
inefficient DMUs. 

We save the script as: “plot_example_12”. 
 
Example 15. Plot: Malmquist index. 
We  create  a  new  script  with  the  name  “plot_malmquist”.  If  we  have  closed  the  working 
session, we need to open the project “Paper_1”, load deaR, and create the script.  
Now, we are going to run the Malmquist index. For that, we write into the script: 
data("EconomyLong") 
data_example_15 <‐ read_malmquist(EconomyLong, 
                                                                      percol = 2,  
                                                                      arrangement = "vertical", 
                                                                      inputs = 3:4,  
                                                                      outputs = 5) 
result_malmquist <‐ malmquist_index(data_example_15, 
                                                                       orientation = "io") 

                                                 Note: The data are in long format.  

We run the instructions of the script (see Figure 55). 

Figure 55. Running the Malmquist index. 

 
The results of the Malmquist index are stored in the object “result_malmquist”. Therefore, 
to get the plots we write into the script: 
plot(result_malmquist) 

  45
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

and run the instruction. The following message will be displayed in the Console: 
Press [enter] to continue 
By  pressing  the  Enter  key  a  plot  will  be  shown  in  the  Viewer  (right  bottom  window)  (see 
Figure 56). We can click on the Zoom to see the plot better. In this first plot, for each DMU 
the Malmquist index and its components are drawn over the years. If there are many DMUs 
you  will  not  probably  see  them  very  well.  However,  it  is  possible  to  select  the  DMUS  the 
DMUs of your interest to focus on them (and the other DMUs in the graph will disappear).  

Figure 56. Malmquist index: Graphic 1. 

 
If we press the Enter key (in the Console) again, a second plot is created (see Figure 57).  

Figure 57. Malmquist index: Graphic 2. 

 
  46
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

On  this  occasion,  the  geometric  means  of  Malmquist  index  and  its  components  are  drawn 
over the years. We can enlarge the plot by clicking on the Zoom and go back (or go forward) 
by clicking on the arrows. Here, it is possible to select the Malmquist index components to 
be shown. 
 
We save “plot_malmquist”. 
 
Example 16. Plot: Cross efficiency. 
We create the new script “plot_cross_efficiency”. If we have closed the working session, we 
need to open the project “Paper_1”, load deaR, and create the script.  
We write and run the followings instructions (see Figure 58): 
data("Golany_Roll_1989") 
data_example <‐ read_data(datadea = Golany_Roll_1989,  
                                                    dmus = 1,  
                                                    inputs = 2:4,  
                                                    outputs = 5:6) 
result_cross <‐ cross_efficiency(data_example,  
                                                          orientation = "io",  
                                                          rts = "crs",  
                                                          selfapp = TRUE) 

Figure 58. Script of cross efficiency. 

 
In  the  object  “result_cross”  are  stored  the  results  of  the  cross  efficiency  corresponding  to 
the models: arbitrary, benevolent and aggressive. All these results are drawn like a heat map 
by using the plot() function. For that, we write into the script: 
plot(result_cross) 
  47
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 
Data Envelopment Analysis with deaR 

and press Enter in the Console to display the different graphs. The result should be similar to 
the one shown in Figure 59. 

Figure 59. Graphs of cross efficiency. 

 
 
We save the script “plot_cross_efficiency”, close the project and quit RStudio. 
 
 
 
Acknowledgements 
The  authors  wish  to  thank  Dra.  Cristina  Pardo‐Garcia  for  her  inestimable 
assistance reviewing this tutorial. 
 
 
 
We  hope  you  find  deaR  useful  and  you  use  it  in  your 
future research and teaching.  
Any comments and suggestions to improve deaR will be 
really appreciated. 

  48
©Coll‐Serrano, V.; Benítez, R. and Bolós, V. J. (2018) 

You might also like