How do I write something like "pause()" in R code like in other programming languages so I can just press something to let the program continue? -- View this message in context: http://r.789695.n4.nabble.com/pause-code-in-R-code-tp4523209p4523209.html Sent from the R help mailing list archive at Nabble.com.
?readline On Sun, Apr 1, 2012 at 7:33 AM, Hurr <hill0093 at umn.edu> wrote:> How do I write something like "pause()" in R code like > in other programming languages so I can just press > something to let the program continue? > > > -- > View this message in context: http://r.789695.n4.nabble.com/pause-code-in-R-code-tp4523209p4523209.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
Sorry, I cannot find your answer in your reply. -- View this message in context: http://r.789695.n4.nabble.com/pause-code-in-R-code-tp4523209p4523348.html Sent from the R help mailing list archive at Nabble.com.
He only wrote one word... it could be that one. For example,
plot(1:5)
readline("Press <return to continue")
plot(1:10, col = 2)
Michael
On Sun, Apr 1, 2012 at 9:10 AM, Hurr <hill0093 at umn.edu>
wrote:> Sorry, I cannot find your answer in your reply.
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/pause-code-in-R-code-tp4523209p4523348.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.
On 01-04-2012, at 15:10, Hurr wrote:> Sorry, I cannot find your answer in your reply. >Answer was given at the top of the message and was ?readline. Read the help of readline. Berend
Marc Girondot
2012-Apr-01 14:27 UTC
[R] Need for optim() resistant to error on the fit criteria.
Hi,
I try to fit parameters based on the comparison between a stochastic
model that uses these parameters and observed data.
The problem is that two runs with the same set of parameters will
produce a fitting criteria slightly different.
I found that optim() is highly sensitive to such a situation and
produces completly wrong result.
I reproduce this situation below.
v is a set of 50 "observed" values
par is the set of parameters to be fitted
fitNorm returns the -Ln L of the observations based on a Gaussian
distribution
fitNorm_error returns the -Ln L of the observations based on a Gaussian
distribution + a small error
Example of optim() result:
with fitNorm
final value 215.918650
converged
$par
[1] 156.27980 18.16392 (compared to 157.5, 18.5)
with fitNorm_error
final value 271.661187
converged
$par
[1] 169.98441 88.81387 (compared to 157.5, 18.5)
So the question: is there another solution for a fitting procedure that
is more resistant to change in fit criteria ?
Thanks a lot,
Marc
#The likelihood function that returns -Ln L of the data
fitNorm<-function(para) {
return(-sum(dnorm(v, para[1], para[2], log=TRUE)))
}
#The likelihood function that returns -Ln L of the data with a slight error
fitNorm_error<-function(para) {
return(-sum(dnorm(v, para[1], para[2], log=TRUE))+rnorm(1, 0, 0.1))
}
#Generate 50 random number from a Gaussian distribution
v<-rnorm(50, 157.5, 18.5)
par<-c(100, 10)
optim(par, fitNorm, method="BFGS", hessian=FALSE,
control=list(maxit=500, trace=1))
optim(par, fitNorm_error, method="BFGS", hessian=FALSE,
control=list(maxit=500, trace=1))
--
__________________________________________________________
Marc Girondot, Pr
Laboratoire Ecologie, Syst?matique et Evolution
Equipe de Conservation des Populations et des Communaut?s
CNRS, AgroParisTech et Universit? Paris-Sud 11 , UMR 8079
B?timent 362
91405 Orsay Cedex, France
Tel: 33 1 (0)1.69.15.72.30 Fax: 33 1 (0)1.69.15.73.53
e-mail: marc.girondot at u-psud.fr
Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
Skype: girondot
This must be a misdirected reply. Personal or system error? -- View this message in context: http://r.789695.n4.nabble.com/pause-code-in-R-code-tp4523209p4523523.html Sent from the R help mailing list archive at Nabble.com.
Are you sure you are executing that line of code....? Michael On Sat, Apr 7, 2012 at 9:18 AM, Hurr <hill0093 at umn.edu> wrote:> readline("press return to continue") > worked as a pause until I used it in 4 places in a different program where > none of them wait. > What problem do I look for? > > > -- > View this message in context: http://r.789695.n4.nabble.com/pause-code-in-R-code-tp4523209p4539399.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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.
On Sat, Apr 7, 2012 at 6:18 AM, Hurr <hill0093 at umn.edu> wrote:> readline("press return to continue") > worked as a pause until I used it in 4 places in a different program where > none of them wait. > What problem do I look for?Your bad coding. cf the posting guide -- especially "reproducible examples" -- to post a coherent question that can be answered. -- Bert> > > -- > View this message in context: http://r.789695.n4.nabble.com/pause-code-in-R-code-tp4523209p4539399.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm