Re: [R] A coding question involving variable assignments in ifelse()

2007-04-27 Thread xpRt.wannabe
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
 
  snip
 
  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
 
  snip
 
  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.


[R] A coding question involving variable assignments in ifelse()

2007-04-26 Thread xpRt.wannabe
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.


Re: [R] A coding question involving variable assignments in ifelse()

2007-04-26 Thread xpRt.wannabe
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()

2007-04-26 Thread xpRt.wannabe
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

snip

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

snip

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] How to iteratively extract elements out of a list

2006-08-26 Thread xpRt.wannabe
Thank you!

On 8/26/06, Patrick Burns [EMAIL PROTECTED] wrote:
   sub.m - lapply(m, function(x)x[x2])
   sub.m
 [[1]]
 [1] 3 4

 [[2]]
 [1] 4 5

 [[3]]
 [1] 4

   sub.m[unlist(lapply(sub.m, function(x) length(x) == 2))]
 [[1]]
 [1] 3 4

 [[2]]
 [1] 4 5

   sub4.m - lapply(m, function(x)x[x4])
   sub4.m[unlist(lapply(sub4.m, function(x) length(x)  0))]
 [[1]]
 [1] 5


 Patrick Burns
 [EMAIL PROTECTED]
 +44 (0)20 8525 0696
 http://www.burns-stat.com
 (home of S Poetry and A Guide for the Unwilling S User)

 xpRt.wannabe wrote:

 Yet another question:
 
 Let's say I do the following:
 
 set.seed(123)
 tmpf - function(){
 x - rpois(rpois(1,4),2)
 }
 n - 3
 m - replicate(n, tmpf())
 m
 sub.m - lapply(m, function(x)x[x2])
 
 'sub.m' gives me:
 
 [[1]]
 [1] 3 4
 
 [[2]]
 [1] 4 5
 
 [[3]]
 [1] 4
 
 The question is:  What do I need to do such that I can extract
 componets of length 2 in 'sub.m' into another sublist, which would
 look like this:
 
 [[1]]
 [1] 3 4
 
 [[2]]
 [1] 4 5
 
 I think that's all the questions I can think of -- for now.
 
 Many, many thanks!!!
 
 On 8/25/06, xpRt. wannabe [EMAIL PROTECTED] wrote:
 
 
 Jim and Patrick,
 
 Both of you made the same suggestion, which works great!
 
 A follow-up question: Suppose I change the condition 'x2' in 'lapply'
 to 'x4', as follows:
 
 set.seed(123)
 tmpf - function() {
 x - rpois(rpois(1,4),2)
 }
 n - 3
 m - replicate(n,tmpf())
 m
 sub.m - lapply(m, function(x)x[x4])  # was x2
 
 As a result, I'd get:
 
 
 
 sub.m
 
 
 [[1]]
 numeric(0)
 
 [[2]]
 [1] 5
 
 [[3]]
 numeric(0)
 
 However, what would I need to do such that 'sub.m' contains only the
 non-zero length component; namely, the 'sub.m[[2]]'?  In essence, I'd
 like to drop all the components of zero length such that 'sub.m'
 results in:
 
 [[1]]
 [1] 5
 
 My best effort was to use 'lapply' again:
 
 lapply(sub.m, function(x)x[length(x)0])
 
 which still gives me:
 
 [[1]]
 numeric(0)
 
 [[2]]
 [1] 5
 
 [[3]]
 numeric(0)
 
 Again, any help would be greately appreciated.
 
 p.s. Sorry to bug you again.   I should have thought through a little
 more prior to composing an example that would represent all possible
 scenarios.
 
 On 8/25/06, jim holtman [EMAIL PROTECTED] wrote:
 
 
 try this:
 
 
 
 set.seed(123)
 tmpf - function() {
 
 
 + x - rpois(rpois(1,4),2)
 + }
 
 
 n - 3
 m - replicate(n,tmpf())
 m
 
 
 [[1]]
 [1] 3 2 4
 
 [[2]]
 [1] 0 2 4 2 2 5 2
 
 [[3]]
 [1] 2 0 4 1 0
 
 
 
 lapply(m, function(x)x[x2])
 
 
 [[1]]
 [1] 3 4
 
 [[2]]
 [1] 4 5
 
 [[3]]
 [1] 4
 
 
 
 On 8/25/06, xpRt.wannabe [EMAIL PROTECTED] wrote:
 
 
 Dear List,
 
 The following code produces a list, which is what I what:
 
 set.seed(123)
 tmpf - function() {
 x - rpois(rpois(1,4),2)
 }
 n - 3
 m - replicate(n,tmpf())
 m
 
 [[1]]
 [1] 3 2 4
 
 [[2]]
 [1] 0 2 4 2 2 5 2
 
 [[3]]
 [1] 2 0 4 1 0
 
 
 Now I need something that would to extract iteratively (or as many
 times as
 the size of 'n') the values that are greater than 2 in each component
 of
 'm' into another list such that the sub-list would be:
 
 [[1]]
 [1] 3 4
 
 [[2]]
 [1] 4 5
 
 [[3]]
 [1] 4
 
 Below is what I tried:
 
 for(i in 1:3)
 sub.list - lapply(m,subset,m[[i]]2)
 
 
 
 sub.list
 
 
 which gives me something different from what I want:
 
 [[1]]
 [1] 4
 
 [[2]]
 [1] 4
 
 [[3]]
 [1] 4
 
 Any help would be appreciated.
 
 
 
 version
 
 
 _
 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
 
 __
 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.
 
 
 
 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem you are trying to solve?
 
 
 
 
 __
 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.


