簡體   English   中英

如何在R中繪制涉及求和和對數的函數

[英]How to plot a function involving summation and logs in R

如何在R中繪制以下功能

$ l(\\ theta)= ln(\\ theta)* \\ sum {y_i} -n * \\ theta -n * ln(1-e ^ {-\\ theta})-\\ sum {ln(y_i!)} $

總和從$ i = 1 $到$ n $

我有數據集,但我知道如何輸入。

像這樣:

L <- function(theta, y){ 
         log(theta)*sum(y) - 
         length(y) *(theta + log(1 - exp(-theta))) - 
         sum(lfactorial(y))
         }
L_theta <- function(theta){
         L(theta, y)
         }
#example
y <- c(1, 3, 5, 7)
L(2, y)
# [1] -11.4324
plot(L_theta, xlim=c(0, 2), xlab="θ" )

產生類似

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM