Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6097683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:04:18+00:00 2026-05-23T13:04:18+00:00

I am trying to optimise my likelihood function of R_j and R_m using optim

  • 0

I am trying to optimise my likelihood function of R_j and R_m using optim to estimate al_j, au_j, b_j and sigma_j. This is what I did.

a = read.table("D:/ff.txt",header=T)
attach(a)   
a

  R_j         R_m
1  2e-03 0.026567295
2  3e-03 0.009798475
3  5e-02 0.008497274
4 -1e-02 0.012464578
5 -9e-04 0.002896023
6  9e-02 0.000879473
7  1e-02 0.003194435
8  6e-04 0.010281122

The parameters al_j, au_j, b_j and sigma_j need to be estimated.

llik=function(R_j,R_m)
 if(R_j< 0)
 {
 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_j>0)
 {
 sum[log(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+au_j-b_j*R_m))^2]
 }else if(R_j==0)
 {
 sum(log(pnorm(au_j,mean=b_j*R_m,sd=sigma_j)-pnorm(al_j,mean=b_j*R_m,sd=sigma_j)))
 }

start.par=c(al_j=0,au_j=0,sigma_j=0.01,b_j=1) 
out1=optim(llik,par=start.par,method="Nelder-Mead")

Error in pnorm(au_j, mean = b_j * R_m, sd = sigma_j) : 
  object 'au_j' not found
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:04:19+00:00Added an answer on May 23, 2026 at 1:04 pm

    It is difficult to tell where to start on this.

    As @mac said, your code is difficult to read. It also contains errors.

    For example, if you try sum[c(1,2)] you will get an error: you should use sum(c(1,2)). In any case, you seem to be taking the sum in the wrong place. You cannot use if and else if on vectors, and need to use ifelse. You have nothing to stop the standard deviation going negative. There is more.

    The following code runs without errors or warnings. You will still have to decide whether it does what you want.

    a <- data.frame( R_j = c(0.002,0.003,0.05,-0.01,-0.0009,0.09,0.01,0.0006),
                     R_m = c(0.026567295,0.009798475,0.008497274,0.012464578,
                             0.002896023,0.000879473,0.003194435,0.010281122) )
    
    llik = function(x) 
       { 
        al_j=x[1]; au_j=x[2]; sigma_j=x[3];  b_j=x[4]
        sum(
            ifelse(a$R_j< 0, log(1/(2*pi*(sigma_j^2)))-
                               (1/(2*(sigma_j^2))*(a$R_j+al_j-b_j*a$R_m))^2, 
             ifelse(a$R_j>0 , log(1/(2*pi*(sigma_j^2)))-
                               (1/(2*(sigma_j^2))*(a$R_j+au_j-b_j*a$R_m))^2,
                              log(pnorm(au_j,mean=b_j*a$R_m,sd=sqrt(sigma_j^2))-
                               pnorm(au_j,mean=b_j*a$R_m,sd=sqrt(sigma_j^2))))) 
           )
       } 
    
    start.par = c(0, 0, 0.01, 1) 
    out1 = optim(llik, par=start.par, method="Nelder-Mead") 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking at trying to optimise a particular function in a PHP application and
Recently, I was trying to optimise this query UPDATE Analytics SET UserID = x.UserID
I'm trying to optimize query performance and have had to resort to using optimizer
I am trying to optimize a small, highly used function which uses the high
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I'm trying to optimise the performance of a string comparison operation on each string
I'm trying to optimize the following. The code bellow does this : If a
I am trying to optimize this sort of things in a heavy computing application:
I am trying to avoid using a scalar valued functions in my project, so
When trying to optimize transactions on my java ee 6 project using hibernate, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.