aboutsummaryrefslogtreecommitdiffstats
path: root/R/interpweights.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/interpweights.R')
-rw-r--r--R/interpweights.R12
1 files changed, 6 insertions, 6 deletions
diff --git a/R/interpweights.R b/R/interpweights.R
index c8702cdc..57995c89 100644
--- a/R/interpweights.R
+++ b/R/interpweights.R
@@ -8,10 +8,10 @@ interpweights <- function(w, v1, v2){
}
interpvalues <- function(w, v, neww){
- ## Given a distribution D=(w,v), compute new weights
+ ## Given a distribution D=(w,v), compute new values
## such that Dnew=(neww, newv) equals D in distribution
cumw <- cumsum(w)
- cdf <- splinefun(v, cumw, method="monoH.FC")
+ cdf <- splinefun(v, cumw, method="hyman")
eps <- 1e-3
newv <- rep(0, length(neww))
cumneww <- cumsum(neww)
@@ -31,8 +31,8 @@ interpvalues <- function(w, v, neww){
}
mid <- (lo+hi)/2
iter <- 0
- while(abs(cdf(mid)-cumneww[i])>eps){
- if(cdf(mid)>cumneww[i]){
+ while(abs(cdf(mid) - cumneww[i])>eps){
+ if(cdf(mid) > cumneww[i]){
hi <- mid
}else{
lo <- mid
@@ -48,8 +48,8 @@ interpvalues.distr <- function(w, v, neww){
## same as interpvalues, but using the distr
## package. need to check how good it is
require(distr)
- D <- DiscreteDistribution(w, v)
- return( q(D)(neww) )
+ D <- DiscreteDistribution(v, w)
+ return( q(D)(cumsum(neww)) )
}
adjust_scenario <- function(scenario, epsilon){