X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2Fplot.R;h=35e89ff40d096a91f368ef1c3d7438fff94e0aaf;hb=476a79d4b332d378716e320fdfd95fa3e1d7be9f;hp=f94f19a6da41b54f854de4d0ad0d359707ed8d1c;hpb=cbd88fe5729bf206a784238a2637aa60e697fcdc;p=morpheus.git diff --git a/pkg/R/plot.R b/pkg/R/plot.R index f94f19a..35e89ff 100644 --- a/pkg/R/plot.R +++ b/pkg/R/plot.R @@ -18,10 +18,10 @@ extractParam <- function(mr, x=1, y=1) #' #' @param mr Output of multiRun(), list of lists of functions results #' @param x Row index of the element inside the aggregated parameter -#' @param y Colomn index of the element inside the aggregated parameter +#' @param y Column index of the element inside the aggregated parameter #' #' @examples -#' \dontrun{ +#' \donttest{ #' β <- matrix(c(1,-2,3,1),ncol=2) #' mr <- multiRun(...) #see bootstrap example in ?multiRun : return lists of mu_hat #' μ <- normalize(β) @@ -64,48 +64,37 @@ plotBox <- function(mr, x, y) #' #' @inheritParams plotHist #' @param params True value of parameters matrix +#' @param idx List index to process in mr #' #' @examples #' #See example in ?plotHist #' @export -plotCoefs <- function(mr, params) +plotCoefs <- function(mr, params, idx, xtitle="Parameter") { - nf <- length(mr) L <- nrow(mr[[1]][[1]]) K <- ncol(mr[[1]][[1]]) - params_hat <- vector("list", nf) - stdev <- vector("list", nf) - for (i in 1:nf) - { - params_hat[[i]] <- matrix(nrow=L, ncol=K) - stdev[[i]] <- matrix(nrow=L, ncol=K) - } + params_hat <- matrix(nrow=L, ncol=K) + stdev <- matrix(nrow=L, ncol=K) for (x in 1:L) { for (y in 1:K) { estims <- extractParam(mr, x, y) - for (i in 1:nf) - { - params_hat[[i]][x,y] <- mean(estims[[i]]) -# stdev[[i]][x,y] <- sqrt( mean( (estims[[i]] - params[x,y])^2 ) ) - # HACK remove extreme quantile in estims[[i]] before computing sd() - stdev[[i]][x,y] <- sd( estims[[i]] [ estims[[i]] < max(estims[[i]]) & estims[[i]] > min(estims[[i]]) ] ) - } + params_hat[x,y] <- mean(estims[[idx]]) +# stdev[x,y] <- sqrt( mean( (estims[[idx]] - params[x,y])^2 ) ) + # HACK remove extreme quantile in estims[[i]] before computing sd() + stdev[x,y] <- sd( estims[[idx]] ) #[ estims[[idx]] < max(estims[[idx]]) & estims[[idx]] > min(estims[[idx]]) ] ) } } - par(mfrow=c(1,nf), cex.axis=1.5, cex.lab=1.5, mar=c(4.7,5,1,1)) + par(cex.axis=1.5, cex.lab=1.5, mar=c(4.7,5,1,1)) params <- as.double(params) o <- order(params) - for (i in 1:nf) - { - avg_param <- as.double(params_hat[[i]]) - std_param <- as.double(stdev[[i]]) - matplot(cbind(params[o],avg_param[o],avg_param[o]+std_param[o],avg_param[o]-std_param[o]), - col=c(2,1,1,1), lty=c(1,1,2,2), type="l", lwd=2, xlab="param", ylab="value") - } + avg_param <- as.double(params_hat) + std_param <- as.double(stdev) + matplot(cbind(params[o],avg_param[o],avg_param[o]+std_param[o],avg_param[o]-std_param[o]), + col=1, lty=c(1,5,3,3), type="l", lwd=2, xlab=xtitle, ylab="") #print(o) #not returning o to avoid weird Jupyter issue... (TODO:) } @@ -115,6 +104,9 @@ plotCoefs <- function(mr, params) #' Draw 3D map of objective function values #' #' @param N Number of starting points +#' @param n Number of points in sample +#' @param p Vector of proportions +#' @param b Vector of biases #' @param β Regression matrix (target) #' @param link Link function (logit or probit) #'