[R] How to iteratively extract elements out of a list

2006-08-25 Thread xpRt.wannabe
Dear List,

The following code produces a list, which is what I what:

set.seed(123)
tmpf - function() {
x - rpois(rpois(1,4),2)
}
n - 3
m - replicate(n,tmpf())
m

[[1]]
[1] 3 2 4

[[2]]
[1] 0 2 4 2 2 5 2

[[3]]
[1] 2 0 4 1 0


Now I need something that would to extract iteratively (or as many
times as
the size of 'n') the values that are greater than 2 in each component
of
'm' into another list such that the sub-list would be:

[[1]]
[1] 3 4

[[2]]
[1] 4 5

[[3]]
[1] 4

Below is what I tried:

for(i in 1:3)
sub.list - lapply(m,subset,m[[i]]2)

 sub.list

which gives me something different from what I want:

[[1]]
[1] 4

[[2]]
[1] 4

[[3]]
[1] 4

Any help would be appreciated.

 version
 _
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

__
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] How to iteratively extract elements out of a list

2006-08-25 Thread xpRt.wannabe
Jim and Patrick,

Both of you made the same suggestion, which works great!

A follow-up question: Suppose I change the condition 'x2' in 'lapply'
to 'x4', as follows:

set.seed(123)
tmpf - function() {
x - rpois(rpois(1,4),2)
}
n - 3
m - replicate(n,tmpf())
m
sub.m - lapply(m, function(x)x[x4])  # was x2

As a result, I'd get:

 sub.m

[[1]]
numeric(0)

[[2]]
[1] 5

[[3]]
numeric(0)

However, what would I need to do such that 'sub.m' contains only the
non-zero length component; namely, the 'sub.m[[2]]'?  In essence, I'd
like to drop all the components of zero length such that 'sub.m'
results in:

[[1]]
[1] 5

My best effort was to use 'lapply' again:

lapply(sub.m, function(x)x[length(x)0])

which still gives me:

[[1]]
numeric(0)

[[2]]
[1] 5

[[3]]
numeric(0)

Again, any help would be greately appreciated.

p.s. Sorry to bug you again.   I should have thought through a little
more prior to composing an example that would represent all possible
scenarios.

