[R] A coding question involving variable assignments in ifelse()
xpRt.wannabe
xprt.wannabe at gmail.com
Thu Apr 26 20:31:51 CEST 2007
Just to be sure, is what I have below the right intepretation of your
suggestion:
deductible <- 15
coverage.limit <- 75
insurance.threshold <- deductible + coverage.limit
tmpf <- function() {
loss <- rlnorm(rpois(1, 3), 2, 5)
n <- length(loss)
accept <- runif(n) < 0.8
payout <- runif(n) < 0.999
sum(ifelse(accept & payout, ifelse(loss > insurance.threshold, loss -
coverage.limit, pmin(loss, deductible)), 0))
}
net <- replicate(1000000, tmpf())
On 4/26/07, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 4/26/2007 12:48 PM, xpRt.wannabe wrote:
> > Dear List,
> >
> > Below is a simple, standard loss model that takes into account the
> > terms of an insurance policy:
> >
> > deductible <- 15
> > coverage.limit <- 75
> > insurance.threshold <- deductible + coverage.limit
> >
> > tmpf <- function() {
> > loss <- rlnorm(rpois(1, 3), 2, 5)
> > sum(ifelse(loss > insurance.threshold, loss - coverage.limit,
> > pmin(loss, deductible)))
> > }
> > net <- replicate(1000000, tmpf())
> >
> > Now, I would like to enhance the model by incorporating the following
> > two probabilities:
> >
> > 1. Probability of claim being accepted by the insurance company, say, 0.8
> > 2. Probability of payout by the insurance company, say, 0.999
> >
> > Could anyone suggest how one might do this?
>
> A general way to generate events with probability p is runif(n) < p. So
> I'd add
>
> n <- length(loss)
> accept <- runif(n) < 0.8
> payout <- runif(n) < 0.999
>
> and then require "accept & payout" before any payment at all, e.g.
>
> sum(ifelse(accept & payout, [ your old ifelse expression ], 0))
>
> There are a lot of implicit independence assumptions here; they may not
> be very realistic.
>
> Duncan Murdoch
>
More information about the R-help
mailing list