will help quicken the maximisation.
simple way would instead of saving your starting parameters in
start.par, add an extra row at the front of "out" to hold them. Then
inside your loop, use something like:
for(i in 2:5)
out[i, ] <- optimx(llik, par = out[i -1, ]
so that the pr
values of
the next loop because I did not know I could do that but I think it
will help quicken the maximisation.
Edward
UCT
On 7 July 2011 13:40, John C Nash [via R]
wrote:
> 2 comments below.
>
> On 07/07/2011 06:00 AM, [hidden email] wrote:
>> Date: Wed, 6 Jul 2011 20:39:19 -0700
2 comments below.
On 07/07/2011 06:00 AM, r-help-requ...@r-project.org wrote:
> Date: Wed, 6 Jul 2011 20:39:19 -0700 (PDT)
> From: EdBo
> To: r-help@r-project.org
> Subject: Re: [R] loop in optim
> Message-ID: <1310009959045-3650592.p...@n4.nabble.com>
> Content-Type
I don't know what else to say. Your code looks right to me, and it
all runs. I would check the value of a at each loop:
for (i in 1:4) {
a <- afull[seq(20 * (i - 1) +1, 20 * i), ]
print(a) # so you can see what it is
out[i, ] <- optim(llik, par = start.par, method = "Nelder-Mead")[[1]]
}
I have one last theoretical question, I did not adjust my code prior so that
it maximise the likehood function. I googled that to make optim maximise you
multiply fn by -1.
In my code, would that be the same as saying "-sum" on the "sum" part of my
code (see below)?
llik = function(x)
{
I am sorry if I sound stupid but I am not able to correct the error
even after running this code.
> afull=read.table("D:/hope.txt",header=T)
> llik = function(x)
+ {
+al_j=x[1]; au_j=x[2]; sigma_j=x[3]; b_j=x[4]
+sum(na.rm=T,
+ifelse(a$R_j< 0, log(1/(2*pi*(sigma_j^2)))-
+
EdBo wrote:
>
> You are right Joshua.
>
> I changed the code because I failed to understand how you attached the
> full data set. How you made the data part of your code.
>
> I am new to R so I am used to one way of attaching data(the way I redone
> it).
>
You don't need to "attach" the data
You are right Joshua.
I changed the code because I failed to understand how you attached the full
data set. How you made the data part of your code.
I am new to R so I am used to one way of attaching data(the way I redone it).
-Original Message-
From: "Joshua Wiley-2 [via R]"
Date: Tue
On Tue, Jul 5, 2011 at 7:07 PM, EdBo wrote:
> Hi Josh
>
> I have run the code and the structure of the output is what I wanted.
> However, the code is giving an identical result for all runs.
Right because the object "a" stays the same for all runs.
>
> I have attached the code I ran below as we
Hi Josh
I have run the code and the structure of the output is what I wanted.
However, the code is giving an identical result for all runs.
I have attached the code I ran below as well as the output. I have just
changed number of runs to match with the size of the data.
a=read.table("D:/hope.txt
Do you want something like this?
## Your data
afull <- read.table(textConnection("
R_j R_m
-0.0625 0.002320654
0 -0.004642807
0.0 0.005936332
0.032258065 0.001060848
0 0.007114057
0.0156250.005581558
0 0.00297479
Hi
I have re-worked on my likelihood function and it is now working(#the code
is below#).
May you help me correct my loop function.
I want optim to estimates al_j; au_j; sigma_j; b_j by looking at 0 to 20,
21 to 40, 41 to 60 data points.
The final result should have 4 columns of each of th
Hi Edward,
At least for me, your llik() function returns Inf for the starting
values specified, so optim() never gets to estimate anything. You
need to alter llik() or find starting parameters that work before
worrying about getting the for loop working.
Cheers,
Josh
On Mon, Jul 4, 2011 at 2:3
Hi
May you help me correct my loop function.
I want optim to estimates al_j; au_j; sigma_j; b_j by looking at 0 to 20,
21 to 40, 41 to 60 data points.
The final result should have 4 columns of each of the estimates AND 4 rows
of each of 0 to 20, 21 to 40, 41 to 60.
###MY code is
n=20
runs=4
o
14 matches
Mail list logo