我有一个R图,我想在其中显示 IF “红色”曲线(现在位于底部情节没有正确显示)乘以常数,它可以 匹配 “蓝色”曲线目前正在展示。
我想知道我如何能够 扩展 “红色”曲线,以便 匹配 “蓝色”曲线?
(图片下方提供了我的R代码。)
这是我的R代码:
SIGMA = 2 # Population SIGMA known
observations = seq(1, 30) # observations drawn
n = length(observations) # number of observations
x_bar = mean(observations) # mean of observations
SE = SIGMA / sqrt(n) # 'S'tandard 'E'rror of the mean
x.min = x_bar - 4*SE
x.max = x_bar + 4*SE
Like = function(x) sapply(lapply(x, dnorm, x = observations, SIGMA), prod) # multiplication of densities to obtain Likelihood values
curve(dnorm(x, x_bar, SE), from = x.min, to = x.max, col = 'blue', lwd = 3, lty = 2 ) # Sampling Distribution of x_bar
curve(Like, from = x.min, to = x.max, col = 'red', lwd = 3, add = T) # Likelihood function of MU
答案 0 :(得分:1)
基本上,我们需要按比例缩放constructor(private http:Http){
this.http.get('data.json').subscribe(res => {
this.people = res.json();
});
}
ngAfterViewInit(){
this.setThis(this.people[0]);
}
的值,以使cc2$y
的缩放值与cc2$y
具有相同的范围(最小值和最大值)。我使用了cc1$y
包的rescale
函数来执行此操作
scales
如果您想在不加载库的情况下使用它,则# Sampling Distribution of x_bar
cc1 = curve(dnorm(x, x_bar, SE), from = x.min, to = x.max, col = 'blue', lwd = 3, lty = 2 )
# Likelihood function of MU
cc2 = curve(Like, from = x.min, to = x.max, col = 'red', lwd = 3, add = T)
library(scales)
scale_factor = mean(rescale(cc2$y, range(cc1$y)) / cc2$y) #APPROXIMATE
plot(cc1, type = "l")
lines(cc2$x, cc2$y * scale_factor, col = "red")
从rescale2
库中修改rescale
scales