-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from edsandorf/v0.0.2-dev
V0.0.2 dev
- Loading branch information
Showing
18 changed files
with
205 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
## spdesignR v0.0.1 | ||
# spdesign v0.0.2 | ||
* New function ´probabilities()´ will now return the choice probabilities by choice task. | ||
* Suppress warnings when calculating the correlation between the blocking column and the attributes to avoid warning when calculating correlation with respect to a constant. | ||
* After a number of candidates without improvement try a new design candidate when using the RSC algorithm | ||
* Updated package load message | ||
* Fixed roxygen @docType issue | ||
|
||
# spdesign v0.0.1 | ||
* This is the first working version of the `spdesign` package that is able to create simple efficient designs for the MNL model. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#' Calculate the probabilities of the design | ||
#' | ||
#' Will take the design object and calculate the probabilities of each | ||
#' alternative and choice tasks. | ||
#' | ||
#' Using Bayesian priors the average across the prior distribution will be used. | ||
#' | ||
#' Using the specific type of model, either the MNL or RPL probs will be | ||
#' returned. | ||
#' | ||
#' @param x An 'spdesign' object. | ||
#' | ||
#' @return A matrix of probabilities for each alternative and choice task. | ||
#' | ||
#' @export | ||
probabilities <- function(x) { | ||
pr_j <- switch( | ||
x$model, | ||
mnl = probabilities_mnl(x) | ||
) | ||
|
||
return( | ||
pr_j | ||
) | ||
} | ||
|
||
#' Calculate the MNL probabilities | ||
#' | ||
#' @inheritParams probabilities | ||
#' | ||
#' @return A matrix of probabilities for each alternative and choice task. With | ||
#' Bayesian priors the return is the average probabilites over the prior | ||
#' distribution | ||
probabilities_mnl <- function(x) { | ||
db_env <- new.env() | ||
list2env(as.list(as.data.frame(x$design)), envir = db_env) | ||
|
||
pr_j <- lapply(x$prior_values, function(p) { | ||
list2env(as.list(p), envir = db_env) | ||
|
||
obs_utility <- lapply(update_utility(x$utility), function(v) eval(parse(text = v), envir = db_env)) | ||
exp_utility <- lapply(obs_utility, exp) | ||
sum_utility <- Reduce("+", exp_utility) | ||
pr_j <- lapply(exp_utility, function(v) { | ||
v <- v / sum_utility | ||
v[is.na(v)] <- 0 | ||
as.vector(v) | ||
}) | ||
|
||
return(do.call(cbind, pr_j)) | ||
}) | ||
|
||
return( | ||
Reduce("+", pr_j) / length(pr_j) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
## usethis namespace: start | ||
#' @import cli | ||
#' @import stringr | ||
#' @importFrom stats runif qnorm as.formula model.matrix | ||
#' @importFrom utils modifyList | ||
## usethis namespace: end | ||
NULL |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.