r - Least square minimization -


i hope right place such basic question. found this , this solutions quite articulated, hence not me fundamentals of procedure.
consider random dataset:

x <- c(1.38, -0.24, 1.72, 2.25) w <- c(3, 2, 4, 2) 

how can find value of μ minimizes least squares equation enter image description here :

the package manipulate allows manually change bar model different values of μ, looking more precise procedure "try manually until not find best fit".

note: if question not correctly posted, welcome constructive critics.

you proceed follows:

optim(mean(x), function(mu) sum(w * (x - mu)^2), method = "bfgs")$par # [1] 1.367273 

here mean(x) initial guess mu.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -