xpRt.wannabe
2007-Apr-26 16:48 UTC
[R] A coding question involving variable assignments in ifelse()
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? platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 2.1 year 2005 month 12 day 20 svn rev 36812 language R Thanks,
Another similar way to do this using apply is: apply(ar1==ar2,1,all) Best, Finny Kuruvilla ***************************************************************** Finny Kuruvilla, MD, PhD Harvard Medical School Fellowship Program in Transfusion Medicine Broad Institute of MIT and Harvard Homepage: http://www.people.fas.harvard.edu/~kuruvill/home/> Estimated people, > > I have two matrices: > > ar1 <- array(data=c(1:16),dim=c(4,4)) > ar2 <- array(data=c(1,2,3,3,5:16),dim=c(4,4)) > > They only differ in the fourth row. I would like to compare them in > order to know which columns are equal. > > The following works, but I would like to have a better solution, and > not > to use what someone called "prehistorical loops": > > for(i in c(1:4)) { cat(as.character(i),": ", > as.character(setequal(ar1[i,],ar2[i,])), "\n") } > 1 : TRUE > 2 : TRUE > 3 : TRUE > 4 : FALSE > > I cannot devise how to use the apply function for this. > Thanks a lot, > Federico
Duncan Murdoch
2007-Apr-26 16:59 UTC
[R] A coding question involving variable assignments in ifelse()
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
rolf at math.unb.ca
2007-Apr-27 16:48 UTC
[R] A coding question involving variable assignments in ifelse()
I think Duncan's suggestion that the poster work it out for him/her self is perfectly reasonable. People can be anonymous all they like. Those of us who are made suspicious by this anonymity (what have they got to hide?) can decline to provide assistance. cheers, Rolf Turner rolf at math.unb.ca