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. Maram [[alternative HTML version deleted]]
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On > Behalf Of maram salem > Sent: Tuesday, October 13, 2009 2:13 PM > To: r-help > Subject: [R] cdf > > 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. > Maram >You say "I want y to remain as it is, ...". where is y defined outside of your function? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
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 >You want to return a function of y, so do it like this: powercdf <- function(a) { force(a) # crucial, so that a gets evaluated now. return( function(y) (y/350)^a ) } Duncan Murdoch> > 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. > Maram > > > > [[alternative HTML version deleted]] > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org 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. >
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