Re: [R] Help with optim

2007-05-29 Thread Bojanowski, M.J. \(Michal\)
Hi,

Unfortunately I don't think it is possible to do exactly what you want, but:

If the numbers reported by 'optim' to the console are enough for you, then
consider using 'capture.output'. Below I used the example from 'optim' help
page, because I could not use yours directly.

hth,

Michal


# -b-e-g-i-n---R---c-o-d-e-

# this is from the 'optim' example

fr <- function(x) {   ## Rosenbrock Banana function
x1 <- x[1]
x2 <- x[2]
100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}

# and now optim-ize capturing the output to 'out' and the results to 'o'
out <- capture.output(
o <- optim( c(-1.2, 1), fr, method="BFGS",
control=c(REPORT=1, trace=1))
)

# 'out' is a character vector storing every line as a separate element
out

# 'o' is returned by optim
o

# to get a grip on the values you could use for example 'strsplit' and then
# extract neccessary info
optimout <- function(out)
{
# split by spaces
l <- strsplit(out, " ")
# just return the numbers
rval <- sapply(l[-length(l)], function(x) x[length(x)] )
as.numeric(rval)
}

x <- optimout(out)
x
plot(x)


# -e-n-d---R---c-o-d-e-


-----Wiadomo¶æ oryginalna-
Od: [EMAIL PROTECTED] w imieniu Anup Nandialath
Wys³ano: Wt 2007-05-29 08:33
Do: r-help@stat.math.ethz.ch
Temat: [R] Help with optim
 
Dear Friends,

I'm using the optim command to maximize a likelihood function. My optim command 
is as follows

estim.out <- optim(beta, loglike, X=Xmain, Y=Y, hessian=T, method="BFGS", 
control=c(fnscale=-1, trace=1, REPORT=1))

Setting the report=1, gives me the likelihood function value (if i'm correct) 
at each step. The output from running this is as follows

initial  value 3501.558347 
iter   2 value 3247.277071
iter   3 value 3180.679307
iter   4 value 3157.201356
iter   5 value 3156.579887
iter   6 value 3017.715292
iter   7 value 2993.349538
iter   8 value 2987.181782
iter   9 value 2986.672719
iter  10 value 2986.658620
iter  11 value 2986.658266
iter  12 value 2986.658219
iter  13 value 2986.658156
iter  13 value 2986.658156
iter  13 value 2986.658135
final  value 2986.658135 
converged

I just wanted to know if there was any way I could get the value of each 
iteration into an object. At present it is dumped on the screen. But is there a 
way to get hold of these values through an object??

Thanks in advance

sincerely

Anup




 
-
The fish are biting.

[[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.


[[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] Help with optim

2007-05-28 Thread Anup Nandialath
Dear Friends,

I'm using the optim command to maximize a likelihood function. My optim command 
is as follows

estim.out <- optim(beta, loglike, X=Xmain, Y=Y, hessian=T, method="BFGS", 
control=c(fnscale=-1, trace=1, REPORT=1))

Setting the report=1, gives me the likelihood function value (if i'm correct) 
at each step. The output from running this is as follows

initial  value 3501.558347 
iter   2 value 3247.277071
iter   3 value 3180.679307
iter   4 value 3157.201356
iter   5 value 3156.579887
iter   6 value 3017.715292
iter   7 value 2993.349538
iter   8 value 2987.181782
iter   9 value 2986.672719
iter  10 value 2986.658620
iter  11 value 2986.658266
iter  12 value 2986.658219
iter  13 value 2986.658156
iter  13 value 2986.658156
iter  13 value 2986.658135
final  value 2986.658135 
converged

I just wanted to know if there was any way I could get the value of each 
iteration into an object. At present it is dumped on the screen. But is there a 
way to get hold of these values through an object??

Thanks in advance

sincerely

Anup




 
-
The fish are biting.

[[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.