作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用ggplot2绘制以下数据集,它是三个实验A1,B1和C1的时间序列,每个实验都有三个重复项。
我正在尝试添加一个统计信息,该统计信息可在返回更平滑的值(均值和方差?)之前检测并删除离群值。我已经编写了自己的离群值函数(未显示),但是我希望已经有一个函数可以执行此操作,但我还没有找到它。
我已经从ggplot2书中的一些示例中查看了stat_sum_df(“median_hilow”,geom =“smooth”),但我不了解Hmisc的帮助文档是否可以消除异常值。
有没有在ggplot中删除此类异常值的函数,或者我将在下面的代码中修改以添加自己的函数吗?
编辑:我刚刚看到了这个(How to use Outlier Tests in R Code),并注意到Hadley建议使用诸如rlm之类的可靠方法。我正在绘制细菌生长曲线,所以我认为线性模型不是最好的,但是在这种情况下对其他模型或使用或使用健壮模型的任何建议都将不胜感激。
library (ggplot2)
data = data.frame (day = c(1,3,5,7,1,3,5,7,1,3,5,7,1,3,5,7,1,3,5,7,1,3,5,7,1,3,5,7,1,3,5,7,1,3,5,7), od =
c(
0.1,1.0,0.5,0.7
,0.13,0.33,0.54,0.76
,0.1,0.35,0.54,0.73
,1.3,1.5,1.75,1.7
,1.3,1.3,1.0,1.6
,1.7,1.6,1.75,1.7
,2.1,2.3,2.5,2.7
,2.5,2.6,2.6,2.8
,2.3,2.5,2.8,3.8),
series_id = c(
"A1", "A1", "A1","A1",
"A1", "A1", "A1","A1",
"A1", "A1", "A1","A1",
"B1", "B1","B1", "B1",
"B1", "B1","B1", "B1",
"B1", "B1","B1", "B1",
"C1","C1", "C1", "C1",
"C1","C1", "C1", "C1",
"C1","C1", "C1", "C1"),
replicate = c(
"A1.1","A1.1","A1.1","A1.1",
"A1.2","A1.2","A1.2","A1.2",
"A1.3","A1.3","A1.3","A1.3",
"B1.1","B1.1","B1.1","B1.1",
"B1.2","B1.2","B1.2","B1.2",
"B1.3","B1.3","B1.3","B1.3",
"C1.1","C1.1","C1.1","C1.1",
"C1.2","C1.2","C1.2","C1.2",
"C1.3","C1.3","C1.3","C1.3"))
> data
day od series_id replicate
1 1 0.10 A1 A1.1
2 3 1.00 A1 A1.1
3 5 0.50 A1 A1.1
4 7 0.70 A1 A1.1
5 1 0.13 A1 A1.2
6 3 0.33 A1 A1.2
7 5 0.54 A1 A1.2
8 7 0.76 A1 A1.2
9 1 0.10 A1 A1.3
10 3 0.35 A1 A1.3
11 5 0.54 A1 A1.3
12 7 0.73 A1 A1.3
13 1 1.30 B1 B1.1
... etc...
r <- ggplot(data = data, aes(x = day, y = od))
r + geom_point(aes(group = replicate, color = series_id)) + # add points
geom_line(aes(group = replicate, color = series_id)) + # add lines
geom_smooth(aes(group = series_id)) # add smoother, average of each replicate
最佳答案
您是否尝试过family = "symmetric"
的geom_smooth
参数(该参数随后会传递给loess
)?这将使黄土光滑,抗异常值。
但是,查看您的数据,为什么您认为线性拟合不足够?您只有4个x值,而且当然似乎没有强有力的证据表明会偏离线性。
关于r - R:如何从ggplot2中的平滑器中删除异常值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2612495/
我是一名优秀的程序员,十分优秀!