Re: [R] A coding question involving variable assignments in ifelse()
On 4/28/2007 6:20 AM, AJ Rossini wrote: > > I agree entirely with Gabor. My advice would be to just ignore the people > who > think differently That's fairly bad advice, in that many of the people who actually provide helpful advice are old-fashioned, and like to know who they're providing it to. If xpRt.wannabe had followed your advice a few days ago, s/he would have seen no help at all. Or maybe you meant to say, "ignore their wishes", and not "ignore their help"? > -- however, if you want those particular folks to respond, > you'll have to play by their rules. (and if you don't play by their rules, > you'll just have to ignore the consequences -- this _IS_ the internet, after > all). And if you want anyone else to respond, you may just be out of luck. Duncan Murdoch > > On Friday 27 April 2007, Gabor Grothendieck wrote: >> I don't think there is any requirement to identify yourself in any >> way nor should their be. Many people on the list are in academia >> and in those cases they probably want their name in lights but >> others may wish to have a lower profile and its common to use >> an alias on the net for privacy. >> >> On 4/27/07, xpRt.wannabe <[EMAIL PROTECTED]> wrote: >>> Is this an ad hominem comment or a comment of brevity? Unless my eyes >>> are playing tricks on me, I can't seem to find any language in the >>> Posting Guide on what is considered a reasonable vs. unreasonable >>> request from an anonymous poster. Kindly point me to it if it exists. >>> >>> In any case, thanks for your time and suggestion. >>> >>> On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: On 4/26/2007 5:21 PM, xpRt.wannabe wrote: > I made a few slight modifications to the original model in an effort > to see the inner workings of the code: > > deductible <- 1 > coverage.limit <- 2 > insurance.threshold <- deductible + coverage.limit > > > > set.seed(123) > loss <- abs(rnorm(rpois(1, 5), 1, 3)) > 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)) > > [1] 6.188817 > > > > To tease out the data as well as to see the effect of 'accept & > > payout', I did the following: >> loss > [1] 3.401663 4.570620 4.068667 4.718488 > >> accept > [1] TRUE FALSE TRUE TRUE # The second loss claim is NOT accepted > by the insurance company. > >> payout > [1] TRUE TRUE TRUE TRUE > >> accept & payout > [1] TRUE FALSE TRUE TRUE # The second entry is FALSE because of > the second entry in 'accept.' > > Based on the inner ifelse() expression, the original loss numbers > become : 1.401663, 2.570620, 2.068667, 2.718488, respectively (which > is fine and what I wanted). > > Because the second entry in 'accept & payout' is FALSE, the second > altered loss number (2.570620) becomes 0, making sum(...) equal > 6.188817. Unfortunately this is _not_ what I want, and I apologize > for not being clear in the first place. What I want is: for any > FALSE entry, the original loss number is unaltered, as opposed to > become 0. So in the example above, the four numbers that should have > been added are: 1.401663, 4.570620, 2.068667, 2.718488, yielding > 10.759438 instead of 6.188817. > > Any further suggestions would be greatly appreciated. I'm sorry, but from an anonymous poster that's not a reasonable request. Just work it out yourself. Duncan Murdoch > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: >> On 4/26/2007 2:31 PM, xpRt.wannabe wrote: >>> Just to be sure, is what I have below the right intepretation of >>> your suggestion: >> Yes, that's what I suggested. >> >> Duncan Murdoch >> >>> 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(100, tmpf()) >>> >>> On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> 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(
Re: [R] A coding question involving variable assignments in ifelse()
I agree entirely with Gabor. My advice would be to just ignore the people who think differently -- however, if you want those particular folks to respond, you'll have to play by their rules. (and if you don't play by their rules, you'll just have to ignore the consequences -- this _IS_ the internet, after all). On Friday 27 April 2007, Gabor Grothendieck wrote: > I don't think there is any requirement to identify yourself in any > way nor should their be. Many people on the list are in academia > and in those cases they probably want their name in lights but > others may wish to have a lower profile and its common to use > an alias on the net for privacy. > > On 4/27/07, xpRt.wannabe <[EMAIL PROTECTED]> wrote: > > Is this an ad hominem comment or a comment of brevity? Unless my eyes > > are playing tricks on me, I can't seem to find any language in the > > Posting Guide on what is considered a reasonable vs. unreasonable > > request from an anonymous poster. Kindly point me to it if it exists. > > > > In any case, thanks for your time and suggestion. > > > > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > > > On 4/26/2007 5:21 PM, xpRt.wannabe wrote: > > > > I made a few slight modifications to the original model in an effort > > > > to see the inner workings of the code: > > > > > > > > deductible <- 1 > > > > coverage.limit <- 2 > > > > insurance.threshold <- deductible + coverage.limit > > > > > > > > > > > > > > > > set.seed(123) > > > > loss <- abs(rnorm(rpois(1, 5), 1, 3)) > > > > 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)) > > > > > > > > [1] 6.188817 > > > > > > > > > > > > > > > > To tease out the data as well as to see the effect of 'accept & > > > > > > > > payout', I did the following: > > > >> loss > > > > > > > > [1] 3.401663 4.570620 4.068667 4.718488 > > > > > > > >> accept > > > > > > > > [1] TRUE FALSE TRUE TRUE # The second loss claim is NOT accepted > > > > by the insurance company. > > > > > > > >> payout > > > > > > > > [1] TRUE TRUE TRUE TRUE > > > > > > > >> accept & payout > > > > > > > > [1] TRUE FALSE TRUE TRUE # The second entry is FALSE because of > > > > the second entry in 'accept.' > > > > > > > > Based on the inner ifelse() expression, the original loss numbers > > > > become : 1.401663, 2.570620, 2.068667, 2.718488, respectively (which > > > > is fine and what I wanted). > > > > > > > > Because the second entry in 'accept & payout' is FALSE, the second > > > > altered loss number (2.570620) becomes 0, making sum(...) equal > > > > 6.188817. Unfortunately this is _not_ what I want, and I apologize > > > > for not being clear in the first place. What I want is: for any > > > > FALSE entry, the original loss number is unaltered, as opposed to > > > > become 0. So in the example above, the four numbers that should have > > > > been added are: 1.401663, 4.570620, 2.068667, 2.718488, yielding > > > > 10.759438 instead of 6.188817. > > > > > > > > Any further suggestions would be greatly appreciated. > > > > > > I'm sorry, but from an anonymous poster that's not a reasonable > > > request. Just work it out yourself. > > > > > > Duncan Murdoch > > > > > > > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > > > >> On 4/26/2007 2:31 PM, xpRt.wannabe wrote: > > > >>> Just to be sure, is what I have below the right intepretation of > > > >>> your suggestion: > > > >> > > > >> Yes, that's what I suggested. > > > >> > > > >> Duncan Murdoch > > > >> > > > >>> 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(100, tmpf()) > > > >>> > > > >>> On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> 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(100, tmpf()) > > > > > > > > Now, I would like to enhance the model by incorporating the > > > > following two probabilities: > > > > > > > > 1. Probability of claim being
Re: [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 [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A coding question involving variable assignments in ifelse()
On 4/27/2007 11:41 AM, Gabor Grothendieck wrote: > I don't think there is any requirement to identify yourself in any > way nor should their be. Many people on the list are in academia > and in those cases they probably want their name in lights but > others may wish to have a lower profile and its common to use > an alias on the net for privacy. I agree with some of the above, but it's also true that there is no requirement on anyone to respond to any particular posting, and you are likely to get more responses if you do identify yourself. If you don't, there's always the possibility that you are a student asking us to do your homework for you, or that you really should hire someone to do your programming. My response may have seemed rude, but I thought at the time that it would have been more rude to ignore the question completely. In my judgment the original answer was sufficient, and the followups showed that Mr./Ms. Anonymous wasn't willing to put a reasonable effort into solving the problem her/himself. Duncan Murdoch > > On 4/27/07, xpRt.wannabe <[EMAIL PROTECTED]> wrote: >> Is this an ad hominem comment or a comment of brevity? Unless my eyes >> are playing tricks on me, I can't seem to find any language in the >> Posting Guide on what is considered a reasonable vs. unreasonable >> request from an anonymous poster. Kindly point me to it if it exists. >> >> In any case, thanks for your time and suggestion. >> >> On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: >> > On 4/26/2007 5:21 PM, xpRt.wannabe wrote: >> > > I made a few slight modifications to the original model in an effort >> > > to see the inner workings of the code: >> > > >> > > deductible <- 1 >> > > coverage.limit <- 2 >> > > insurance.threshold <- deductible + coverage.limit >> > > >> > > >> > > >> > > set.seed(123) >> > > loss <- abs(rnorm(rpois(1, 5), 1, 3)) >> > > 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)) >> > > >> > > [1] 6.188817 >> > > >> > > >> > > >> > > To tease out the data as well as to see the effect of 'accept & >> > > payout', I did the following: >> > > >> > >> loss >> > > [1] 3.401663 4.570620 4.068667 4.718488 >> > >> accept >> > > [1] TRUE FALSE TRUE TRUE # The second loss claim is NOT accepted >> > > by the insurance company. >> > >> payout >> > > [1] TRUE TRUE TRUE TRUE >> > >> accept & payout >> > > [1] TRUE FALSE TRUE TRUE # The second entry is FALSE because of >> > > the second entry in 'accept.' >> > > >> > > Based on the inner ifelse() expression, the original loss numbers >> > > become : 1.401663, 2.570620, 2.068667, 2.718488, respectively (which >> > > is fine and what I wanted). >> > > >> > > Because the second entry in 'accept & payout' is FALSE, the second >> > > altered loss number (2.570620) becomes 0, making sum(...) equal >> > > 6.188817. Unfortunately this is _not_ what I want, and I apologize >> > > for not being clear in the first place. What I want is: for any FALSE >> > > entry, the original loss number is unaltered, as opposed to become 0. >> > > So in the example above, the four numbers that should have been added >> > > are: 1.401663, 4.570620, 2.068667, 2.718488, yielding 10.759438 >> > > instead of 6.188817. >> > > >> > > Any further suggestions would be greatly appreciated. >> > >> > I'm sorry, but from an anonymous poster that's not a reasonable request. >> > Just work it out yourself. >> > >> > Duncan Murdoch >> > >> > > >> > > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: >> > >> On 4/26/2007 2:31 PM, xpRt.wannabe wrote: >> > >>> Just to be sure, is what I have below the right intepretation of your >> > >>> suggestion: >> > >> Yes, that's what I suggested. >> > >> >> > >> Duncan Murdoch >> > >> >> > >>> 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(100, tmpf()) >> > >>> >> > >>> On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> 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))) >> > > }
Re: [R] A coding question involving variable assignments in ifelse()
I don't think there is any requirement to identify yourself in any way nor should their be. Many people on the list are in academia and in those cases they probably want their name in lights but others may wish to have a lower profile and its common to use an alias on the net for privacy. On 4/27/07, xpRt.wannabe <[EMAIL PROTECTED]> wrote: > Is this an ad hominem comment or a comment of brevity? Unless my eyes > are playing tricks on me, I can't seem to find any language in the > Posting Guide on what is considered a reasonable vs. unreasonable > request from an anonymous poster. Kindly point me to it if it exists. > > In any case, thanks for your time and suggestion. > > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > > On 4/26/2007 5:21 PM, xpRt.wannabe wrote: > > > I made a few slight modifications to the original model in an effort > > > to see the inner workings of the code: > > > > > > deductible <- 1 > > > coverage.limit <- 2 > > > insurance.threshold <- deductible + coverage.limit > > > > > > > > > > > > set.seed(123) > > > loss <- abs(rnorm(rpois(1, 5), 1, 3)) > > > 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)) > > > > > > [1] 6.188817 > > > > > > > > > > > > To tease out the data as well as to see the effect of 'accept & > > > payout', I did the following: > > > > > >> loss > > > [1] 3.401663 4.570620 4.068667 4.718488 > > >> accept > > > [1] TRUE FALSE TRUE TRUE # The second loss claim is NOT accepted > > > by the insurance company. > > >> payout > > > [1] TRUE TRUE TRUE TRUE > > >> accept & payout > > > [1] TRUE FALSE TRUE TRUE # The second entry is FALSE because of > > > the second entry in 'accept.' > > > > > > Based on the inner ifelse() expression, the original loss numbers > > > become : 1.401663, 2.570620, 2.068667, 2.718488, respectively (which > > > is fine and what I wanted). > > > > > > Because the second entry in 'accept & payout' is FALSE, the second > > > altered loss number (2.570620) becomes 0, making sum(...) equal > > > 6.188817. Unfortunately this is _not_ what I want, and I apologize > > > for not being clear in the first place. What I want is: for any FALSE > > > entry, the original loss number is unaltered, as opposed to become 0. > > > So in the example above, the four numbers that should have been added > > > are: 1.401663, 4.570620, 2.068667, 2.718488, yielding 10.759438 > > > instead of 6.188817. > > > > > > Any further suggestions would be greatly appreciated. > > > > I'm sorry, but from an anonymous poster that's not a reasonable request. > > Just work it out yourself. > > > > Duncan Murdoch > > > > > > > > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > > >> On 4/26/2007 2:31 PM, xpRt.wannabe wrote: > > >>> Just to be sure, is what I have below the right intepretation of your > > >>> suggestion: > > >> Yes, that's what I suggested. > > >> > > >> Duncan Murdoch > > >> > > >>> 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(100, tmpf()) > > >>> > > >>> On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> 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(100, 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
Re: [R] A coding question involving variable assignments in ifelse()
Is this an ad hominem comment or a comment of brevity? Unless my eyes are playing tricks on me, I can't seem to find any language in the Posting Guide on what is considered a reasonable vs. unreasonable request from an anonymous poster. Kindly point me to it if it exists. In any case, thanks for your time and suggestion. On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > On 4/26/2007 5:21 PM, xpRt.wannabe wrote: > > I made a few slight modifications to the original model in an effort > > to see the inner workings of the code: > > > > deductible <- 1 > > coverage.limit <- 2 > > insurance.threshold <- deductible + coverage.limit > > > > > > > > set.seed(123) > > loss <- abs(rnorm(rpois(1, 5), 1, 3)) > > 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)) > > > > [1] 6.188817 > > > > > > > > To tease out the data as well as to see the effect of 'accept & > > payout', I did the following: > > > >> loss > > [1] 3.401663 4.570620 4.068667 4.718488 > >> accept > > [1] TRUE FALSE TRUE TRUE # The second loss claim is NOT accepted > > by the insurance company. > >> payout > > [1] TRUE TRUE TRUE TRUE > >> accept & payout > > [1] TRUE FALSE TRUE TRUE # The second entry is FALSE because of > > the second entry in 'accept.' > > > > Based on the inner ifelse() expression, the original loss numbers > > become : 1.401663, 2.570620, 2.068667, 2.718488, respectively (which > > is fine and what I wanted). > > > > Because the second entry in 'accept & payout' is FALSE, the second > > altered loss number (2.570620) becomes 0, making sum(...) equal > > 6.188817. Unfortunately this is _not_ what I want, and I apologize > > for not being clear in the first place. What I want is: for any FALSE > > entry, the original loss number is unaltered, as opposed to become 0. > > So in the example above, the four numbers that should have been added > > are: 1.401663, 4.570620, 2.068667, 2.718488, yielding 10.759438 > > instead of 6.188817. > > > > Any further suggestions would be greatly appreciated. > > I'm sorry, but from an anonymous poster that's not a reasonable request. > Just work it out yourself. > > Duncan Murdoch > > > > > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > >> On 4/26/2007 2:31 PM, xpRt.wannabe wrote: > >>> Just to be sure, is what I have below the right intepretation of your > >>> suggestion: > >> Yes, that's what I suggested. > >> > >> Duncan Murdoch > >> > >>> 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(100, tmpf()) > >>> > >>> On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> 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(100, 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 > > >>> __ > >>> R-help@stat.math.ethz.ch mailing list > >>> https://stat.ethz.ch/mailman/listinfo/r-help > >>> PLEASE do read the posting guide > >>> http://www.R-project.org/posting-guide.html > >>> and provide commented, minimal, self-contained, reproducible code. > >> > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and prov
Re: [R] A coding question involving variable assignments in ifelse()
On 4/26/2007 5:21 PM, xpRt.wannabe wrote: > I made a few slight modifications to the original model in an effort > to see the inner workings of the code: > > deductible <- 1 > coverage.limit <- 2 > insurance.threshold <- deductible + coverage.limit > > > > set.seed(123) > loss <- abs(rnorm(rpois(1, 5), 1, 3)) > 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)) > > [1] 6.188817 > > > > To tease out the data as well as to see the effect of 'accept & > payout', I did the following: > >> loss > [1] 3.401663 4.570620 4.068667 4.718488 >> accept > [1] TRUE FALSE TRUE TRUE # The second loss claim is NOT accepted > by the insurance company. >> payout > [1] TRUE TRUE TRUE TRUE >> accept & payout > [1] TRUE FALSE TRUE TRUE # The second entry is FALSE because of > the second entry in 'accept.' > > Based on the inner ifelse() expression, the original loss numbers > become : 1.401663, 2.570620, 2.068667, 2.718488, respectively (which > is fine and what I wanted). > > Because the second entry in 'accept & payout' is FALSE, the second > altered loss number (2.570620) becomes 0, making sum(...) equal > 6.188817. Unfortunately this is _not_ what I want, and I apologize > for not being clear in the first place. What I want is: for any FALSE > entry, the original loss number is unaltered, as opposed to become 0. > So in the example above, the four numbers that should have been added > are: 1.401663, 4.570620, 2.068667, 2.718488, yielding 10.759438 > instead of 6.188817. > > Any further suggestions would be greatly appreciated. I'm sorry, but from an anonymous poster that's not a reasonable request. Just work it out yourself. Duncan Murdoch > > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: >> On 4/26/2007 2:31 PM, xpRt.wannabe wrote: >>> Just to be sure, is what I have below the right intepretation of your >>> suggestion: >> Yes, that's what I suggested. >> >> Duncan Murdoch >> >>> 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(100, tmpf()) >>> >>> On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> 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(100, 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 >>> __ >>> R-help@stat.math.ethz.ch mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A coding question involving variable assignments in ifelse()
I made a few slight modifications to the original model in an effort to see the inner workings of the code: deductible <- 1 coverage.limit <- 2 insurance.threshold <- deductible + coverage.limit set.seed(123) loss <- abs(rnorm(rpois(1, 5), 1, 3)) 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)) [1] 6.188817 To tease out the data as well as to see the effect of 'accept & payout', I did the following: > loss [1] 3.401663 4.570620 4.068667 4.718488 > accept [1] TRUE FALSE TRUE TRUE # The second loss claim is NOT accepted by the insurance company. > payout [1] TRUE TRUE TRUE TRUE > accept & payout [1] TRUE FALSE TRUE TRUE # The second entry is FALSE because of the second entry in 'accept.' Based on the inner ifelse() expression, the original loss numbers become : 1.401663, 2.570620, 2.068667, 2.718488, respectively (which is fine and what I wanted). Because the second entry in 'accept & payout' is FALSE, the second altered loss number (2.570620) becomes 0, making sum(...) equal 6.188817. Unfortunately this is _not_ what I want, and I apologize for not being clear in the first place. What I want is: for any FALSE entry, the original loss number is unaltered, as opposed to become 0. So in the example above, the four numbers that should have been added are: 1.401663, 4.570620, 2.068667, 2.718488, yielding 10.759438 instead of 6.188817. Any further suggestions would be greatly appreciated. On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > On 4/26/2007 2:31 PM, xpRt.wannabe wrote: > > Just to be sure, is what I have below the right intepretation of your > > suggestion: > > Yes, that's what I suggested. > > Duncan Murdoch > > > 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(100, tmpf()) > > > > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> 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(100, 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 > >> > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A coding question involving variable assignments in ifelse()
On 4/26/2007 2:31 PM, xpRt.wannabe wrote: > Just to be sure, is what I have below the right intepretation of your > suggestion: Yes, that's what I suggested. Duncan Murdoch > 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(100, tmpf()) > > On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> 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(100, 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 >> > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A coding question involving variable assignments in ifelse()
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(100, tmpf()) On 4/26/07, Duncan Murdoch <[EMAIL PROTECTED]> 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(100, 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 > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [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(100, 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 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[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(100, 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 major2 minor2.1 year 2005 month12 day 20 svn rev 36812 language R Thanks, __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.