dams-mcda / Dams-MCDA

Emma Fox R/Shiny Project with a docker server configuration
1 stars 0 forks source link

Task 13 (Step 4: View Results) WW/EF #80

Closed elbfox closed 4 years ago

elbfox commented 5 years ago

In each dam Results page, add (in order from top to bottom): 1) a bar graph that shows the preference scores for each decision criterion for that dam (what is now currently shown at the bottom of the preference elicitation pages - e.g., "Raw Scores of Alternative 5" on the current Alternative 5 page); 2) a second bar graph that shows the total weighted MCDA scores for each decision alternative for that dam, stacked with the component scores for the decision criteria; 3) a table with decision alternatives for the rows and decision criteria for the columns and the preference-weighted MCDA scores in the cells, with an ending TOTAL column (i.e., the output decision matrix from the MOGA for that dam); Each of these 3 sets of results will have titles and text above them explaining to the user what they are seeing (Emma will provide these titles and text) and there will need to be links back to the same materials from the Read This links (step 3, task 13) so the user can follow the flow of knowledge from original dam data matrix to normalized data matrix to preference scores to final MCDA scores. Add download capability for graphs.

Will want error bars on the decision alternatives to show some uncertainty for: fish survival and river recreation (network dependent criteria)

sythel commented 4 years ago

@elbfox I am confused about references of "decision alternative" in graph 2 and 3. I thought alternatives were removed?

elbfox commented 4 years ago

DamsData.csv has alternative-specific criteria data for each dam (see WSMUpdate_Dams), so while the preference elicitation tabs structure changed from alternatives to dams (i.e., each user is asked to consider criteria for each of 8 dams), each dam still has alternative performance data for the set of criteria. This is what I'm wrestling with in the WSM script. The graphic output should be similar to what it was previously, but specific to each individual dam. Does this make sense?

sythel commented 4 years ago

I don't see a DamsData.csv in branch WSMUpdate_Dams @elbfox

elbfox commented 4 years ago

I emailed the same, but there should now be a DamsData.csv in the WSMUpdate_Dams, also now requested to merge with TabsUpdate_Dams as an intermediate step.

elbfox commented 4 years ago

I have a note from you @sythel somewhere that generateOutput needs to be cleaned up in server.R script, but I'm not sure what that means for generating graphs. Cleaned up how? I imagine this will look very different now that I've had to separate out the individual dam results (limited to 5 alternatives) and the multi-dam ranked results.

elbfox commented 4 years ago

Trying to get this working in GraphTesting branch using basic Rgraphics functions in WSM_graph_test.R to check results...did not use because I have a hard time wrapping my head around it and needed a quick way to show graphic results. Example:

bars data table for West Enfield Dam results Score1 <- as.matrix(scoresum1) colnames(Score1) <- alternative_names

Graph West Enfield alternative scores WSMPlot1 <- barplot((scoresum1), main="West Enfield Dam Recommendation", ylab= "Decision Alternative Score", names.arg= alternative_names, beside=TRUE, col=rainbow(5))

Place the legend at the top-left corner with no frame
using rainbow colors legend("topleft", c("KeepMaintain","ImproveHydro","ImproveFish","Improve FishANDHydro","Remove"), cex=0.6, bty="n", fill=rainbow(5));

sythel commented 4 years ago

I have a note from you @sythel somewhere that generateOutput needs to be cleaned up in server.R script,

Not super important. It was because of the amount of commented lines inside the function. Also would be beneficial to make the function smaller for readability. seems like simplifying it might be possible due to the repetition of the renderPlots

sythel commented 4 years ago

I am going to try and simplify the single dam weighting procedure in WSM_graphs_test

Is there still need for multiple WSM*.R files? I'd like to link WSM_graphs_test.R up with server.r so I can work on this issue

elbfox commented 4 years ago

WSM_graphs_test is now the only correct one, so we don't need multiple files. I had kept the old one because this started as a scratch file and then turned into the working one with your help.

elbfox commented 4 years ago

Update to part 3) a table with decision alternatives for the rows and decision criteria for the columns and the preference-weighted MCDA scores in the cells, with an ending TOTAL column:

