R 中的损失函数

Function of loss in R

我通过以下公式为 k 元素向量给出了损失函数:

其中p为正参数。我必须在 R 中编写一个函数,其中 returns u 的值最小化了该函数。我该怎么做?

首先定义要最小化的函数:

my_function <- function(u) {
    ...
}

然后可以调用optim()函数:

result <- optim(starting_point_for_u, my_function, ...)
# parameter value minimizing the function
result$par
# minimal value of function
result$value