كبريــاء فتــــاة at pubhealth.ku.dk
2009-Feb-04 16:45 UTC
[Rd] Problem using option packeg with new R version (PR#13498)
Hello, I'm facing a problem, using "optim" packeg. I've
written a program and run it using the latest R version 2.8.1,but there was an
error message as following:
R version 2.7.2 (2008-08-25) # same result when I use R version 2.8.1,Copyright
(C) 2008 The R Foundation for Statistical ComputingISBN 3-900051-07-0R is free
software and comes with ABSOLUTELY NO WARRANTY.You are welcome to redistribute
it under certain conditions.Type 'license()' or 'licence()' for
distribution details. Natural language support but running in an English
localeR is a collaborative project with many contributors.Type
'contributors()' for more information and'citation()' on how to
cite R or R packages in publications.Type 'demo()' for some demos,
'help()' for on-line help, or'help.start()' for an HTML browser
interface to help.Type 'q()' to quit R.>
#=========================================================> #3rd trial>
#=========================================================> >
X<-matrix(rnorm(30),5,6)> X [,1] [,2] [,3]
[,4] [,5] [,6][1,] -0.27769355 0.54293814 -1.93856940 -1.8097458
-0.9172400 -0.5542488[2,] -0!
.09146831 0.26066833 0.91905734 0.2981062 0.4640875 -0.1789108[3,]
-0.99167996 -0.64401482 -0.08517589 -0.4101295 1.5204661 1.3439740[4,]
-1.54003312 -0.03145120 0.17489151 1.1248919 0.6047474 1.1909949[5,]
-0.94150604 0.19836236 -0.63982776 0.5272774 -0.4088086 -0.2593536> >
n<-nrow(X)> p<-ncol(X)> n[1] 5> p[1] 6> >
v<-rep(0,p-1)> v[1] 0 0 0 0 0> > fn1<-function(v) {+
a<-sum(v*v)+ u<-v/sqrt(1+a)+ b<-sum(u*u)+ u[length(v)+1]<-sqrt(1+b)+
c<<- X %*% u # also I try c<- X %*% u+ fn1<- -
optim(c(0,1),fn2,NULL,method="BFGS",c)$value+ }> > >
fn2<-function(par){+ fn2<-
-length(c)*log(par[2])+sum(log(par[2]*par[2]+(c-par[1])*(c-par[1])))+ }>
optim(v,fn1,NULL,method="BFGS",X)Error in fn(par, ...) : unused
argument(s) (c(-0.277693546148993, -0.091468312551809, -0.99167995523182,
-1.5400331178273, -0.941506038285282, 0.542938135331624, 0.260668332757676,
-0.64401482390065, -0.0314512041135196, 0.198362357527128, -1.93856939573315,
0.919057338245786, -0.085175885159938, 0!
.174891510504697, -0.639827759135, -1.80974578397221, 0.298106!
24003356
9, -0.410129481117372, 1.12489185606582, 0.527277375478827, -0.917240000748393,
0.464087477214494, 1.52046606812109, 0.60474736264106, -0.408808568730677,
-0.554248793092077, > > > c<-rnorm(10)> v<-rnorm(10)>
w<-rexp(10)> fn1<-function(v) {+ for(i in 1:10){+ par[1]<-v[i]+
par[2]<-w[i]+ a[i]<-optim(par,fn2, NULL,method="BFGS",c)$value+
}+ }> fn2<-function(par){+ fn2<-
-length(c)*log(par[2])+sum(log(par[2]*par[2]+(c-par[1])*(c-par[1])))+ }> >
optim(v,fn1,NULL,method="BFGS",X)Error in fn(par, ...) : unused
argument(s) (c(-0.277693546148993, -0.091468312551809, -0.99167995523182,
-1.5400331178273, -0.941506038285282, 0.542938135331624, 0.260668332757676,
-0.64401482390065, -0.0314512041135196, 0.198362357527128, -1.93856939573315,
0.919057338245786, -0.085175885159938, 0.174891510504697, -0.639827759135,
-1.80974578397221, 0.298106240033569, -0.410129481117372, 1.12489185606582,
0.527277375478827, -0.917240000748393, 0.464087477214494, 1.52046606812109,
0.60474736264106, -0.40!
8808568730677, -0.554248793092077, >
Wihle, when I run the same program on the old Version 1.7.1, I've got
different result as follows:R : Copyright 2003, The R Development Core
TeamVersion 1.7.1 (2003-06-16)R is free software and comes with ABSOLUTELY NO
WARRANTY.You are welcome to redistribute it under certain conditions.Type
`license()' or `licence()' for distribution details.R is a collaborative
project with many contributors.Type `contributors()' for more
information.Type `demo()' for some demos, `help()' for on-line help,
or`help.start()' for a HTML browser interface to help.Type `q()' to quit
R.[Previously saved workspace restored]>
#=========================================================> #3rd trial>
#=========================================================> >
X<-matrix(rnorm(30),5,6)> X [,1] [,2] [,3]
[,4] [,5] [,6][1,] 0.3857697 -0.676798170 -1.39627127 -0.5585526
0.49491835 -1.5055718[2,] -1.3984869 0.036486347 -0.27965160 0.4181540
0.28574020 -0.!
1874612[3,] 0.4118289 0.062688233 1.67673064 0.3231048 -0.58132802
-1.5297349[4,] -0.8236798 -2.142110808 0.07844006 2.4561737 -0.08797541
0.1006625[5,] -1.6269258 0.004665647 1.21449692 -0.5522195 -1.57935227
0.7255697> > n<-nrow(X)> p<-ncol(X)> n[1] 5> p[1] 6>
> v<-rep(0,p-1)> v[1] 0 0 0 0 0> > > fn1<-function(v) {+
a<-sum(v*v)+ u<-v/sqrt(1+a)+ b<-sum(u*u)+ u[length(v)+1]<-sqrt(1+b)+
c<<- X %*% u+ #c<- X %*% u+ fn1<- -
optim(c(0,1),fn2,NULL,method="BFGS",c)$value+ }> > >
fn2<-function(par){+ fn2<-
-length(c)*log(par[2])+sum(log(par[2]*par[2]+(c-par[1])*(c-par[1])))+ }>
optim(v,fn1,NULL,method="BFGS",X)$par[1] 0.3857697 -1.3984869
2.0925084 3.2370430 -1.6269258$value[1] -6.132011$countsfunction gradient
15 15 $convergence[1] 0$message[1] "CONVERGENCE: REL_REDUCTION_OF_F
<= FACTR*EPSMCH"There were 50 or more warnings (use warnings() to see
the first 50)>
#=====================================================================================>
> c<-rn!
orm(10)> v<-rnorm(10)> w<-rexp(10)> fn1<-function(v) {+ for(i
!
in 1:10)
{+ par[1]<-v[i]+ par[2]<-w[i]+ a[i]<-optim(par,fn2,
NULL,method="BFGS",c)$value+ }+ }> fn2<-function(par){+ fn2<-
-length(c)*log(par[2])+sum(log(par[2]*par[2]+(c-par[1])*(c-par[1])))+ }> >
optim(v,fn1,NULL,method="BFGS",X)Error in optim(par, fn2, NULL, method
= "BFGS", c) : L-BFGS-B needs finite values of fnIn addition:
Warning messages: 1: bounds can only be used with method L-BFGS-B in: optim(v,
fn1, NULL, method = "BFGS", X) 2: bounds can only be used with method
L-BFGS-B in: optim(par, fn2, NULL, method = "BFGS", c) 3: bounds can
only be used with method L-BFGS-B in: optim(par, fn2, NULL, method =
"BFGS", c) 4: bounds can only be used with method L-BFGS-B in:
optim(par, fn2, NULL, method = "BFGS", c) 5: bounds can only be used
with method L-BFGS-B in: optim(par, fn2, NULL, method = "BFGS", c) 6:
NaNs produced in: log(x)
#========================================================================================
So, I'd be thankful if you could help me solving this !
problem and inform me weather there is bug in the newest version or the code is
changed. Best RegardsAishaPh.D studentStatistics DeparmentUniversity of
NottinghamUK
_________________________________________________________________
Windows Live Messenger just got better .Video display pics, contact updates
& more.
http://www.download.live.com/messenger
[[alternative HTML version deleted]]
Reasonably Related Threads
- Behavior or as.environment in function arguments/call (and force() behaviors...)
- [RFC][InlineCost] Modeling JumpThreading (or similar) in inline cost model
- distinct DISubprograms hindering sharing inlined subprogram descriptions
- assign connections automatically
- R-beta: question on dyn.loaded code