We need actually 4 tables per dam, 3 of which (a, c, d) prepped in WSM_graphs_test.R, and 1 of which is already coded in server.R (b): (a) Raw data matrix (decision alternative rows, decision criteria columns), (b) preferences data matrix (decision alternative rows, decision criteria columns), (c)normalized data matrix (decision alternative rows, decision criteria columns), and (d) weighted data matrix (decision alternative rows, decision criteria columns. I will add placeholder text to ui.R tomorrow

sythel commented 4 years ago

can you list references a, c, d with line numbers in WSM_graphs_test.R?

elbfox commented 4 years ago

Ex: West Enfield Dam Tables a) Line 405- 407: Dam1RawTable c) Line 409 - 411: Dam1NormTable d) Line 413 - 415: Dam1ScoreTable

These variable names are repeated for the other dams 2 (Medway) - 8 (Ripogenus). Thanks for the reminder to be more specific!

sythel commented 4 years ago

(a, b, c, d) you want in graphs, correct?

also just to confirm (b) is the raw preference score.

Here are the tables for a,c,d a c d for this one each dams table looks the same

code changes are in branch IndividualDamOutput

sythel commented 4 years ago

looking into why (d) is repeated now

elbfox commented 4 years ago

Actually, a, and c we just want in tables, no graphs.

b should have a corresponding graph (this is called the summplot, I believe) d will also have corresponding graphs (these are graphs 2 and 3 in each results tab, numbered uniquely as figures in the ui.R because we wanted to have them all individually identifiable).

Also, in the imgur links you provided, it looks like the tables are 3 dimensional (i.e., with levels) in the West Enfield tab, and it should just be decision alternatives and criteria for Dam 1/West Enfield.

sythel commented 4 years ago

for the levels: I put them all in one place for verifying the data before splitting them up and optimizing/cleaning

sythel commented 4 years ago

b

elbfox commented 4 years ago

Why are the values so high? Shouldn't b be pulling directly from the toggle bar inputs?

sythel commented 4 years ago

ok I think I got confused by the mention of SummPlot. I was using values from WSM's returned variable called scoresum_total. Now I am assuming that the current graphs on individual dam result page are (b) since they are called "SummPlot"

I will remove the changes of last commit

elbfox commented 4 years ago

Yes, sorry for the confusion! I wanted to be accurate with the variable name but I realize now that the name SummPlot is confusing because it has been repurposed or was initially labeled poorly.

I will give lines of code and R script reference next time :)

sythel commented 4 years ago

d

elbfox commented 4 years ago

All of these tables/graphs (a - d) should get labels where rows = decision alternatives (5) and columns = decision criteria (14).

sythel commented 4 years ago

example graphs for d d1) WSM table d2) WSM table inverted

NOTE: still need to fix labels

elbfox commented 4 years ago

d1 doesn't make sense to include the way you have it depicted above. Instead, d1 should be using Score1, or WSMPlot1a (WSM_graphs_test.R lines 548 - 558)

d2 should show stacked criteria for each decision alternative d2 should be using CritAlt1, or WSMPlot1b (WSM_graphs_test.R lines 562 - 573)

sythel commented 4 years ago

so i think my tables plots match the requested they are just out of order ie: d1 -> d2, d2 -> d1

options: if I keep "d2" as new d1: the graph will label each bar with the criteria that contributes to the score. if I change d1 to "Score1" from WSM > Ind_scoresum then it will be scores without references to criteria.

elbfox commented 4 years ago

Ok, yes "d2" is right, then. d1 should be scores without references to criteria. The idea is that the bars in each graph should have the same height, the first one, "d1" , will be the decision alternative scores, and then "d2" shows the scores broken down by criteria.

The whiteboard image/drawing in #81 reminded me that we also need a 100% stacked column for each decision alternative, to compare how much the criteria contribute to each alternative. (x -axis is decision alternative, y-axis is % criteria contributionto alternative score). Let me know if this doesn't make sense. It should be the first graph, labeled 1, in the whiteboard image/drawing in #81

sythel commented 4 years ago

The whiteboard image/drawing in #81 reminded me that we also need a 100% stacked column for each decision alternative, to compare how much the criteria contribute to each alternative. (x -axis is decision alternative, y-axis is % criteria contributionto alternative score). Let me know if this doesn't make sense. It should be the first graph, labeled 1, in the whiteboard image/drawing in #81

@elbfox Is this for each dam? or just a reminder for #81

also does the latest commit fix/close this issue? After its solved I will go split up into each dam appropriately

elbfox commented 4 years ago

This is for each dam. I don't have time to check this in R but based on the variables and labels you're using it seems fine. I'd say once the 100% stacked column thing is working go ahead and split up into each dam appropriately.

