library(nlme)
fm1 <- nlme(height ~ SSasymp(age, Asym, R0, lrc),
data = Loblolly,
fixed = Asym + R0 + lrc ~ 1,
random = Asym ~ 1,
start = c(Asym = 103, R0 = -8.5, lrc = -3.3), verbose = TRUE)
# **Iteration 1
# LME step: Loglik: -114.787, nlminb iterations: 1
# reStruct parameters:
# Seed
# -1.669062
# PNLS step: RSS = 43.40812
# fixed effects: 101.4496 -8.627331 -3.233751
# iterations: 4
# Convergence crit. (must all become <= tolerance = 1e-05):
# fixed reStruct
# 0.02048682 0.02712258
#
# **Iteration 2
# LME step: Loglik: -114.7428, nlminb iterations: 1
# reStruct parameters:
# Seed
# -1.624988
# PNLS step: RSS = 43.40812
# fixed effects: 101.4496 -8.627331 -3.233751
# iterations: 1
# Convergence crit. (must all become <= tolerance = 1e-05):
# fixed reStruct
# 0 0
In particular, I am referring to the nlme
function call, but I think the solution will be generalizable to other verbose = TRUE
generated outputs. Essentially, I would like to store the verbose text (starting from **Iteration 1). Is there any way to do this in R?
Edit: Gregor de Cilla's answer works great for the above example (where algorithm converged). What if the algorithm didn't converge?
u2 = evaluate({
fm2 <- nlme(height ~ SSasymp(age, Asym, R0, lrc),
data = Loblolly,
fixed = Asym + R0 + lrc ~ 1,
random = Asym ~ 1,
start = c(Asym = 103, R0 = -10, lrc = -8), verbose = TRUE)
})
> cat(u2[[2]])
# Error in cat(u2[[2]]) : object 'u2' not found