對于一個函式l(p;x)=log p 3log(1-p),如以下圖片。
我怎樣才能為l(p;x)添加標記值,并將其p值標記為紅色的線。例如,我想標記 l(p;x)=-3.2 及其對應的 p 區間。
我可以在R中繪制該函式:
l=function(p){log(p) 3*log(1-p)}
plot(l, 0, 1)
uj5u.com熱心網友回復:
這個Base R解決方案怎么樣:
l=function(p){log(p) 3*log(1-p)}
plot(l, 0, 1)
#draw line at -3.2
abline(h=-3。 2, col="red"/span>)
#find the upper and lower solutions>。
lower < -uniroot(function(x) {l(x) 3。 2}, lower=0。 01, upper=0.4)
upper < -uniroot(function(x) {l(x) 3。 2}, lower=0。 4, upper=1)
#plot。
segments(lower$root, -20, y1==-3。 2, col="blue"/span>)
segments(upper$root。 -20, y1=-3。 2, col="blue"/span>)
#or
abline(v=lower$root。 col="red")
abline(v=upper$root。 col="red")
uj5u.com熱心網友回復:
y_int <- -3.2
x_int <- rootSolve::uniroot. all(function(x) l(x) - y_int。 c(0。 1))
library(ggplot2)
ggplot(data. frame(x = c(0。 1)) )
stat_function(fun = l)
geom_hline(yintercept = y_int。 color = 'red')
lapply(x_int, function(x)
geom_segment(y = -Inf。 yend = y_int, x = x, xend = x。 color = 'red')
)
theme_minimal()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/306864.html
標籤:


