Roslina,
this code performs what you need:
dt = matrix((1:(58*12))/58/12,58) # some numbers
# if dt is a data.frame use dt = as.matrix(dt)
a = (1:12)/12 # some a coef
b = (12:1)/12 # some b coef
dtgam = matrix(pgamma(dt,a,b),58)
# dtgam is the transformation you're looking for
no loop needed no transform function involved
cheers,
Patrizio
2009/5/7 Roslina Zakaria <zroslina at yahoo.com>:> Hi R-users,
>
> I have this code to?uniformise the data using gamma:
>
>> length(dp1)
> [1] 696
>> dim(dp1)
> [1] 58 12
>> dim(ahall)
> [1]? 1 12
>> dim(bhall)
> [1]? 1 12
>
>> trans_dt <- function(dt,a,b)
> + { n1 <- ncol(dt)
> +?? n2 <- length(dt)
> +?? trans? <- vector(mode='numeric', length=n2)
> +?? dim(trans) <- dim(dt)
> +?? for (i in 1:n1)
> +?? {? dt[,i] <- as.vector(dt[,i])
> +????? trans[,i] <- transform(dti,newdt=pgamma(dti,shape=
a[1,i],scale=b[1,i])) }
> +?? trans
> + }
>
>> trans_dt(dp1,ahall,bhall)
> Error in transform(dti, newdt = pgamma(dti, shape = a[1, i], scale = b[1,?
:
> ? object "dti" not found
>
> and also try
> trans_dt <- function(dt,a,b)
> { n1 <- ncol(dt)
> ? n2 <- length(dt)
> ? trans? <- vector(mode='numeric', length=n2)
> ? dim(trans) <- dim(dt)
> ? for (i in 1:n1)
> ? {? dti <- dt[,i]
> ???? ai? <- a[1,i]
> ???? bi? <- b[1,i]
> ???? trans[,i] <- transform(dti,newdt=pgamma(dti,shape= ai,scale=bi)) }
> ? trans
> }
>
> trans_dt(dp1,ahall,bhall)
> Error in pgamma(dti, shape = ai, scale = bi) : object "dti" not
found
>
>
> Thank you for any help given.
>
>
>
> ? ? ? ?[[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.
>
>
--
+-------------------------------------------------
| Patrizio Frederic, PhD
| Assistant Professor,
| Department of Economics,
| University of Modena and Reggio Emilia,
| Via Berengario 51,
| 41100 Modena, Italy
|
| tel: +39 059 205 6727
| fax: +39 059 205 6947
| mail: patrizio.frederic at unimore.it
+-------------------------------------------------