On 8/25/06, jim holtman [EMAIL PROTECTED] wrote:
 try this:

  set.seed(123)
  tmpf - function() {
 + x - rpois(rpois(1,4),2)
 + }
  n - 3
  m - replicate(n,tmpf())
  m
 [[1]]
 [1] 3 2 4

 [[2]]
 [1] 0 2 4 2 2 5 2

 [[3]]
 [1] 2 0 4 1 0

  lapply(m, function(x)x[x2])
 [[1]]
 [1] 3 4

 [[2]]
 [1] 4 5

 [[3]]
 [1] 4

 

 On 8/25/06, xpRt.wannabe [EMAIL PROTECTED] wrote:
  Dear List,
 
  The following code produces a list, which is what I what:
 
  set.seed(123)
  tmpf - function() {
  x - rpois(rpois(1,4),2)
  }
  n - 3
  m - replicate(n,tmpf())
  m
 
  [[1]]
  [1] 3 2 4
 
  [[2]]
  [1] 0 2 4 2 2 5 2
 
  [[3]]
  [1] 2 0 4 1 0
 
 
  Now I need something that would to extract iteratively (or as many
  times as
  the size of 'n') the values that are greater than 2 in each component
  of
  'm' into another list such that the sub-list would be:
 
  [[1]]
  [1] 3 4
 
  [[2]]
  [1] 4 5
 
  [[3]]
  [1] 4
 
  Below is what I tried:
 
  for(i in 1:3)
  sub.list - lapply(m,subset,m[[i]]2)
 
   sub.list
 
  which gives me something different from what I want:
 
  [[1]]
  [1] 4
 
  [[2]]
  [1] 4
 
  [[3]]
  [1] 4
 
  Any help would be appreciated.
 
   version
  _
  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
 
  __
  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.
 


 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem you are trying to solve?


__
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] How to iteratively extract elements out of a list

2006-08-25 Thread xpRt.wannabe
Yet another question:

Let's say I do the following:

set.seed(123)
tmpf - function(){
x - rpois(rpois(1,4),2)
}
n - 3
m - replicate(n, tmpf())
m
sub.m - lapply(m, function(x)x[x2])

'sub.m' gives me:

[[1]]
[1] 3 4

[[2]]
[1] 4 5

[[3]]
[1] 4

The question is:  What do I need to do such that I can extract
componets of length 2 in 'sub.m' into another sublist, which would
look like this:

[[1]]
[1] 3 4

[[2]]
[1] 4 5

I think that's all the questions I can think of -- for now.

Many, many thanks!!!

On 8/25/06, xpRt. wannabe [EMAIL PROTECTED] wrote:
 Jim and Patrick,

 Both of you made the same suggestion, which works great!

 A follow-up question: Suppose I change the condition 'x2' in 'lapply'
 to 'x4', as follows:

 set.seed(123)
 tmpf - function() {
 x - rpois(rpois(1,4),2)
 }
 n - 3
 m - replicate(n,tmpf())
 m
 sub.m - lapply(m, function(x)x[x4])  # was x2

 As a result, I'd get:

  sub.m

 [[1]]
 numeric(0)

 [[2]]
 [1] 5

 [[3]]
 numeric(0)

 However, what would I need to do such that 'sub.m' contains only the
 non-zero length component; namely, the 'sub.m[[2]]'?  In essence, I'd
 like to drop all the components of zero length such that 'sub.m'
 results in:

 [[1]]
 [1] 5

 My best effort was to use 'lapply' again:

 lapply(sub.m, function(x)x[length(x)0])

 which still gives me:

 [[1]]
 numeric(0)

 [[2]]
 [1] 5

 [[3]]
 numeric(0)

 Again, any help would be greately appreciated.

 p.s. Sorry to bug you again.   I should have thought through a little
 more prior to composing an example that would represent all possible
 scenarios.

 On 8/25/06, jim holtman [EMAIL PROTECTED] wrote:
  try this:
 
   set.seed(123)
   tmpf - function() {
  + x - rpois(rpois(1,4),2)
  + }
   n - 3
   m - replicate(n,tmpf())
   m
  [[1]]
  [1] 3 2 4
 
  [[2]]
  [1] 0 2 4 2 2 5 2
 
  [[3]]
  [1] 2 0 4 1 0
 
   lapply(m, function(x)x[x2])
  [[1]]
  [1] 3 4
 
  [[2]]
  [1] 4 5
 
  [[3]]
  [1] 4
 
  
 
  On 8/25/06, xpRt.wannabe [EMAIL PROTECTED] wrote:
   Dear List,
  
   The following code produces a list, which is what I what:
  
   set.seed(123)
   tmpf - function() {
   x - rpois(rpois(1,4),2)
   }
   n - 3
   m - replicate(n,tmpf())
   m
  
   [[1]]
   [1] 3 2 4
  
   [[2]]
   [1] 0 2 4 2 2 5 2
  
   [[3]]
   [1] 2 0 4 1 0
  
  
   Now I need something that would to extract iteratively (or as many
   times as
   the size of 'n') the values that are greater than 2 in each component
   of
   'm' into another list such that the sub-list would be:
  
   [[1]]
   [1] 3 4
  
   [[2]]
   [1] 4 5
  
   [[3]]
   [1] 4
  
   Below is what I tried:
  
   for(i in 1:3)
   sub.list - lapply(m,subset,m[[i]]2)
  
