knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
HDM is the little cousin of the more widely know AHP. Both are used for using expert evaluations to weight potential alternatives with the final goal of making a complex decesion. Using this package is very easy, you just need a list of data frames that correspond to your expert's rating of criteria and the critiera that represents your decision modeled as a tree. The tough part of HDM is getting your experts to rate your model; this package includes 2 Shiny apps described below to make that process much easier.
Because HDM is based on a tree this package depends on the data.tree package. To send in data to be evaluated you'll need to create a model using data.tree.
Your decision model will be structured as a tree. For example if you're trying to decide what to eat for breakfast your tree might look like this:
1 What to eat for breakfast 2 ¦--Taste 3 ¦ ¦--Salty 4 ¦ °--Sweet 5 °--Speed 6 ¦--Fast 7 °--Slow
The decision you're trying to make is the first node, "What to eat for breakfast". After that you have sub-critera, "Taste" and "Speed", then each sub-criteria can have it's own sub-criteria. There is no limit to the number of levels in the tree however note that the longer your tree the harder it will be for your experts to evaluate it, thus you will likely have a much harder time collecting data.
Note that the last level in the tree is the set of Alternatives that you're choosing between. Alternatives are not mandantory, so you could technically have a tree that just weights criteria against each other.
Once your model is defined and you ask your experts to rate your model you're going to get a bunch of pairwise comparisons, these are ComboFrames, or the distinct combinations of nodes to be compared against each other as data frames. ComboFrames is simply a list of these data frames and must correspond to the model for the calculations to work.
If you already have data and you just want to use the package just do this:
calculatedTree <- calculateHDMWeights(tree, comboFrames)
Here are some more detailed examples of using HDPR
First we need to create a tree that represents our model. You can do that like this:
#TODO put code here that creates the model as a tree
Typically the next thing you do is get experts to rate your model by doing a series of pairwise comparisons. You can use the shiny app in inst/gui/hdpr-evaluate to do this but for the sake of the example here is what the finished data should look like representing a single expert's evaluation:
#TODO put code here that creates a sample evaluation here
Next will be code that will create the outputs for one expert:
#TODO run the code that does evaluation for a single expert
If you have muliple experts combine them together first, then caluclate:
#TODO using more than one expert do the calcualtion
The output is the final set of weights for each branch in the tree. You can examine it like this:
#TODO code here to show what the final output of the tree looks like
Enjoy your results! However you probably don't really want to define your model by hand or get all those values into data frames. To make your life easier there are 2 Shiny apps that will help you define your model and collect results from experts.
There are 2 Shiny apps in here, hdp-admin and hdp-eval. You can run them in R Studio but both have Docker files so you can easily build and deploy them to whatever environment you want. To ensure consistency across the models and the evaluations they share a databased which is also defined in Docker. The architecture looks like this:
The hdp admin app will allow you as a model administrator to
The model designer allows you to add multiple levels of critiera to your model, name your model, and define alternatives. Each level of critiera should be input as a comma seperated list as shown in the Model Designer below:
Note there is a new tab for each level in the tree, so if you want to add more levels simply go to that tab and add more criteria.
hdp-admin saves data to a MongoDB. Each model is saved with an email for the model creator and a pin. To load models that you've saved previously you need to enter your email and your pin. Note that this isn't intended to be extremely secure, it's just designed to keep people using the same tenant from messing with each other's models. There is not recover functionality so if you can't get to your database then remember your pin!
Experts are a critical piece of HDM, they are the ones giving you data to analyze! Experts will evaluate your model via the hdp-eval app described below through a URL that is unique for each expert. The "Experts" tab in the admin tool will allow you to add or modify experts by putting their emails into the text boxes as shown in the image below. Note that the URL contains the modelID and the expert's email in a query string.
Once your model is evaluated you can view your results in the results tab.
The evaluation app will allow experts to evaluate your model by rating each node in the tree against each other.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.