# Optim result highly dependent on starting value

I want to fit a standardized Student's-t distribution. The log-likelihood is given by:

\begin{align*} log \mathcal{L}(\nu | l_1,...,l_n)=\sum_{i=1}^n \left( log \left( (\pi (\nu-2))^{-\frac{1}{2}}\Gamma \left(\frac{\nu}{2} \right)^{-1} \Gamma \left(\frac{\nu+1}{2} \right) \left(1+\frac{l^2}{\nu-2} \right)^{\text{$-\frac{1+\nu}{2}$}}\right)\right) \end{align*}

I try do to this with the optim command. My R code is (data):

# log likelihood
pinumber<-3.141592653589793
startvalue<-55

loglikstandardizedt <-function(par){
if(par>0) return(-sum(log((pinumber*(par-2))^(-1/2)*gamma(par/2)^(-1)*gamma((par+1)/2)*(1+standresidalvewma^2/(par-2))^(-(1+par)/2))))
else return(Inf)
}

optim(startvalue,loglikstandardizedt, method="BFGS")
param = optim(startvalue,loglikstandardizedt, method="BFGS")$par  I can control it via looking at the plot:  denstiystandtresid<-function (x) (pinumber*(param-2))^(-1/2)*gamma(param/2)^(-1)*gamma((param+1)/2)*(1+x^2/(param-2))^(-(1+param)/2) plot(density(standresidalvewma),ylim=c(0,0.8)) curve(denstiystandtresid,col="red",add=TRUE)  I have the problem, that the output of optim, that means the value for "par" is highly dependend on the starting value. What is the right starting value? And what is the best value for my$\nu\$?

The variation is very large, I get values from 27 up to 215, so this is a huge difference?

In general, when using optim for one dimensional problem, you should set the method argument to Brent otherwise optim is indeed unreliable.
• pinumber you can use pi instead (it's a reserved constant in R)
• par is a reserved keyword in R so it's better to use another name.
• loglikstandardizedt assumes a vector standresidalvewma which is not declared in the call to loglikstandardizedt
• To the OPs defense, stats::optim even uses par as a named argument and so do other optimization functions in R like those in the optimx package. Though I agree that it would be nice to avoid. – Benjamin Christoffersen Nov 3 '18 at 11:05
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8566781878471375, "perplexity": 4270.397946160433}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-10/segments/1581875143805.13/warc/CC-MAIN-20200218180919-20200218210919-00172.warc.gz"}