[R] cdf
David Winsemius
dwinsemius at comcast.net
Wed Oct 14 00:43:16 CEST 2009
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 got : object y not found ??
>
> I want y to remain as it is, a continous variable, not for example
> seq(0,350).
> Thank you in advance.
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} )
> 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
More information about the R-help
mailing list