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.
azman wrote:> > 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... > >Your example is nice, because it is self-contained (even if there is a buglet). When I run it, I got a message that "object y1 is not found". That comes from a line if (y1<=0) ... which suspiciously looks like a remainder of an old version that ended up at the wrong place. Remove this, and also remove two {} below it which do no harm, but are confusing. Program looked reasonably after this. I also recommend to use good indentation, but it is possible that is has been removed by the mailer. If you are lost again by an error message from a deeply nested call: use traceback() immediately after the message. Dieter -- View this message in context: http://n4.nabble.com/R-beginner-tp1576033p1576971.html Sent from the R help mailing list archive at Nabble.com.
I have try again my function from this email.I just copy and paste it on the R software and it doesn't give any problem like before.Did you change anything to my function? Actually before this I have do others about my research and long time not see this function. Thank you very much for your help... -- View this message in context: http://n4.nabble.com/R-beginner-tp1576033p1839292.html Sent from the R help mailing list archive at Nabble.com.