Skip to content

Commit

Permalink
Final touches on factorFormula
Browse files Browse the repository at this point in the history
Addresses Issue #65
  • Loading branch information
nutterb committed Oct 30, 2015
1 parent fffc18e commit a4e7887
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
`data` argument of `compileDecisionModel`.
* Adds `factorFormula` to assist in writing formulae that make use
of factor levels instead of their numeric codes.
* Deterministic nodes are now represented as diamonds by default.

### 0.10.0 (26 Sept 2015)
>>>>>>> origin/current-devel
* Implements the `factorLevels` element in network objects
and arguments in `setNode`. See Issue #81
* Changes to `plot.HydeNetwork` relevant to changes in
Expand Down
6 changes: 4 additions & 2 deletions R/factorFormula.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
#'
factorFormula <- function(form, network){
form <- deparse(form)
form <- trimws(form)
form <- paste0(form, collapse = "")

relabel <- extractFactors(form)

relabel_mat <- isolateVariableFromLabel(relabel)
relabel_mat <- isolateVariableFromLabel(relabel, network)

new_label <-
mapply(getNumericLevel,
Expand Down Expand Up @@ -73,7 +75,7 @@ extractFactors <- function(form){
unlist(relabel)
}

isolateVariableFromLabel <- function(relabel){
isolateVariableFromLabel <- function(relabel, network){
relabel_mat <- stringr::str_split_fixed(relabel, "[=][=]", 2)
relabel_mat <- trimws(relabel_mat)
relabel_mat <- gsub("('|\")", "", relabel_mat)
Expand Down
15 changes: 8 additions & 7 deletions vignettes/DecisionNetworks.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,24 @@ net <- setNode(net, payoff, "determ", define=fromFormula(),
nodeFormula = factorFormula(payoff ~
ifelse(playerFinalPoints > 21, -1,
ifelse(playerFinalPoints == 21,
ifelse(dealerOutcome == 1, 0,
ifelse(dealerOutcome == "Blackjack", 0,
ifelse(dealerOutcome == 7, 0, 1)),
ifelse(dealerOutcome == 2,
ifelse(dealerOutcome == "Bust",
ifelse(playerFinalPoints < 22, 1, -1),
ifelse(dealerOutcome == 3,
ifelse(dealerOutcome == "17",
ifelse(playerFinalPoints == 17, 0,
ifelse(playerFinalPoints > 17, 1, -1)),
ifelse(dealerOutcome == 4,
ifelse(dealerOutcome == "18",
ifelse(playerFinalPoints == 18, 0,
ifelse(playerFinalPoints > 18, 1, -1)),
ifelse(dealerOutcome == 5,
ifelse(dealerOutcome == "19",
ifelse(playerFinalPoints == 19, 0,
ifelse(playerFinalPoints > 19, 1, -1)),
ifelse(dealerOutcome == 6,
ifelse(dealerOutcome == "20",
ifelse(playerFinalPoints == 20, 0,
ifelse(playerFinalPoints > 20, 1, -1)),
ifelse(playerFinalPoints == 21, 0, -1))))))))))
ifelse(playerFinalPoints == 21, 0, -1)))))))),
net))
```

Expand Down

0 comments on commit a4e7887

Please sign in to comment.