[R] need help in R

Sunny Laws laws at math.utah.edu
Mon May 20 19:45:15 CEST 2002


I am trying to draw the following function Ln and find the value u that
maximizes Ln.

> L<-length(Y)
> sigmasquare<-function(u){   
  upowers<-rep(1,(L-1))
  for(i in 2:(L-1)){upowers[i]<-u*upowers[i-1]}
  0.1/(1-u)+0.5*sum((Y[(L-1):1])^2*upowers[1:(L-1)])
  }
> Ln<-function(u){
  absY <- abs(Y)
  for (k in 1:L) {sun <- -0.5*log(sigmasquare(u)) -
  absY/sqrt(sigmasquare(u))}
  sum(sun)}
Here, Y is a vector with the length L.

To draw the function Ln I tried the following.

> f_seq(0.0, 1.0, 0.01)
> plot(f, Ln(f), type="l", xlab=expression(u), ylab=expression(Ln(u)))
However, R gave me the following message.

Error in xy.coords(x, y, xlabel, ylabel, log) :
        x and y lengths differ

How can I draw function Ln and find the value u that
maximizes Ln numerically?
I will appreciate it very much if you can help me.
Thank you.


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list