- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 mgcv
包中的广义加性模型 gam()
合并到 xyplot()
函数或 coplot( )
R 中 lattice
包中的函数。
数据可以在http://statweb.stanford.edu/~tibs/ElemStatLearn/中找到, 通过选择臭氧数据。
这是我的内核平滑代码。
ozonedata=ozone
Temperature=equal.count(ozonedata$temperature,4,1/2)
Wind=equal.count(ozonedata$wind,4,1/2)
xyplot(ozone^(1/3) ~ radiation | Temperature * Wind, data = ozonedata, as.table = TRUE,
panel = function(x, y, ...) {panel.xyplot(x, y, ...);panel.loess(x, y)},
pch = 20,xlab = "Solar Radiation", ylab = "Ozone (ppb)")
或
coplot((ozone^(1/3))~radiation|temperature*wind,data=ozonedata,number=c(4,4),
panel = function(x, y, ...) panel.smooth(x, y, span = .8, ...),
xlab="Solar radiation (langleys)", ylab="Ozone (cube root ppb)")
生成广义加性模型如下。
gam_ozone = gam(ozone^(1/3)~s(radiation)+s(temperature)+s(wind),data=ozonedata,method="GCV.Cp")
现在我无法将 gam()
的拟合结合到点阵图中。
最佳答案
我认为这应该可行。请注意,我们将 gam_ozone
对象作为参数传递给名为 gam
的 xyplot
。这将允许我们在面板功能中访问它。
xyplot(ozone^(1/3) ~ radiation | Temperature * Wind, data = ozonedata,
as.table = TRUE, gam=gam_ozone,
panel = function(x, y, gam,...) {
xx <- dimnames(trellis.last.object())
ww <- arrayInd(packet.number(), .dim=sapply(xx, length))
avgtmp <- mean(xx[[1]][[ww[1]]])
avgwind <- mean(xx[[2]][[ww[2]]])
gx<-seq(min(x, na.rm=T), max(x, na.rm=T), length.out=50)
gy<-predict(gam, data.frame(radiation=gx,
temperature=avgtmp, wind=avgwind))
panel.xyplot(x, y, ...);
panel.xyplot(gx, gy, ..., col="red", type="l");
},
pch = 20,xlab = "Solar Radiation", ylab = "Ozone (ppb)"
)
现在,为了使用 gam
进行预测,您必须为每个面板找到用于风和温度的值。我决定做的,只是取每个带状疱疹范围的中间值。所以我用了 Deepayan-approved, undocumented feature通过调用 dimnames
获取每个当前带状疱疹的范围。然后我用 packet.number()
找到当前面板 一旦我有了范围,我就采取方法获得平均值。
不,我将使用我们传入的 gam
模型来预测每个面板的曲线。我根据观察值计算了 50 个 x
值的范围,然后从 gam
中预测了一个新行。
最后,我使用 panel.xyplot
绘制原始数据,然后绘制 gam
预测线。
关于r - 如何将 gam() 合并到 Lattice 包的 xyplot() 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23977949/
我正在尝试使用 android studio 3.5 来熟悉 android XYPlot。我首先测试了几个例子,最后得到了同样的错误 - Caused by: android.view.Inflat
下面是我在仅以单个变量为条件时使用的代码。如下所示使用 index.cond 可以切换最终图表中面板的顺序。但是,现在我以两个变量为条件,下面的代码无法切换不同面板的位置。我如何修改 index.co
我已经加载了lattice包。然后我运行: > xyplot(yyy ~ xxx | zzz, panel = function(x,y) { panel.lmline(x,y)} 这会生成绘图面板,
我想使用 r 的 lattice 包叠加直方图和表示累积分布函数的 xyplot。 我曾尝试使用自定义面板功能来完成此操作,但似乎无法正确处理——我被一个单变量的图和一个双变量的图挂断了。 这是我想要
我遇到了无法解决的 ggplot 问题,所以也许这里有人可以指出原因。抱歉,我无法上传我的数据集,但可以在下面找到一些数据描述。 ggplot 的输出如下所示,除了 NO 行,其他一切正常。 > al
我用格子创建了一个 xyplot library(lattice) X1=c(5, -2, 1, -3) X2=X1^2 names=paste("dot", 1:4, sep="") xyplot(
R 按字母顺序(对于字符串)或级别顺序(对于因子)确定 xyplot() 中的面板顺序。我有日期作为文本,我想按时间顺序显示,而不是按字母顺序显示。 x <- sample(1:10, 10, rep
现在我有这张图表:http://i.stack.imgur.com/xyyNX.png 我想显示垂直网格。我不知道该怎么做。如果可能,我也想替换虚线。 这是我用来绘制的代码(忽略不相关的部分,例如实际
我想在格子中的单个面板上叠加多个组,并且想要独立的回归线。 获得多个面板相当容易,每个面板都有一条使用条件因子的回归线: xyplot( Petal.Width ~ Petal.Length |
我在数据框上使用 xyplot,并且想要向面板函数提供不是 (x,y, ...) 参数的数据,而是数据框的一些附加列(例如下面示例中的 k) ): library(lattice) mydata <-
当我在重新排序因子之前使用线连接制作 xyplot 时,它为我提供了数据点之间良好的顺序连接: library(lattice) fin <- read.csv("http://dl.dropbox.
我试图改变 strip 的背景颜色(它是一个 6 x 6 矩阵,我有 6 个 strip 颜色存储在名为 cola 的向量中)。我尝试结合在互联网上找到的东西,但我得到的结果完全偏离了目标:现在我得到
我正在尝试使用 xYplot from package Hmisc 绘制覆盖在抖动原始数据点上的误差线。使用panel.stripplot 调用xYplot 中的函数似乎很简单。它可以工作,但有一个奇
考虑一个具有 relation='fixed'、alternating=FALSE 和 as.table=TRUE< 的晶格 xyplot/。 如果最后一行面板不完整(即面板数量少于布局的列数量),则
我正在使用 jfreechart,我需要向我的系列数据添加标签。图形上有粗体点,需要标签...以下代码不起作用。 XYSeries series = new XYSeries("Average
我的绘图(使用 xyplot、lattice)看起来像: 看起来不错,但是如何控制灰色面板框的高度呢? 我试过: strip=strip.custom( par.strip.text=list(cex
我正在尝试重现 this plot : 它看起来像库格子中的 xyplot,但我找不到将马赛克图与 xyplot 组合的方法。 有人知道怎么做吗? 最佳答案 你只是在寻找内置于 vcd:::cotab
我有一个“长”数据框定义为: q <- data.frame(Indicator.Code=factor(),Year=numeric(),Value=numeric()) 并且我试图在单个 xypl
大约一年以来,我一直在使用 AndroidPlot 在我的应用程序中显示不同的图表。现在我正在使用 BarCharts,图表已经完成,但我怎样才能使角变圆? 我找到了一些关于线条的结果: How to
我想将点的形状设置为圆形。我是这样做的: Shape shape = new Ellipse2D.Double(-5,-5,5,5); renderer.setSeriesShape(0, sha
我是一名优秀的程序员,十分优秀!