[R] MLE Function

2007-09-10 Thread Terence Broderick
I am just trying to teach myself how to use the mle function in R because it is 
much better than what is provided in MATLAB. I am following tutorial material 
from the internet, however, it gives the following errors, does anybody know 
what is happening to cause such errors, or does anybody know any better 
tutorial material on this particular subject.
  
> x.gam<-rgamma(200,rate=0.5,shape=3.5)
> x<-x.gam
> library(stats4)
> ll<-function(lambda,alfa){n<-200;x<-x.gam 
> -n*alfa*log(lambda)+n*log(gamma(alfa))-9alfa-1)*sum(log(x))+lambda*sum(x)}
Error: syntax error, unexpected SYMBOL, expecting '\n' or ';' or '}' in 
"ll<-function(lambda,alfa){n<-200;x<-x.gam 
-n*alfa*log(lambda)+n*log(gamma(alfa))-9alfa"
> ll<-function(lambda,alfa){n<-200;x<-x.gam 
> -n*alfa*log(lambda)+n*log(gamma(alfa))-(alfa-1)*sum(log(x))+lambda*sum(x)}
> est<-mle(minuslog=ll,start=list(lambda=2,alfa=1))
Error in optim(start, f, method = method, hessian = TRUE, ...) : 
objective function in optim evaluates to length 200 not 1

   
   


audaces fortuna iuvat
   
-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


[R] fitdistr()

2007-09-09 Thread Terence Broderick
I am trying to fit the chi-squared distribution to a set of data using the 
fitdistr function found in the MASS4 library, the data set is called ONES3, I 
have loaded it using the command
   
  ONES3<-read.table("ONES3.pdf",header=TRUE,na="NA")
   
  I print out the dataset ONES3 to the screen to make sure it has loaded
   
  Then I try to fit this data using the command fitdistr
   
   fitdistr(ONES3,"chi-squared")
   
  and it returns the comment 
   
  Error in fitdistr(ONES3, "chi-squared") : 'x' must be a non-empty numeric 
vector

  Can anybody help with this, I imagine it is a common mistake for beginners 
like myself



audaces fortuna iuvat
   
-

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.