[R] Error, Variable is missing

R. Michael Weylandt michael.weylandt at gmail.com
Thu Mar 29 17:30:19 CEST 2012


I believe you need to actually pass the values to your function:

pdf(x, mu, sigma, alpha, beta, rho) # Works
pdf(x) # Doesn't.

If not, please show us how you are calling pdf().

Michael

On Thu, Mar 29, 2012 at 9:25 AM, Guaramy <Guaramy at hotmail.com> wrote:
> Hi, I am writing a function to plot a pdf of a distribution
>
> x=seq(-4,4,length=200)
> mu = 0
> sigma = 0.01
> alpha = 17.5
> beta = 17.5
> rho = 0.1
> GNL.pdf.fn = function(x,mu,sigma,alpha,beta,rho)
> {
>                y = x-rho*mu
>        cf.fn = function(s){
>                cplex = complex(1,0,1)
>                temp1 = alpha*beta*exp(-sigma*s^2/2)
>                temp2 = (alpha-cplex*s)*(beta+cplex*s)
>                out = (temp1/temp2)^rho
>                out
>                }
>        temp.fn = function(s){
>                (Mod(cf.fn(s)))*cos(Arg(cf.fn(s))-s*y)
>                        }
>
>        int.fn = function(t){sapply(t,FUN=temp.fn)}
>        te = integrate(int.fn,lower=0,upper=Inf,rel.tol=1e-10,subdivisions=1000000)
>        temp3 = ifelse(te$message == "OK",te$value/pi,NA)
>        temp3
> }
> GNL.pdf.fn(x[100],mu,sigma,alpha,beta,rho)
>
> L = rep(0,length(x))
>
> pdf = function(x,mu,sigma,alpha,beta,rho)
> {
>        for(i in 1:length(x))
>        {
>                L[i] = GNL.pdf.fn(x,mu,sigma,alpha,beta,rho)
>        }
>        L
> }
>
> The GNL function calculates the values of x and its working fine.
> The problem is my pdf function. The aim of that function is to store all the
> values of x in a list L and the plot the result.
> But when I call the pdf function this error keeps ocurring
>
> Error in rho * mu : 'rho' is missing
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Error-Variable-is-missing-tp4515418p4515418.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.



More information about the R-help mailing list