# [R] cdf

David Winsemius dwinsemius at comcast.net
Wed Oct 14 14:13:55 CEST 2009

```On Oct 13, 2009, at 6:53 PM, Duncan Murdoch wrote:

> On 13/10/2009 6:43 PM, David Winsemius wrote:
>> On Oct 13, 2009, at 5:12 PM, maram salem wrote:
>>> Dear all,
>>> I have the cdf of the following power fuction distribution:
>>> F(y)=(y/350)^a               ,0<y<350,
>>> where " a " is some parameter with range a>0.
>>> I want to use it as the argument of the discretize function of
>>> the  actuar package.
>>>
>>> So I think I need to define this function to R so that if I
>>> entered  a=1, I get the following
>>> F(y)=(y/350)
>>> and if I entered a=4.5, I get the following
>>> F(y) =(y/350)^4.5
>>> ........... and so on
>>>
>>> I've tried
>>> a<-vector(mode="numeric",length=1)
>>> powercdf<-function(a,y)
>>> (y/350)^a
>>>
>>> But when I typed: powercdf(10,y)
>>> instead of getting : (y/350)^10     (which is what I want)
>>>
>>> I want y to remain as it is, a continous variable, not for
>>> example  seq(0,350).
>> If you want symbolic algebra then use a system designed for such.
>> If  you invoke a function in R you need to give it arguments for
>> evaluation  ... to numerical values.
>> If you want a function that returns a function, that is also
>> possible.
>> > cdffn <- function(y, arg) return( function(y) {y^arg} )
>
> But don't do it like that.  If you do, you'll see things like this:
>
> > power <- 10
> > cdf10 <- cdffn(arg=power)  # don't need y as an argument.
> > power <- 1
> > cdf10(1:10)
> [1]  1  2  3  4  5  6  7  8  9 10
>
> See my other post for a correct implementation using force().

not realized how far out of itself a function might look for
arguments. You did mention the crucial aspect of force but I didn't
really get it until this further clue. Sometimes I'm a bit dense.

--
David

>
> Duncan Murdoch
>
>> > cdf10 <- cdffn(y, 10)
>> > cdf10(1:10)
>>  [1]           1        1024       59049     1048576
>> 9765625     60466176   282475249  1073741824
>>  [9]  3486784401 10000000000
>> David Winsemius, MD
>> Heritage Laboratories
>> West Hartford, CT
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help