本文介绍了交点 2 条正态曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我认为这是一个基本问题,但我似乎无法找到如何在 R 中计算:

Although I think this is a basic question, I can't seem to find out how to calculate this in R:

2 个或多个正态分布(拟合在直方图上)的交点(我需要 x 值),例如具有以下参数:

the point of intersection (I need the x-value) of 2 or more normal distributions (fitted on a histogram) which have for example the following parameters:

d=data.frame(mod=c(1,2),mean=c(14,16),sd=c(0.9,0.6),prop=c(0.6,0.4))

用我的 2 条曲线的均值和标准差,并支撑每个 mod 对分布的贡献比例.

With the mean and standard deviation of my 2 curves, and prop the proportions of contribution of each mod to the distribution.

推荐答案

你可以使用uniroot:

f <- function(x) dnorm(x, m=14, sd=0.9) * .6 - dnorm(x, m=16, sd=0.6) * .4

uniroot(f, interval=c(12, 16))

$root
[1] 15.19999

$f.root
[1] 2.557858e-06

$iter
[1] 5

$estim.prec
[1] 6.103516e-05

ETA 一些说明:


ETA some exposition:

uniroot 是一个单变量根查找器,即给定一个变量 x 的函数 f,它找到 x 的值 求解方程 f(x) = 0.

uniroot is a univariate root finder, ie given a function f of one variable x, it finds the value of x that solves the equation f(x) = 0.

要使用它,您需要提供函数 f,以及假定解值所在的区间.在这种情况下,f 只是两个密度的差值;它们相交的点将是 f 为零的地方.在这个例子中,我通过绘制一个图并看到它们在 x=15 附近相交,得到了区间 (12, 16).

To use it, you supply the function f, along with an interval within which the solution value is assumed to lie. In this case, f is just the difference between the two densities; the point where they intersect will be where f is zero. I got the interval (12, 16) in this example by making a plot and seeing that they intersected around x=15.

这篇关于交点 2 条正态曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:05