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

  • Home
  • SEARCH
  • 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 8198431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:56:59+00:00 2026-06-07T05:56:59+00:00

I want to run some maximum likelihood code on the data sample I have

  • 0

I want to run some maximum likelihood code on the data sample I have created. This is what I have so far:

library("maxLik") 
data <- replicate(20, rnorm(100))
logLikFun <- function(param) {
mu <- param[1]
sigma <- param[2]
sum(dnorm(data, mean = mu, sd = sigma, log = TRUE))
}
mle <- maxLik(logLik = logLikFun, start = c(mu = 0, sigma = 1))
summary(mle)

I am having some problems extracting the mean and standard deviation for each sample of the 20, I amended the apply function to try to suit this but nothing has worked yet. Any ideas?

  • 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-06-07T05:57:00+00:00Added an answer on June 7, 2026 at 5:57 am

    Create a function (find.mle in this example) that takes a vector of data and calculates the MLE based on it, and then use apply to apply that to the columns of data:

    library("maxLik") 
    data <- replicate(20, rnorm(100))
    
    find.mle = function(d) {
        logLikFun <- function(param) {
            mu <- param[1]
            sigma <- param[2]
            sum(dnorm(d, mean = mu, sd = sigma, log = TRUE))
        }
        maxLik(logLik = logLikFun, start = c(mu = 0, sigma = 1))$estimate
    }
    
    mles = apply(data, 2, find.mle)
    

    This will give you a 2×20 matrix with your estimates:

    > mles
                [,1]      [,2]        [,3]       [,4]       [,5]        [,6]
    mu    0.03675611 0.1129927 -0.06499549 0.04651673 0.06593217 -0.08753828
    sigma 0.93497523 0.9817961  0.84734600 0.93139761 1.01083924  1.04114752
               [,7]       [,8]      [,9]       [,10]      [,11]       [,12]
    mu    0.1629807 0.01665411 0.2306688 -0.02147982 0.07723695 0.009476477
    sigma 1.0428713 1.01658241 1.0073277  0.99781761 0.99327722 0.983356049
               [,13]      [,14]      [,15]      [,16]     [,17]     [,18]
    mu    0.06524147 0.02442983 -0.1305258 -0.1050299 0.1449996 0.1172218
    sigma 1.04004799 0.89963009  0.9979824  1.0227063 0.9319562 0.9916734
               [,19]       [,20]
    mu    -0.1288296 -0.05769467
    sigma  0.9975368  0.89506586
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one ruby script that I want to run with some flags
I want to run some Python unit tests from my Maven module. I have
I have a web application that I want to run some system tests on,
I want my C# WinForms app to run some code when either the app
I want to run some code after the eclipse goal of the eclipse plugin
I want to run some code on startup to pre-cache some stuff, and would
I want to run some of my apps code every night in some sort
I want to run some code that makes use of User.Identity.Name, I want to
I have a sprite and i want run some animations, but over the sprite
I want to run some JS code when an image's CSS property display has

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.