sub.list
  
   which gives me something different from what I want:
  
   [[1]]
   [1] 4
  
   [[2]]
   [1] 4
  
   [[3]]
   [1] 4
  
   Any help would be appreciated.
  
version
   _
   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
  
   __
   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.
  
 
 
  --
  Jim Holtman
  Cincinnati, OH
  +1 513 646 9390
 
  What is the problem you are trying to solve?
 


__
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] Fitting Truncated Lognormal to a truncated data set (was: fitting truncated normal distribution)

2006-08-17 Thread xpRt.wannabe
Dear List,

I am trying to fit Truncated Lognormal to a data set that is
'truncated' from above a certain value, say, 0.01.  Below is what I
was able to come up with.  I would appreciate it if you could review
and make any necessary changes.

# This is modified off the code for 'dtnorm' of library(msm).
dtlnorm - function (n, mean = 0, sd = 1, lower = -Inf, upper = Inf)
{
   ret - numeric()
   if (length(n)  1)
   n - length(n)
   while (length(ret)  n) {
   y - rlnorm(n - length(ret), mean, sd)
   y - y[y = lower  y = upper]
   ret - c(ret, y)
   }
   stopifnot(length(ret) == n)
   ret
}

# This is modified off the code for 'rtnorm' of the library(msm).
rtlnorm - function (n, mean = 0, sd = 1, lower = -Inf, upper = Inf)
{
   ret - numeric()
   if (length(n)  1)
   n - length(n)
   while (length(ret)  n) {
   y - rlnorm(n - length(ret), mean, sd)
   y - y[y = lower  y = upper]
   ret - c(ret, y)
   }
   stopifnot(length(ret) == n)
   ret
}

x - rtlnorm(100, mean=-11.64857, sd = 3.422795, 0.01)

fitting truncated normal distribution on 8/16/2006.
dtlnorm0 - function(x, mean = 0, sd = 1)
{
dtlnorm(x, mean, sd, 0.01, Inf)
}

fitdistr(x, dtlnorm0, start = list(mean = -11, sd = 1))

Thank you.

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

__
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

2006-06-02 Thread xpRt.wannabe
Uwe and Ben,

Thank you both for your help.

To me, both sets of code seem to do the job and should produce the
same results.  However, as a test I inserted set.seed( ) as follows.
Unless I put set.seed( ) in the wrong lines, the results produced by
both sets of code turn out to be different.  I am baffled.

y - replicate(10, {
set.seed(123)
rp - rpois(8, 5)
mysum - sapply(rp, function(x) {
set.seed(123)
x - rnorm(x)
x - x - max(0, x-15) + max(0, x-90)
sum(x)
})
 })

##

tmpf - function() {
set.seed(123)
x - rnorm(rpois(1,5))
sum(ifelse(x90,x-75,pmin(x,15)))
}
replicate(10,replicate(8,tmpf()))

