[R] Help fix last line of my optimization code

2011-07-01 Thread Edward Bowora
Hi

I need help figure out how to fix my code.

When I call into R
optimize(llik,init.params=F)
 I get this error message
Error in optimize(llik, init.params = F) : element 1 is empty;
   the part of the args list of 'min' being evaluated was:
   (interval)


My data and my code looks like below.


R_j R_m
0.002   0.026567296
0.010.003194435
.   .
.   .
.   .
.   .
0.0006  0.010281122

a=read.table(D:/ff.txt,header=T)
attach(a)
llik=function(R_j,R_m)
#The parameters al_j, au_j, b_j ,
and sigma_j need to be estimated and there are no initial estimates to
them.
if(R_j 0)
{
 LF=sum[log(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+al_j-b_j*R_m))^2]
}else if(R_j0)
{
 LF=sum[log(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+au_j-b_j*R_m))^2]
}else
{
 LF=sum[(log(pnorm((au_j-b_j*R_m)/sigma_j)-pnorm((al_j-b_j*R_m)/sigma_j)))]
}
optimize(llik,init.params=F)
Error in optimize(llik, init.params = F) : element 1 is empty;
   the part of the args list of 'min' being evaluated was:
   (interval)

Thank you

Edward

__
R-help@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.


[R] help optimize

2011-07-01 Thread Edward Bowora
Hi

I need help figure out how to fix my code.

When I call into R
optimize(llik,init.params=F)
 I get this error message
Error in optimize(llik, init.params = F) : element 1 is empty;
  the part of the args list of 'min' being evaluated was:
  (interval)


My data and my code looks like below.


R_j R_m
0.002   0.026567296
0.010.003194435
.   .
.   .
.   .
.   .
0.0006  0.010281122

a=read.table(D:/ff.txt,header=T)
attach(a)
llik=function(R_j,R_m)
#The parameters al_j, au_j, b_j ,
and sigma_j need to be estimated and there are no initial estimates to
them.
if(R_j 0)
{
 LF=sum[log(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+al_j-b_j*R_m))^2]
}else if(R_j0)
{
 LF=sum[log(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+au_j-b_j*R_m))^2]
}else
{
 LF=sum[(log(pnorm((au_j-b_j*R_m)/sigma_j)-pnorm((al_j-b_j*R_m)/sigma_j)))]
}
optimize(llik,init.params=F)
Error in optimize(llik, init.params = F) : element 1 is empty;
  the part of the args list of 'min' being evaluated was:
  (interval)

Thank you

Edward

__
R-help@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.


[R] maximum likelihood using nlm to estimate 4 variables

2011-06-27 Thread Edward Bowora
Hi I need help

I am new to R and am having problems estimating parameters out of
3stage constrained function.

I have constructed a code as below and my data are two colomns of R_j
and R_m(sample given below). R_j and R_m represents the dependent and
independent variables respectively. The parameters al_j, au_j, b_j ,
and sigma_j need to be estimate and there are no initial estimates to
them


llik=function(R_j,R_m)
{

LF=if(R_j 
0)sum[ln(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+al_j-b_j*R_m))^2]
+
if(R_j 0)sum[ln(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+au_j-b_j*R_m))^2]
+

if(R_j==0)sum[(ln(%pnorm((au_j-b_j*R_m)/sigma_j)-%pnorm((al_j-b_j*R_m)/sigma_j)))]
}
est.nlm = nlm(llik,0) #not sure what to put for the 4 initial
estimates so I just put 0
est.nlm$estimate

Sample Data
R_j R_m
0.002   0.026567295
0.003   0.009798475
0.050.008497274
-0.01   0.012464578
-0.0009 0.002896023
0.090.000879473
0.010.003194435
0.0006  0.010281122

I will appreciate if you help me to modify my code to get my estimates
or give me any better method to use.

Thank you in advance

Edward
Student: Institute of Actuaries

__
R-help@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.


[R] maximizing the LDV model

2011-06-23 Thread Edward Bowora
Hi

Please find attached document to see my problem that I wish you would assist
me to solve.

I want to maximise the LDV model to get alpha estimates.

I am looking forward to hearing from you soon.

Edward
Actuarial Science student
__
R-help@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.