- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 ggplot2
中的 geom_density
在一个图中绘制多条密度曲线。我正在使用三个不同变量的数据框,每个变量有 100 个观测值。当我绘制其中两个变量时,一切似乎都正常,但对于第三个变量,我得到了密度超过 400 的意外结果。
这是数据的代码:
ad <- c(-0.0132492114254477, -0.0131566406997403, -0.0124505699056991, -0.0115071942052754, -0.0137753259532595, -0.0123873418067515, -0.013484307776411, -0.0134860926609266, -0.0126213557468908, -0.0125706300396337, -0.0130604154708213, -0.0128227278939455, -0.0115426841601749, -0.0122782889162225, -0.013070774907749, -0.0119269454694547, -0.0116610578105781, -0.0121781467814678, -0.0124721634549679, -0.012449585895859, -0.0119129861965286, -0.0127578461117945, -0.0128044526445264, -0.013716807434741, -0.0112243706437065, -0.0116435861691951, -0.0114757004236708, -0.0127175755090884, -0.0116204482711493, -0.0130377477108104, -0.0137735602022686, -0.0115581604482711, -0.012729930299303, -0.0112369577695777, -0.0109428317616508, -0.0117127921279212, -0.0115321825884927, -0.0119841820418205, -0.0130280606806068, -0.0135132485991527, -0.0115461937952712, -0.0119339866065326, -0.011019811398114, -0.0129747054803881, -0.0121079158124913, -0.0128866529998634, -0.0121608692086921, -0.0114331529315293, -0.0119070302036353, -0.0119004100041, -0.0117581221812217, -0.011107114937816, -0.0131571764384311, -0.0141545086784201, -0.0100181331146644, -0.0119012190788575, -0.0115824982916497, -0.0113907448407818, -0.0133925816591499, -0.0127234057673909, -0.0131873199398661, -0.0132453409867432, -0.010473172065054, -0.0122787289872899, -0.0118153122864562, -0.0110454803881372, -0.0126237939046056, -0.012450955309553, -0.0121033155664889, -0.0115688861555282, -0.0143594615279486, -0.0119171873718737, -0.0123140139401394, -0.0131844881782151, -0.0107496569632364, -0.0126211343446768, -0.0115844608446084, -0.0114007844745114, -0.0128332786661199, -0.0128161158944922, -0.0114647013803472, -0.011756602432691, -0.0128521142544759, -0.0108213858138581, -0.0125040645073117, -0.0124875495421622, -0.0117613284132842, -0.0127021347546809, -0.0118033675003416, -0.0119659368593686, -0.0116807571409046, -0.0125886674866749, -0.0134783763837637, -0.0127761268279349, -0.0131142927429275, -0.0119841902419024, -0.0124082930162635, -0.0117776711767118, -0.0103475632089655, -0.0117088369550362)
jv <- c(-0.0482115384615385,0.0157269230769231,-0.0738038461538462,0.0211679487179487,-0.0435153846153846,-0.123296153846154,-0.0276717948717949,0.0533141025641026,0.0181576923076923,0.0129294871794872,-0.0384320512820513,0.0192589743589744,-0.0173948717948718,-0.0714230769230769,-0.0332628205128205,-0.0706025641025641,0.0366705128205128,0.0291115384615385,-0.0759076923076923,0.00654615384615385,-0.00717435897435898,-0.0177871794871795,0.101819230769231,0.0550935897435897,0.0267064102564103,-0.0546858974358974,-0.0297051282051282,-0.00357179487179487,-0.0270423076923077,-0.0272679487179487,0.0187871794871795,-0.0283602564102564,-0.0277012820512821,-0.105816666666667,0.0205679487179487,-0.0592487179487179,0.0306692307692308,-0.0260294871794872,0.00484615384615385,0.00461666666666667,-0.00527307692307692,-0.0263,-0.0303576923076923,0.0370576923076923,-0.0291346153846154,-0.0259294871794872,-0.0230320512820513,-0.0300089743589744,-0.0328589743589744,0.000247435897435898,-0.0256371794871795,-0.00738333333333333,-0.00796410256410257,0.00740000000000001,0.0251282051282051,-0.0435948717948718,0.0045474358974359,-0.0328589743589744,-0.028224358974359,-0.0188525641025641,-0.0164871794871795,-0.0456153846153846,-0.0882666666666667,0.0340987179487179,-0.0272166666666667,0.0326153846153846,-0.0682730769230769,-0.0203346153846154,-0.0712448717948718,0.0139166666666667,-0.00764487179487179,0.0173282051282051,-0.0299807692307692,0.0117282051282051,0.0266089743589744,-0.0869025641025641,-0.0227051282051282,0.053675641025641,0.0453115384615385,-0.00631794871794872,-0.0243923076923077,0.000192307692307693,-0.0350705128205128,-0.0226307692307692,0.019925641025641,-0.0162,-0.00284615384615385,0.0322615384615385,-0.024424358974359,-0.0704871794871795,-0.00747564102564103,-0.0441782051282051,0.0897589743589744,-0.00944871794871795,0.0320948717948718,-0.00680512820512821,-0.0837705128205128,-0.0299435897435897,-0.0639474358974359,0.0137384615384615)
all <- c(-0.0307303749434931,0.0012851411885914,-0.0431272080297726,0.00483037725633668,-0.0286453552843221,-0.0678417478264527,-0.0205780513241029,0.019914004951588,0.00276816828040077,0.000179428569926724,-0.0257462333764363,0.00321812323251441,-0.0144687779775233,-0.0418506829196497,-0.0231667977102848,-0.0412647547860094,0.0125047275049673,0.00846669584003534,-0.0441899278813301,-0.0029517160248526,-0.00954367258544381,-0.015272512799487,0.0445073890623522,0.0206883911544244,0.00774101980635189,-0.0331647418025463,-0.0205904143143995,-0.00814468519044164,-0.0193313779817285,-0.0201528482143795,0.00250680964245544,-0.0199592084292638,-0.0202156061752925,-0.0585268122181222,0.00481255847814894,-0.0354807550383196,0.00956852409036905,-0.0190068346106538,-0.00409095341722648,-0.00444829096624301,-0.00840963535917408,-0.0191169933032663,-0.0206887518529032,0.0120414934136521,-0.0206212655985533,-0.0194080700896753,-0.0175964602453717,-0.0207210636452518,-0.0223830022813048,-0.00582648705333207,-0.0186976508342006,-0.00924522413557467,-0.0105606395012668,-0.00337725433921004,0.00755503600677036,-0.0277480454368647,-0.0035175311971069,-0.0221248595998781,-0.0208084703167544,-0.0157879849349775,-0.0148372497135228,-0.0294303628010639,-0.0493699193658603,0.010909994480714,-0.0195159894765614,0.0107849521136237,-0.0404484354138413,-0.0163927853470842,-0.0416740936806804,0.00117389025556923,-0.0110021666614102,0.00270550887816572,-0.0211473915854543,-0.000728141525005001,0.007929658697869,-0.0497618492236205,-0.0171447945248683,0.0211374282755648,0.0162391298977093,-0.00956703230622048,-0.0179285045363275,-0.00578214737019165,-0.0239613135374943,-0.0167260775223137,0.00371078825916465,-0.0143437747710811,-0.00730374112971901,0.00977970185342875,-0.0181138632373503,-0.041226558173274,-0.00957819908327283,-0.02838343630744,0.0381402989876053,-0.0111124223883264,0.00949028952597218,-0.00939465922351531,-0.0480894029183882,-0.0208606304601508,-0.0371474995532007,0.00101481229171268)
wang <- c(0.2383,-0.0022,-0.1754,0.0201,-0.2122,-0.2433,-0.0417,-0.087,-0.1733,-0.0926,0.0108,0.1159,0.0116,-0.0188,-0.0521,0.0927,-0.029,-0.1382,-0.1039,-0.1547,0.178,0.1101,0.008,-0.0127,0.0442,0.0036,0.0718,0.0529,-0.0873,-0.4223,-0.016,0.1449,0.1787,0.2187,0.132,0.0556,-0.1027,0.2228,-0.305,-0.1352,0.0763,0.0236,0.2504,-0.046,0.1139,-0.1191,0.0101,0.0876,-0.1283,0.0761,0.1044,-0.0583,0.0929,-0.0966,-0.0196,0.1311,0.0329,-0.2297,0.0595,-0.3032,-0.0741,0.2044,0.0406,0.0533,0.0826,0.0035,-0.0818,-0.0747,-0.218,-9e-04,0.0666,-0.0916,-0.0613,-0.2477,-0.0238,0.1959,-0.3,0.069)
# data frames
df <- data.frame(ad = ad, jv = jv, all = all)
wang <- data.frame(wang = wang)
当我使用下面的函数绘制 df$all
时,一切正常。这是我得到的图,预期密度值考虑了 100 个观测值。
ggplot() +
geom_density(aes(x = wang, colour = 'observed'), wang, size = 1) +
geom_density(aes(x = jv, colour = 'expected within'), df, size = 1) +
geom_density(aes(x = all, colour = 'expected adults'), df, size = 1) + #df$all in this line
geom_vline(aes(xintercept = mean(wang$wang),
colour = 'observed mean')) +
scale_colour_manual("", values = c('observed' = "dodgerblue2",
'expected within' = "darkgoldenrod2",
'expected adults' = 'darkolivegreen4',
'observed mean' = 'red')) +
scale_x_continuous(expand = c(0, 0), limits = c(-0.3, 0.2)) +
scale_y_continuous(expand = c(0, 0))
但是,当在第四个 geom_density
中使用 df$ad
而不是 df$all
时,我得到的密度值高得多的图比观察的数量
ggplot() +
geom_density(aes(x = wang, colour = 'observed'), wang, size = 1) +
geom_density(aes(x = jv, colour = 'expected within'), df, size = 1) +
geom_density(aes(x = ad, colour = 'expected adults'), df, size = 1) + #df$ad in this line
geom_vline(aes(xintercept = mean(wang$wang),
colour = 'observed mean')) +
scale_colour_manual("", values = c('observed' = "dodgerblue2",
'expected within' = "darkgoldenrod2",
'expected adults' = 'darkolivegreen4',
'observed mean' = 'red')) +
scale_x_continuous(expand = c(0, 0), limits = c(-0.3, 0.2)) +
scale_y_continuous(expand = c(0, 0))
我绘制了直方图以及 df$ad
的密度图(下面的代码),这就是我得到的
ggplot() +
geom_density(aes(x = ad, colour = 'density'), df) +
geom_histogram(aes(x = ad), df)
当我只有 100 个观测值时,为什么在绘制 df$ad
的密度时会得到如此高的值,如直方图所示?为什么在绘制 df$all
时不会发生这种情况?
谢谢
最佳答案
因为“geom_density”绘制了密度估计值,而“geom_hist”给出了落入不同 bin 的数据计数。 “geom_density”的 y 轴上的单位不是计数。参见 Can a probability distribution value exceeding 1 be OK?有关密度估计实际含义的更多信息。
您的 ad
变量的可变性要小得多,相对于 all
的标准差为 0.019,标准差为 0.00085。
在帮助中查看缩放到 1,?geom_density
如果您希望所有变量的密度在同一比例上:aes(x = ad, color = 'expected adults', y=..缩放..)
。无论哪种方式,“geom_density”都能正确显示您的数据,尽管您可能想探索直方图是否不是显示数据分布的更好方法。
关于r - geom_density 返回比预期更多的观测值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52388378/
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
在编码时,我问了自己这个问题: 这样更快吗: if(false) return true; else return false; 比这个? if(false) return true; return
如何在逻辑条件下进行“返回”? 在这样的情况下这会很有用 checkConfig() || return false; var iNeedThis=doSomething() || return fa
这是我的正则表达式 demo 如问题所述: 如果第一个数字是 1 则返回 1 但如果是 145 则返回 145 但如果是 133 则返回 133 样本数据a: K'8134567 K'81345678
在代码高尔夫问答部分查看谜题和答案时,我遇到了 this solution返回 1 的最长和最晦涩的方法 引用答案, int foo(void) { return! 0; } int bar(
我想在下面返回 JSON。 { "name": "jackie" } postman 给我错误。说明 Unexpected 'n' 这里是 Spring Boot 的新手。 1日龄。有没有正确的方法来
只要“is”返回 True,“==”不应该返回 True 吗? In [101]: np.NAN is np.nan is np.NaN Out[101]: True In [102]: np.NAN
我需要获取所有在 6 号或 7 号房间或根本不在任何房间的学生的详细信息。如果他们在其他房间,简单地说,我不希望有那个记录。 我的架构是: students(roll_no, name,class,.
我有一个表单,我将它发送到 php 以通过 ajax 插入到 mysql 数据库中。一切顺利,php 返回 "true" 值,但在 ajax 中它显示 false 消息。 在这里你可以查看php代码:
我在 Kotlin 中遇到了一个非常奇怪的无法解释的值比较问题,以下代码打印 假 data class Foo ( val a: Byte ) fun main() { val NUM
请注意,这并非特定于 Protractor。问题在于 Angular 2 的内置 Testability service Protractor 碰巧使用。 Protractor 调用 Testabil
在调试窗口中,以下表达式均返回 1。 Application.WorksheetFunction.CountA(Cells(4 + (i - 1) * rows_per_record, 28) & "
我在本地使用 jsonplaceholder ( http://jsonplaceholder.typicode.com/)。我正在通过 extjs rest 代理测试我的 GET 和 POST 调用
这是 Postman 为成功调用我的页面而提供的(修改后的)代码段。 var client = new RestClient("http://sub.example.com/wp-json/wp/v2
这个问题在这里已经有了答案: What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must
我想我对 C 命令行参数有点生疏。我查看了我的一些旧代码,但无论这个版本是什么,都会出现段错误。 运行方式是 ./foo -n num(其中 num 是用户在命令行中输入的数字) 但不知何故它不起作用
我已经编写了一个类来处理命名管道连接,如果我创建了一个实例,关闭它,然后尝试创建另一个实例,调用 CreateFile() 返回 INVALID_HANDLE_VALUE,并且 GetLastErro
即使 is_writable() 返回 true,我也无法写入文件。当然,该文件存在并且显然是可读的。这是代码: $file = "data"; echo file_get_contents($fil
下面代码中的变量 $response 为 NULL,尽管它应该是 SOAP 请求的值。 (潮汐列表)。当我调用 $client->__getLastResponse() 时,我从 SOAP 服务获得了
我一直在网上的不同论坛上搜索答案,但似乎没有与我的情况相符的... 我正在使用 Windows 7,VS2010。 我有一个使用定时器来调用任务栏刷新功能的应用程序。在该任务栏函数中包含对 LoadI
我是一名优秀的程序员,十分优秀!