On 6/2/06, Uwe Ligges [EMAIL PROTECTED] wrote:
 xpRt.wannabe wrote:

  Dear List:
 
  I have the follow code:
 
  y - replicate(10,replicate(8,sum(rnorm(rpois(1,5)
 
  Now I need to apply the following condition to _every_ randomly generated
  Normal number in the code above:
 
  x - max(0,x-15) + max(0,x-90), where x represents the individual Normal
  numbers.
 
  In other words, the said condition needs to be applied before
  replicate(...(replicate(...(sum(...))) takes place.
 
  Any help would be greatly appreciated.


 y - replicate(10, {
 rp - rpois(8, 5)
 mysum - sapply(rp, function(x) {
 x - rnorm(x)
 x - x - max(0, x-15) + max(0, x-90)
 sum(x)
 })
  })

__
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


[R] A coding question

2006-06-01 Thread xpRt.wannabe
Dear List:

I have the follow code:

y - replicate(10,replicate(8,sum(rnorm(rpois(1,5)

Now I need to apply the following condition to _every_ randomly generated
Normal number in the code above:

x - max(0,x-15) + max(0,x-90), where x represents the individual Normal
numbers.

In other words, the said condition needs to be applied before
replicate(...(replicate(...(sum(...))) takes place.

Any help would be greatly appreciated.


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

__
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


[R] Is there a way to view S-PLUS script files in R

2006-03-16 Thread xpRt.wannabe
Dear List,

I have some S-PLUS script files (.ssc).  Does there exist an R
function/command  that can read such files?  I simply want to view the
code and practice in R to help me learn the subject matter.

Any help would be greatly appreciated.

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

__
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


[R] How to show the intermediate tick marks without the values in a different color

2006-03-02 Thread xpRt.wannabe
Is there a way to show also the intermediate tick marks without the
values?

Example:

plot(cars)

What would one do to show the tick marks in, say, gray color at the
increment of 1 without showing the actual values in-between the default
x
values: 5, 10, 15, 20, 25?

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


[R] Another question related to box-percentile plot, bpplot(): How to color the box or middle half of the data

2005-10-18 Thread xpRt.wannabe
Dear List,

A follow-up question related to bpplot() of the Hmisc package: How does
one
color the box , or the middle half of the data, of a box-percentile
plot?
bpplot(... , col=lightgray) apparently does not work, though
boxplot(...
, col=lightgray) works.

With much appreciation,

platform i386-pc-mingw32
arch i386
os   mingw32
system   i386, mingw32
status
major2
minor1.0
year 2005
month04
day  18
language R

__
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


[R] A two-part question about box-percentile plots, bpplot(): (1) yaxt=n doesn't seem to work (2) how to display mean values

2005-10-17 Thread xpRt.wannabe
Dear List,

I have a two-part question related to bpplot(), a box-percentile plot
function in the Hmisc package.

Take the example given in the Help for bpplot(), for instance.

(1) How does one set but not draw the y-axis?  What I did was,
bpplot(... , yaxt=n), but that apparently does not work (though it
works for boxplot()).

(2) How does one display the mean value of each variable inside each
respective box-percentile box?  The following is what I did but to no
avail:

 bpplot(x1, x2, x3)
 points(1:1, mean(x1), pch = 1)
 points(1:1, mean(x2), pch = 2)
 points(1:1, mean(x3), pch = 3)

Your help is much appreciated.

platform i386-pc-mingw32
arch i386
os   mingw32
system   i386, mingw32
status
major2
minor1.0
year 2005
month04
day  18
language R

__
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


[R] Add lines to density plot

2005-09-16 Thread xpRt.wannabe
Dear List,

I am using R to learn bootstrapping concepts. Not to be oblivious to 
the
contributed packages of boot and bootstrap, I have opted to do the
following as a way to hone my R skills.

One example I am trying to work through is the following:

x - 1:20
Observed - sample(x,20)
Resamples - replicate(1000,sample(Observed,replace=TRUE))
Boot.Means - apply(Resamples,2,mean)
plot(density(Boot.Means))

For the life of me, I can't seem to figure out how to add two lines to 
the
density plot:

1. A line that represents the mean of Boot.Means
2. A line that represents the mean of Observed

Any help/pointer would be greatly appreciated. I have tried lines() 
but to
no avail.

[[alternative HTML version deleted]]

__
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


[R] A coding question involving variable assignments

2005-08-11 Thread xpRt.wannabe
Dear List,

I have the following code that does what I want:

x - replicate(5,replicate(10,sum(rnorm(rpois(1,10)

How might one change it such that the maximum value generated by
rnorm(rpois(1,10)) can be retrieved for later use?

__
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


Re: [R] A coding question involving variable assignments

2005-08-11 Thread xpRt.wannabe
Jim and List,

Thank you for the prompt reply.  Perhaps I should have been more
specific in the way I phrased the question.

The code you gave would return the max value just one time.  I was
interested in getting as many max values generated by
rnorm(rpois(1,10)) as specified by:

 replicate(5,replicate(10 ... )

In the end, I expect to get 10 x 5 max values.

In that context, how might the code be changed?

On 8/11/05, jim holtman [EMAIL PROTECTED] wrote:
 temp - rnorm(rpois(1,10))
 x - replicate(5,replicate(10,sum(temp)))
 temp - max(temp)
 
 On 8/11/05, xpRt.wannabe [EMAIL PROTECTED] wrote:
  Dear List,
 
  I have the following code that does what I want:
 
  x - replicate(5,replicate(10,sum(rnorm(rpois(1,10)
 
  How might one change it such that the maximum value generated by
  rnorm(rpois(1,10)) can be retrieved for later use?
 
  __
  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
 
 
 
 --
 Jim Holtman
 Convergys
 +1 513 723 2929
 
 What the problem you are trying to solve?


__
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


Re: [R] A coding question involving variable assignments

2005-08-11 Thread xpRt.wannabe
Ted and List,

In your code that produced 'mx', you dropped sum() from my original
code though.  As a result, the 10 x 5 max's are of the same value. 
Unfortunately, that's not what I need.


On 8/11/05, ecatchpole [EMAIL PROTECTED] wrote:
 On 12/08/05 05:55,  xpRt.wannabe wrote,:
  Dear List,
 
  I have the following code that does what I want:
 
  x - replicate(5,replicate(10,sum(rnorm(rpois(1,10)
 
  How might one change it such that the maximum value generated by
  rnorm(rpois(1,10)) can be retrieved for later use?
 
 set.seed(99)
 x - replicate(5,replicate(10,sum(rnorm(rpois(1,10)
 set.seed(99)
 mx - replicate(5,replicate(10,max(rnorm(rpois(1,10)
 
 should work?
 
 Ted.
 --
 Dr E.A. Catchpole
 Visiting Fellow
 Univ of New South Wales at ADFA, Canberra, Australia
 and University of Kent, Canterbury, England
 - www.ma.adfa.edu.au/~eac
 - fax: +61 2 6268 8786
 - ph:  +61 2 6268 8895


__
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


Re: [R] A coding question involving variable assignments

2005-08-11 Thread xpRt.wannabe
Ted and List,

What I need is I need to know what max of rnorm(rpois(1,10)) is before
R does sum(), replicate(10, ...) and replicate(5, ...).

The fact that you have set.seed(99) twice, does that mean, say, entry
[1,1] 0.4896243 in 'mx' is one of the z number of values generated by
rnorm(rpois(1,10)) that add up to [1,1]  -2.0071674 in 'x'?  Another
way to ask the question, I guess, is, by doing set.seed(99) twice are
the values generated by rnorm(rpois(1,10)) for 'x' same as those for
'mx'?


On 8/11/05, ecatchpole [EMAIL PROTECTED] wrote:
 Sorry, I don't follow. What's wrong with this?
 
 Ted.
 
   set.seed(99)
x - replicate(5,replicate(10,sum(rnorm(rpois(1,10)
   set.seed(99)
   mx - replicate(5,replicate(10,max(rnorm(rpois(1,10)
   x
 [,1][,2][,3]   [,4]   [,5]
  [1,] -2.0071674  -7.0883335 -0.03766649  2.6859415 -5.4685172
  [2,] -4.7211799   2.4177121 -0.92575948 -7.2201952 -2.5969177
  [3,]  0.2325584  -0.1790635 -3.17988580 -2.0249829  1.6994276
  [4,] -1.7738725   1.5836438  5.06193854 -5.4798269 -2.4363479
  [5,] -3.0394562   2.8859440  2.67993750  5.0534413  0.6560877
  [6,]  6.2436591  -4.0226431  1.97545757 -1.5641548  4.0443831
  [7,]  0.4641453 -10.4417831  1.08048629  2.4675178 -5.5114109
  [8,]  1.1570728  -3.6081361  1.37858782  0.3534015  1.8282236
  [9,]  4.3988625   3.0692562 -0.69898483 -1.6882952 -1.1548913
 [10,] -3.7288105  -1.4455309  5.80146323 -6.1962790 -1.3698381
   mx
[,1]  [,2]  [,3]  [,4] [,5]
  [1,] 0.4896243 1.4110132 0.7329387 3.2700493 1.861891
  [2,] 1.0989215 1.6215407 1.5980779 2.2921963 1.417614
  [3,] 1.4000518 1.4867612 1.0130372 0.5686142 1.442630
  [4,] 0.5981696 2.0916016 2.0894395 0.9760749 1.419316
  [5,] 1.0066032 1.8084703 1.6556502 2.1431458 2.393037
  [6,] 2.7329641 1.8689793 1.1494738 1.2899945 1.702919
  [7,] 0.5851713 0.6224785 2.4466643 1.1955567 0.951106
  [8,] 1.3850466 0.9305735 1.4003689 1.5209779 1.864211
  [9,] 1.8645760 1.1958389 0.9270208 0.4971312 1.576020
 [10,] 1.5889265 1.0253490 4.6865908 0.9852816 1.032410
 
 
 On 12/08/05 12:17,  xpRt.wannabe wrote,:
  Ted and List,
 
  In your code that produced 'mx', you dropped sum() from my original
  code though.  As a result, the 10 x 5 max's are of the same value.
  Unfortunately, that's not what I need.
 
 
  On 8/11/05, ecatchpole [EMAIL PROTECTED] wrote:
 On 12/08/05 05:55,  xpRt.wannabe wrote,:
 Dear List,
 
 I have the following code that does what I want:
 
 x - replicate(5,replicate(10,sum(rnorm(rpois(1,10)
 
 How might one change it such that the maximum value generated by
 rnorm(rpois(1,10)) can be retrieved for later use?
 set.seed(99)
 x - replicate(5,replicate(10,sum(rnorm(rpois(1,10)
 set.seed(99)
 mx - replicate(5,replicate(10,max(rnorm(rpois(1,10)
 
 should work?
 
 Ted.
 --
 Dr E.A. Catchpole
 Visiting Fellow
 Univ of New South Wales at ADFA, Canberra, Australia
 and University of Kent, Canterbury, England
 - www.ma.adfa.edu.au/~eac
 - fax: +61 2 6268 8786
 - ph:  +61 2 6268 8895
 
 
 
 --
 Dr E.A. Catchpole
 Visiting Fellow
 Univ of New South Wales at ADFA, Canberra, Australia
 and University of Kent, Canterbury, England
 - www.ma.adfa.edu.au/~eac
 - fax: +61 2 6268 8786
 - ph:  +61 2 6268 8895


__
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


Re: [R] A coding question involving variable assignments

2005-08-11 Thread xpRt.wannabe
Thank you!  That was helpful.

Another thing I learned was that I would need to do set.seed(99) not
once but twice in this context.

On 8/11/05, ecatchpole [EMAIL PROTECTED] wrote:
 On 12/08/05 13:27,  xpRt.wannabe wrote,:
  Ted and List,
 
  What I need is I need to know what max of rnorm(rpois(1,10)) is before
  R does sum(), replicate(10, ...) and replicate(5, ...).
 
  The fact that you have set.seed(99) twice, does that mean, say, entry
  [1,1] 0.4896243 in 'mx' is one of the z number of values generated by
  rnorm(rpois(1,10)) that add up to [1,1]  -2.0071674 in 'x'?  Another
  way to ask the question, I guess, is, by doing set.seed(99) twice are
  the values generated by rnorm(rpois(1,10)) for 'x' same as those for
  'mx'?
 
 Yes, that's the reason for having a set.seed() function.
 
 Ted.
 
 --
 Dr E.A. Catchpole
 Visiting Fellow
 Univ of New South Wales at ADFA, Canberra, Australia
 and University of Kent, Canterbury, England
 - www.ma.adfa.edu.au/~eac
 - fax: +61 2 6268 8786
 - ph:  +61 2 6268 8895


__
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