- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的代码:
#data
sites <-
structure(list(site = c(928L, 928L, 928L, 928L, 928L, 928L, 928L,
928L, 928L, 928L, 928L, 928L, 928L, 928L,
928L, 928L, 928L, 928L, 928L, 928L, 928L,
928L, 928L, 928L, 928L, 928L),
date = c(13493L, 13534L, 13566L, 13611L, 13723L,
13752L, 13804L, 13837L, 13927L, 14028L,
14082L, 14122L, 14150L, 14182L, 14199L,
16198L, 16279L, 16607L, 16945L, 17545L,
17650L, 17743L, 17868L, 17941L, 18017L, 18092L),
y = c(7L, 7L, 17L, 18L, 17L, 17L, 10L, 3L, 17L, 24L,
11L, 5L, 5L, 3L, 5L, 14L, 2L, 9L, 9L, 4L, 7L,
6L, 1L, 0L, 5L, 0L)),
.Names = c("site", "date", "y"),
class = "data.frame", row.names = c(NA, -26L))
#convert to date
x<-as.Date(sites$date, origin="1960-01-01")
#plot smooth, line goes below zero!
qplot(data=sites, x, y, main="Site 349")
(p <- qplot(data = sites, x, y, xlab = "", ylab = ""))
(p1 <- p + geom_smooth(method = "loess",span=0.5, size = 1.5))
LOESS
线和置信区间低于零,我想将图形限制为 0 和正数(因为负数没有意义)。
最佳答案
我赞同马特·帕克 (Matt Parker) 的建议,即您必须更改拟合程序。通常适用于仅正数据的一种选择是在对数尺度上进行拟合,然后取幂以获得原始尺度上的结果。这将保证只有正值。
生成具有以下一些问题的随机数据:
d <- data.frame(x=0:100)
d$y <- exp(rnorm(nrow(d), mean=-d$x/40, sd=0.8))
qplot(x,y,data=d) + stat_smooth()
qplot(x,y,data=d) + stat_smooth() + scale_y_log10()+coord_trans(ytrans="pow10")
coord_trans
上看到这样的例子。帮助页面。如果您不喜欢 y Axis ,则可以操作中断和标签。
ggplot2
有一些变化因为这个问题最初是问的,而原来的答案没有处理0。
log(1+x)
转型。这是内置的,但我们需要进行逆变换
exp(x)-1
以及。
library(scales)
#create exp(x)-1 transformation, the inverse of log(1+p)
expm1_trans <- function() trans_new("expm1", "expm1", "log1p")
qplot(x, y, data=sites) + stat_smooth(method="loess") +
scale_y_continuous(trans=log1p_trans()) +
coord_trans(ytrans=expm1_trans())
library(splines)
qplot(x, y, data=sites) + stat_smooth(method="glm", family="quasipoisson",
formula = y ~ ns(x, 3))
关于r - 在 ggplot 中,在 LOESS 中将 y 限制为 >0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2777053/
我需要平滑一些模拟数据,但是当要平滑的模拟纵坐标大多是相同的值时,偶尔会遇到问题。这是最简单情况的一个可重现的小示例。 > x y loess.smooth(x,y) Error in simpl
我在使用 loess 时遇到问题和 loess.smooth带有缺失数据的时间序列。 这两个命令都不适用于此玩具数据。 x 1)。 关于r - "loess"缺失数据的时间序列,我们在Stack Ov
我的结果是 NA。我做错了什么? data(Boston, package='MASS') x <- Boston$dis y <- Boston$nox n <- length(x) cvs <-
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭去年。 Im
在使用 LOESS 平滑时,我无法理解如何在 ggplot2 中计算置信区间。从其他几个线程中,我的理解是 ggplot2 使用基于回归标准误差计算的 t 间隔,即使用实际数据点与 LOESS 线之间
我试图了解 predict.loess函数能够计算点 y_hat 处的新预测值 ( x )原始数据中不存在的。例如(这是一个简单的例子,我意识到这种例子显然不需要黄土,但它说明了这一点): x 1,
如果我有一些 (x,y) 数据,我可以轻松地通过它绘制直线,例如 f=glm(y~x) plot(x,y) lines(x,f$fitted.values) 但是对于曲线数据,我想要一条曲线。似乎可以
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我正在尝试用 Python 来做 R 上的 STL 函数。 R命令是 fit <- stl(elecequip, s.window=5) plot(fit) 我如何在 Python 中执行此操作?我调
如何在 python 中拟合局部加权回归,以便它可以用于预测新数据? 有 statsmodels.nonparametric.smoothers_lowess.lowess,但它只返回原始数据集的估计
我正在尝试使用 loess 拟合模型,但出现错误,例如“3 处使用的伪逆”、“邻域半径 1”和“倒数条件数 0”。这是一个 MWE: x = 1:19 y = c(NA,71.5,53.1,53.9,
我有一个数据集,其中包含一些点,并且想要在其上拟合一条线。我用loess函数尝试过。不幸的是我得到了非常奇怪的结果。请参阅下面的情节。我期望一条线能够更多地穿过这些点并贯穿整个情节。我怎样才能做到这一
好吧,我挥舞着我的白旗。 我正在尝试对我的数据集计算 loess 回归。 我希望 loess 计算一组不同的点,这些点绘制为每个组的平滑线。 问题是 loess 计算逃避了 dplyr::group_
我正在使用平滑器来检查事件发生的概率如何取决于时间 ods graphics on; proc loess data=final plots(only MAXPOINTS=NONE)=FITPLOT;
召集所有专家研究局部回归和/或R! 我在 R 中遇到了标准 loess 函数的限制,希望您能给我一些建议。当前的实现仅支持 1-4 个预测器。让我列出我们的应用场景,以说明为什么一旦我们想要使用全局拟
我正在 R 中运行 LOESS 回归,并且在我的一些较小的数据集上遇到了警告。 警告信息: 1: In simpleLoess(y, x, w, span, degree = degree, para
我对此很陌生,实际上我并不理解绘图方法之间的差异,但是考虑到我有一个小尺寸的图表,loess似乎给了我最丰富的信息。数据集(n=~300)。我正在尝试使用 facet_wrap 按性别拆分数据,而 l
我想获取嘈杂的 2d 数据并使用 LOESS 平滑来找到更平滑的 2D 表面。数据是r行c列的数据框或矩阵的形式。 'asbio' 包将为 n*n 数据绘制曲面图,我可以计算出如何使用 stats 基
我正在尝试使用泰坦尼克号的数据绘制二元选择 glm 的模型预测与经验概率的关系图。为了显示类(Class)和性别之间的差异,我使用了分面,但有两件事我不太明白。首先,我想将黄土曲线限制在 0 和 1
尝试在 R 中使用 MA 规范化 (http://en.wikipedia.org/wiki/MA_plot) 对两个变量 x 和 y 做 loess,如下所示: > x = rnorm(100) +
我是一名优秀的程序员,十分优秀!