# [R] Newbie that don't understand R code

Berend Hasselman bhh at xs4all.nl
Mon Aug 17 20:37:47 CEST 2009

```
kfcnhl wrote:
>
> I got some R code that I don't understand.
>
> Question as comment in code
> //where is t comming from, what is phi inverse
>
> rAC <- function(name, n, d, theta){
> .................
> phi.inverse <- switch(name,
> clayton = function(t, theta)
> //where is t comming from, what is phi inverse
> {
> (1 + t)^(-1/theta)
> }
> ,
> gumbel = function(t, theta)
> {
> exp( - t^(1/theta))
> }
> ,
> frank = function(t, theta)
> {
> (-1/theta) * log(1 - (1 - exp( - theta)) * exp( - t))
> }
> ,
> BB9 = function(t, theta)
> {
> exp( - (theta^theta + t)^(1/theta) + theta)
> }
> ,
> GIG = function(t, theta)
> {
> lambda <- theta
> chi <- theta
> psi <- theta
> if (chi==0)
> out <- (1+2*t/psi)^(-lambda)
> else if (psi==0)
> out <- 2^(lambda+1)*exp(besselM3(lambda,sqrt(2*chi*t),log
> value=TRUE)-lambda*log(2*chi*t)/2)/gamma(-lambda)
> else
> out <- exp(besselM3(lambda,sqrt(chi*(psi+2*t)),logvalue=T
> RUE)+lambda*log(chi*psi)/2-besselM3(lambda,sqrt(chi*psi),logvalue=TRUE)-lambda*log(chi*(psi+2*t))/2)
> out
> }
> )
> phi.inverse( - log(U)/Y, theta)
> }
>

1. t comes from the argument of the function object returned when <name> has
the value clayton

clayton = function(t, theta)
####where is t comming from, what is phi inverse
{
(1 + t)^(-1/theta)
}

2. In phi.inverse <- switch(....)  the value returned by the switch
expression is assigned to phi.inverse.
The switch expression appears to return a function object depending on
the value of the <name>
argument to rAC.

3. the code at the end of the rAC function contains two errors (spaces):
log value should be logvalue
T RUE should be TRUE

After corrections it appears to work.

Berend
--
View this message in context: http://www.nabble.com/Newbie-that-don%27t-understand-R-code-tp25009034p25011959.html
Sent from the R help mailing list archive at Nabble.com.

```