我想通过scatterplot3d绘制响应曲面,但是下面的代码通过错误.
library(rsm)
swiss2.lm <- lm(Fertility ~ poly(Agriculture, Education, degree = 2), data = swiss)
persp(swiss2.lm, Education ~ Agriculture, zlab = "Fertility")
library(scatterplot3d)
s3d <-
scatterplot3d(
swiss
# , type = "h"
, highlight.3d = TRUE
, angle = 55
, scale.y = 0.7
, pch = 16
)
s3d$plane3d(swiss2.lm, lty.box = "solid")
Run Code Online (Sandbox Code Playgroud)
如果您能帮助解决问题,我将非常感谢.谢谢
Eidt
Error in segments(x, z1, x + y.max * yx.f, z2 + yz.f * y.max, lty = ltya, :
cannot mix zero-length and non-zero-length coordinates
Run Code Online (Sandbox Code Playgroud)
我正在使用库中的swiss …
我正在进行聚类分析并创建树形图.我使用了ggdendrogram
包,想要使用它的输出ggplot2
.我想知道如何获得与叶标签相同的x标签.谢谢
D1 <- as.dist(
matrix(
data=
c( 0, 9, 3, 6, 11
, 9, 0, 7, 5, 10
, 3, 7, 0, 9, 2
, 6, 5, 9, 0, 8
, 11, 10, 2, 8, 0)
, nrow= 5
, ncol = 5
, byrow=TRUE
))
HCD1 <- hclust(d = D1, method="single", members=NULL)
library(ggdendro)
ggdendrogram(HCD1, theme_dendro=FALSE)
Run Code Online (Sandbox Code Playgroud)
HCD1Data <- dendro_data(as.dendrogram(HCD1))
library(ggplot2)
p1 <-
ggplot(data = HCD1Data$segments) +
geom_segment(aes(x=x, y=y, xend=xend, yend=yend))
print(p1)
Run Code Online (Sandbox Code Playgroud)
我从下面的代码在这里通过@AnandaMahto写的.此功能以前工作正常,但停止使用R 3.1.1
和knitr 1.6.10
.任何帮助将不胜感激.谢谢
\documentclass{article}
\begin{document}
<<echo=FALSE>>=
library(devtools)
source_gist("https://gist.github.com/mrdwab/7586769")
@
\Sexpr{knit_child(textConnection(helpExtract(cor, section="Arg", type = "s_text")),
options = list(tidy = FALSE, eval = FALSE))}
\Sexpr{knit_child(textConnection(helpExtract(cor, type = "s_code")),
options = list(tidy = FALSE, eval = FALSE))}
<<tidy=TRUE>>=
## normal R code
args(lm)
@
\end{document}
Run Code Online (Sandbox Code Playgroud) 我想xtable
在candisc::cancor
输出上使用函数.但是想不出来.在这方面的任何帮助将受到高度赞赏.谢谢
library(xtable)
library(candisc)
data(Rohwer, package="heplots")
X <- as.matrix(Rohwer[,6:10]) # the PA tests
Y <- as.matrix(Rohwer[,3:5]) # the aptitude/ability variables
(cc <- cancor(X, Y, set.names=c("PA", "Ability")))
Canonical correlation analysis of:
5 PA variables: n, s, ns, na, ss
with 3 Ability variables: SAT, PPVT, Raven
CanR CanRSQ Eigen percent cum scree
1 0.6703 0.44934 0.81599 77.30 77.30 ******************************
2 0.3837 0.14719 0.17260 16.35 93.65 ******
3 0.2506 0.06282 0.06704 6.35 100.00 **
Test of H0: The canonical …
Run Code Online (Sandbox Code Playgroud) 我想拟合以下广义非线性模型:Probit(G)=K+1/Sigma*(Temp-T0)*Time
.作为天真的模特,我创造Probits(G)
了qnorm(G)
然后适合了Nonlinear Model
.但我想,以适应Nonlinear Model
与logit
链接类似glm
的功能R
.如果有人帮我配合带logit
链接的广义非线性模型,我将非常感激R
.在此先感谢您的帮助.
Data <-
structure(list(Temp = c(23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
27L, 27L, 27L, 27L, 27L, 27L, 33L, 33L, 33L, 33L, 33L, 33L, 33L,
35L, 35L, 35L, 35L, 35L), Time = c(144L, 168L, 192L, 216L, 240L,
264L, 288L, 312L, 120L, 144L, 168L, 192L, 216L, 240L, 72L, 96L,
120L, 144L, 168L, 192L, 216L, 96L, 120L, 144L, 168L, …
Run Code Online (Sandbox Code Playgroud) 我以前用交互绘图,ggplot2
代码如下.现在我想重现相同的情节,ggvis
如下所示,与ggplto2
输出不同.如果有人指出我用`ggvis获得相同的情节,我将非常感激.提前致谢.
library(ggplot2)
p <- qplot(as.factor(dose), len, data=ToothGrowth, geom = "boxplot", color = supp) + theme_bw()
p <- p + labs(x="Dose", y="Response")
p <- p + stat_summary(fun.y = mean, geom = "point", color = "blue", aes(group=supp))
p <- p + stat_summary(fun.y = mean, geom = "line", aes(group = supp))
p <- p + theme(axis.title.x = element_text(size = 12, hjust = 0.54, vjust = 0))
p <- p + theme(axis.title.y = element_text(size = 12, angle = …
Run Code Online (Sandbox Code Playgroud) 我想找到Lethal Dose(LD50
),其置信区间为R
.其他软件系列Minitab,SPSS,SAS提供了三种不同版本的置信区间.我在任何包中找不到这样的间隔R
(我也使用findFn
了sos
包中的函数).如果有人指导如何找到这样的间隔,我将非常感激.我基于Delta方法编写了一种类型的间隔(不确定它是否正确)但是想要使用R
包中的任何已建立的函数.谢谢
MWE
dose <- c(10.2, 7.7, 5.1, 3.8, 2.6, 0)
total <- c(50, 49, 46, 48, 50, 49)
affected <- c(44, 42, 24, 16, 6, 0)
finney71 <- data.frame(dose, total, affected)
fm1 <- glm(cbind(affected, total-affected) ~ log(dose),
family=binomial(link = logit), data=finney71[finney71$dose != 0, ])
summary(fm1)$coef
Estimate Std. Error z value Pr(>|z|)
(Intercept) -4.886912 0.6429272 -7.601035 2.937717e-14
log(dose) 3.103545 0.3877178 8.004650 1.198070e-15
library(MASS)
xp <- dose.p(fm1, p=c(0.50, 0.90, …
Run Code Online (Sandbox Code Playgroud) 我想知道是否有办法为每个回归方程提取R2.
d <- data.frame(
state = rep(c('NY', 'CA'), 10),
year = rep(1:10, 2),
response= rnorm(20)
)
library(plyr)
models <- dlply(d, "state", function(df)
lm(response ~ year, data = df))
ldply(models, coef)
l_ply(models, summary, .print = TRUE)
Run Code Online (Sandbox Code Playgroud)
我试过了
l_ply(models, summary$r.squared, .print = TRUE)
Run Code Online (Sandbox Code Playgroud)
但是这会抛出以下错误消息
Error in summary$r.squared : object of type 'closure' is not subsettable
Run Code Online (Sandbox Code Playgroud) 这是我所面对的一个简单例子.我有我的因子水平,B-1, B-2, B-9, B-10, B-11
并希望按照给定的顺序排列它们.在这里,我可以轻松地重新排列级别,但是,在我的数据中,我确实有复杂的结构,并希望通过一些编码来完成.我想知道如何按逻辑顺序排列这些因子水平.
set.seed(12345)
f <- rep(c("B-1", "B-2", "B-9", "B-10", "B-11"), each=3)
Y <- runif(n=15, min=100, max=1000)
df <- data.frame(f, Y)
levels(df$f)
[1] "B-1" "B-10" "B-11" "B-2" "B-9"
library(gtools)
mixedsort(df$f)
[1] B-1 B-1 B-1 B-10 B-10 B-10 B-11 B-11 B-11 B-2 B-2 B-2 B-9 B-9 B-9
Levels: B-1 B-10 B-11 B-2 B-9
df2 <- df[mixedorder(df$f), ]
df3 <- within(df,
Position <- factor(f,
levels=names(sort(table(f),
decreasing=TRUE))))
levels(df3$Position)
[1] "B-1" "B-10" "B-11" "B-2" "B-9"
Run Code Online (Sandbox Code Playgroud)
我想知道如何从数值中减去等级data.table
.我的MWE如下.
set.seed(12345)
A <- rep(x=paste0("A", 1:2), each=6)
B <- rep(x=paste0("B", 1:3), each=2, times=2)
Rep <- rep(x=1:2, times=3)
Y <- rnorm(n=12, mean = 50, sd = 5)
library(data.table)
dt <- data.table(A, B, Rep, Y)
dt[, j=mean(Y), by=.(A, B)]
dt[, j=mean(Y), by=.(A)]
dt[, j=mean(Y), by=.(A, B)] - dt[, j=mean(Y), by=.(A)]
Error in Ops.data.frame(dt[, j = mean(Y), by = .(A, B)], dt[, j = mean(Y), :
‘-’ only defined for equally-sized data frames
Run Code Online (Sandbox Code Playgroud)
编辑
我要这个:
dt[, j=mean(Y), by=.(A, B)] - dt[, …
Run Code Online (Sandbox Code Playgroud) r ×10
ggplot2 ×2
graph ×2
knitr ×2
sweave ×2
data.table ×1
dataframe ×1
dendrogram ×1
ggdendro ×1
ggvis ×1
glm ×1
gnm ×1
latex ×1
levels ×1
nls ×1
regression ×1
rnw ×1
scatter-plot ×1
sorting ×1
statistics ×1
xtable ×1