- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用离散广义贝塔分布(DGBD)来拟合频率数据。
数据如下:
freq = c(1116, 2067, 137 , 124, 643, 2042, 55 ,47186, 7504, 1488, 211, 1608,
3517 , 7 , 896 , 378, 17 ,3098, 164977 , 601 , 196, 637, 149 , 44,2 , 1801, 882 , 636,5184, 1851, 776 , 343 , 851, 33 ,4011, 209, 715 ,
937 , 20, 6922, 2028 , 23, 3045 , 16 , 334, 31 , 2)
Rank = rank(-freq, ties.method = c("first") )
p = freq/sum(freq)
log.f = log(freq)
log.p = log(p)
log.rank = log(Rank)
log.inverse.rank = log(length(Rank)+1-Rank)
co=coef(lm(log.p~log.inverse.rank + log.rank))
zmf = function(x) exp(co[[1]]+ co[[2]]*log(length(x)+1-x) + co[[3]]*log(x))
plot(p~Rank, xlim = c(1, 80), log = "xy",xlab = "Rank (log)", ylab = "Probability (log)")
curve(zmf, col="blue", add = T)
xx=c(1:length(Rank))
lines(zmf(xx)~xx, col = "red")
points(zmf(xx)~xx, col = "purple")
虽然我还没有弄清楚底层逻辑,但是找到了解决方案:
@Frank 提醒我注意在曲线中设置 n 长度的技巧。它解决了问题。因此,当我们尝试拟合原始数据时,曲线中的 n 是必要的。尽管在很多情况下,n 会被忽略。
plot(p~Rank, log = "xy",xlab = "Rank (log)", ylab = "Probability (log)")
curve(zmf, col="blue", add = T, n = length(Rank)) # set the the number of x values at which to evaluate.
最佳答案
您需要在此处指定n
的原因是您的函数依赖于length(x)
!
zmf = function(x) exp(co[[1]]+ co[[2]]*log(length(x)+1-x) + co[[3]]*log(x))
^^^^^^^^^
这里,curve
提供给函数的 x
的长度是 n
!
如果您坚持使用默认的 n=101
但使用向量 xx 提供您的
:line
和 point
,那么这就是您的绘图长度为 101 的
plot(p~Rank, xlim = c(1,80), log = "xy",xlab = "Rank (log)", ylab = "Probability (log)")
curve(zmf, col="blue", add = T)
xx=seq(1,length(Rank),length.out=101)
lines(zmf(xx)~xx, col = "red")
points(zmf(xx)~xx, col = "purple")
既不是巫术也不是 bug ! :)
关于r - 为什么 'curve' 与 R 中的 'lines' 和 'points' 如此不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22446006/
当我用 g++ 编译时出现以下错误: Parser.cpp:(.text+0x2478): 未定义对“Curve::Curve()”的引用 Parser.cpp 的标题如下: #include "Be
问题 假设我知道希尔伯特曲线面和四叉树,例如 4/032212303102122 (第 4 面,第 15 层)。 或者我可能知道 S2 Geometry CellId,例如 9749618424903
我正在尝试将文本包裹在贝塞尔曲线中,并遵循此链接中的教程,http://www.planetclegg.com/projects/WarpingTextToSplines.html 我通过此代码获得衍
如果我有一组来 self 扫描的黑白图像的点。 它看起来像一条曲线,我想使用这些点的三次贝塞尔曲线来模拟一条平滑的曲线。 如何确定起点、2 个控制点和终点? 从图像中可以模拟出几条三次贝塞尔曲线,但我
我想将具有已知端点(p0 和 p3)的贝塞尔曲线拟合到嘈杂的二维数据。这似乎比传统的 4 点贝塞尔曲线拟合更简单,但我仍然难以弄清楚。 有人可以指出我现有的代码或算法来找到控制点 p1 和 p2 的最
我正在尝试使用 B 样条曲线拟合。 B样条曲线的阶数为4。当我有很多控制点时,它工作得很好。但是,如果控制点的数量很少,比如两个,我的程序就会崩溃。我意识到控制点的数量与结的数量和顺序有关。谁能帮我澄
我有三个形成抛物线的 X/Y 点。我只需要计算通过这三个点的抛物线顶点是多少。最好是一种快速的方法,因为我必须做很多这些计算! “Ask A Scientist”网站提供this answer : T
我想绘制 x 的函数,其中 x 应用于向量。无论如何,最简单的是举一个简单的例子: var <- c(1,2,3) curve(mean(var)+x) curve(mean(var+x)) 虽然第一
一位同事问我这个问题,我一直在努力解决这个问题。 假设我想定义一个函数,它接受一个表达式(具体来说,假设为 x^2)作为参数,并将该参数传递给 curve()。 如果我想以简单的方式做到这一点,我只需
我想绘制 x 的函数,其中 x 应用于向量。无论如何,最简单的是举一个简单的例子: var <- c(1,2,3) curve(mean(var)+x) curve(mean(var+x)) 虽然第一
ECDSA算法中256位EC key 的签名长度将是多少? 我想验证签名长度是否相同。如果某个机构可以帮助我设置一个EC key ,那将是很棒的。 最佳答案 这取决于您如何对签名进行编码。这是来自Op
我有以下代码生成四个图,但它们最终被压扁(见下图)。我该如何解决这个问题? par(mfrow=c(2,2)) curve(.5*exp(-.5*x),from=0,to=10,main="f(x)"
我编写了一个程序,它处理当前资源到几何图形表面的欧氏距离。在我们的几何考虑中,y 坐标始终为零 - 因此它在 x 和 z 维度上是一个二维结构。该图显示了它的外观: (length yellow =
为什么curve似乎不适用于从列表中提取的元素? 考虑两个看似相同的函数,但构建方式不同: a curve(m[[1]]) Error in curve(m[[1]]) : 'expr' mus
我有一个公式作为字符向量,并希望在曲线中使用它。 curve(-8*cos(2*x), 0, 10) #works as expected formula <- "-8*cos(2*x)" # not
为什么curve似乎不适用于从列表中提取的元素? 考虑两个看似相同的函数,但构建方式不同: a curve(m[[1]]) Error in curve(m[[1]]) : 'expr' mus
是否可以循环动画此图像? 我试图通过创建一个相对父级并将每个图像设置为动画(业务解决方案 div、it 解决方案 div、生命周期解决方案 div 和教育解决方案 div 为绝对)。我使用了这段代码,
如何在Flex中弯曲我的文本小部件?我有一个被文本包围的圆圈,我需要为文本创建这个样式。另外,这个圆圈占屏幕宽度的50%,所以这个曲线效果也应该是动态的
我怎样才能弯曲一张纸(立方体)?我想控制弯曲/曲线的角度。 例如 立方体([50,50,2]); 最佳答案 您可以 rotate_extrude()一个带有参数角的矩形。这需要 openscad 版本
我正在尝试寻找一种聪明的方法来创建像下一个一样的曲线(使用 Unity3d 2D 部分(不使用网格对撞机))),但我没有找到 任何帮助,将不胜感激。 最佳答案 看到最后一个答案(已删除)不符合我的要求
我是一名优秀的程序员,十分优秀!