sythel commented 4 years ago

100% stacked columns

the 100% part is confusing me

the image you reference has two graphs labeled 1 (I assume it was the red "1" you were referring to because it is closer relevant)

other than that it seems fine: x -> alternatives, y-> score, stacked/break bars into criteria

I will refer this graph as (d3)

elbfox commented 4 years ago

The 100% stacked is a different option in Excel, for instance. You can pick the stacked bar, which stacks the values to a total bar that will vary in height from category to category (in this case decision alternative to alternative), or you can pick the 100% stacked bar that sets the values relative to 100%, so it uses the relative score instead of the real score. I don't have a variable set up for this yet.

I can add a visual example tomorrow if this is still confusing. Let me know.

sythel commented 4 years ago

yeah an example would help

elbfox commented 4 years ago

working on this now

elbfox commented 4 years ago

image

sythel commented 4 years ago

and in this scenario the value of KeepMaintain does not equal the value of ImproveHydro? so all values scale to 100%

elbfox commented 4 years ago

Exactly, the values scale to 100%. The actual MCDA scores (sum of criteria scores) should not be equal to one another; rather, the criteria values should all be out of 100% in terms of their contribution to each decision alternative (so the total of each bar is 100%).

sythel commented 4 years ago

cases when the alternative value is 0?

elbfox commented 4 years ago

The criteria values would also be zero, then, so there would be nothing to scale. There should be no bar in that case.

sythel commented 4 years ago

d3

sythel commented 4 years ago

will be changing y unit to % in next commit

elbfox commented 4 years ago

Looks great! Thank you.

sythel commented 4 years ago

is this issue closed?

elbfox commented 4 years ago

solved this locally, will push soon.

EDIT: realized WSMPlt1a was wrong, and we were missing what I thought I was asking for in 1a, but I have corrected it in the server.R file and am updating the ui now

elbfox commented 4 years ago

Graphs are now coming up wonky, maybe as a result of the commit where they got swapped in PR #141. B and C (individual dams) are showing different alternative scores, which shouldn't be happening. I'm concerned that this might be a result of the normalization changes.

elbfox commented 4 years ago

plot A is the problem, I tried using Ind_WeightedScoreMatrix as the data, but it causes R to throw an error and the app to shut down. It was originally using something called ResultsMatrix, but I searched for that and couldn't find it used except listed as an input, and I don't see it used outside of the server.R script.

I had all of this working in the DamsReOrder branch and I'm struggling to figure out what happened.

sythel commented 4 years ago

ResultsMatrix is given as an argument to that method which is being passed inside generateOutput to generateDam as variable WSMMatrix original source is variable Ind_WieghtedScoreMatrix from WSM.R

elbfox commented 4 years ago

Ok, I've reverted it back to ResultsMatrix in my local version here. I see that WSMMatrix is being passed inside generateOutput to generateDam, but I'm not seeing when it turns into ResultsMatrix. Tracing back is the only way I know how to effectively troubleshoot, so I'm not sure what else to do here. The graphs for plots A are very wrong (bar/column heights should match plots B) right now in "IndividualDamOutput" branch, but were correct in "DamsReOrder" branch (I checked them all, and went cell by cell in every matrix to be sure).

sythel commented 4 years ago

When you pass in a variable to a function it changes its name to the argument (only inside the function) ex

a <- 1
someMethod <- function(b){
message(b)
}
someMethod(a)

would print 1

in this case 'a' is our WSMMatrix and 'b' is ResultsMatrix

sythel commented 4 years ago

The graphs for plots A are very wrong (bar/column heights should match plots B) right now in "IndividualDamOutput" branch, but were correct in "DamsReOrder" branch (I checked them all, and went cell by cell in every matrix to be sure).

can you provide table data or plot image discrepancies so I can investigate

just to make sure you are referring to plotOutput("WSMPlot(damId)a",...)?

elbfox commented 4 years ago

See below Figure 7 graph for West Enfield (using attached file in csv format) EqualPrefs_forLiveSite.xlsx image image

Also, I think I found the issue (maybe). Lines 995 - 995 in server.R looks like WSMMatrix is being defined initially as RawCriteriaMatrix, not Ind_WeightedScoreMatrix. Figure 5 here (now renamed Figure 8) is correct, but it uses Ind_scoresum so that makes sense.

sythel commented 4 years ago

line 995 which branch?