[R] R beginner

azman norazman at math.upm.edu.my
Wed Mar 3 05:05:56 CET 2010


hello,
i'am is new in R software.i have try to make a function but it can't give
what it should.i dunno what have to do next.
Can somebody help me to solve it.i'll very appreciate...

##GEV simulation(Non-stationary)
dsim<-function(n, alpha, beta,sca,sha){
t <- 1:n
location <- alpha + beta*t
inv.df<-function(x) location + -(sca/sha)+(sca/sha)*(-log(x))^(-sha)
u<-runif(n)
y<-inv.df(u)
return(y)
}

xdat<-c(3.4,7.8,10.1,11.7,13.9,14.1,14.2,14.6,14.6,14.6,15,15,16.1,18)

##GEV function(Non-stationary)
GEV.lik<-function(a,x)#a=(location,scale,shape)
{
alpha <- a[1]
beta <- a[2]
scale<-a[3]
shape<-a[4]

n <- length(x)
t <- 1:n
location<-100/(1+alpha*exp(beta*x))

if(scale<=0)return(1e+10)
if(y1<=0)return(1e+10)
{
if(min(1+shape*(x-location)/scale)<=0)return(1e+10)
n<- length(x)
y0<- 1+(1/shape)
y1<- (1+shape*(x-location)/scale)
y2<- log(y1)
y3<- y1^(-1/shape)
l<- -n*log(scale)-y0*sum(y2)-sum(y3)
}
return(-l)
}
start<-c(50,-0.5,6.55,0.1)

bl<-c(-Inf,-Inf,0,-0.5)
bu<-c(Inf,Inf,Inf,Inf)

y<-optim(start,GEV.lik,x=xdat,hessian=T)
y
y$par
y$hessian

 
-- 
View this message in context: http://n4.nabble.com/R-beginner-tp1576033p1576033.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list