R 高斯牛顿法

R 高斯牛顿法,r,mle,R,Mle,求非线性分布的最大似然估计(在R中,使用高斯-牛顿法): 为此,我被要求生成一些从0均匀(随机)分布的数据 y = sin(x*theta) + epsilon where epsilon ~ N(0 , 0.01^2) theta <- 2 x <- runif(200, 0, 10) x <- sort(x) #this is just to sort the generated data so that plotting it #actually looks l

求非线性分布的最大似然估计(在R中,使用高斯-牛顿法):

为此,我被要求生成一些从0均匀(随机)分布的数据
y = sin(x*theta) + epsilon
where epsilon ~ N(0 , 0.01^2)
theta <- 2

x <- runif(200, 0, 10)

x <- sort(x)  #this is just to sort the generated data so that plotting it
 #actually looks like a sine funciton

y <- sin(x*theta) + rnorm(200, mean = 0, sd = 0.1^2)

GN_sin <- function(theta.iter, x , y, epsilon){

 index <- TRUE

 while (index){

     y.iter <- matrix(y - sin(x*theta.iter), 200, 1)

     x.iter <- matrix(theta.iter*cos(x*theta.iter), 200, 1)

     theta.new <- theta.iter +

         solve(t(x.iter)%*%x.iter)%*%t(x.iter)%*%y.iter

         if (abs(theta.new-theta.iter) < epsilon) {index <- FALSE}

   theta.iter <- as.vector(theta.new)

 cat(theta.iter, '\n')

 }
}