[R] A coding question involving variable assignments in ifelse()
Duncan Murdoch
murdoch at stats.uwo.ca
Thu Apr 26 18:59:42 CEST 2007
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