我想复制并通过一些特殊格式的RStudio版本0.99.834中的一些代码.见下文MWE.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <-
lm(
formula=weight ~ group
)
lm.D90 <-
lm(
formula =weight ~ group - 1
) # omitting intercept
Run Code Online (Sandbox Code Playgroud)
现在,如果我复制以下代码
lm.D9 <-
lm(
formula=weight ~ group
)
lm.D90 <-
lm(
formula =weight ~ group - 1
) # omitting intercept
Run Code Online (Sandbox Code Playgroud)
进入RStudio Version 0.99.834
它给出以下输出
lm.D9 <-
lm(
formula=weight ~ group
)
lm.D90 <-
lm(
formula =weight ~ group - …
Run Code Online (Sandbox Code Playgroud) 这是中提到broom
的网站,它可以被用于TukeyHSD
和multcomp
(见这里)。但是,我无法弄清楚如何使用broom
forTukeyHSD
和multcomp
。
请参阅下面给出的 MWE。
df1 <- data.frame(
Rep = factor(rep(1:3, each = 4, times = 2)),
Trt = rep(paste0("T", 1:4), times = 6),
Loc = rep(paste0("Loc", 1:2), each = 12),
Y = rnorm(24)
)
library(dplyr)
df2 <- filter(df1, Loc=="Loc1")
fm1 <- aov(Y ~ Rep + Trt , data = df2)
anova(fm1)
library(multcompView)
fm1Tukey1 <-
data.frame(Letter = multcompLetters(TukeyHSD(fm1)$Trt[, "p adj"])$Letters)
fm1Tukey <- data.frame(Trt = row.names(fm1Tukey1), fm1Tukey1)
fm1Means1 <- …
Run Code Online (Sandbox Code Playgroud) R 3.5.0于2018年4月25日发布.我正在尝试在Ubuntu 18.04 LTS上安装R 3.5.0.我尝试了以下代码
echo "deb http://cran.stat.ucla.edu/bin/linux/ubuntu `lsb_release -sc`/" | sudo tee --append /etc/apt/sources.list.d/cran.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo apt update
sudo apt install r-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
r-base is already the newest version (3.4.4-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Run Code Online (Sandbox Code Playgroud)
想知道如何在Ubuntu 18.04 LTS上安装R 3.5.0.
我从R
和得到不同的多项式回归系数Python
.
[R
X <- c(0,0, 10, 10, 20, 20)
Y <- c(5, 7, 15, 17, 9, 11)
fm1 <- lm(Y~X+I(X^2))
summary(fm1)
Call:
lm(formula = Y ~ X + I(X^2))
Residuals:
1 2 3 4 5 6
-1 1 -1 1 -1 1
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 6.00000 1.00000 6.000 0.00927 **
X 1.80000 0.25495 7.060 0.00584 **
I(X^2) -0.08000 0.01225 -6.532 0.00729 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ …
Run Code Online (Sandbox Code Playgroud) 我不知道如何来模拟实验设计数据,如完全随机设计,随机区组设计,拉丁方设计等,[R .任何帮助将受到高度赞赏.谢谢
我想NAs
在输出中省略与执行knitr::kable
相同的输出xtable
(请参阅下面的kable
和xtable
输出)。
fm12anova <-
structure(list(SOV = c("Days", "Residuals"), Df2 = c(1L, 178L
), Sum.Sq2 = c(162702.651909532, 405251.617480465), Mean.Sq2 = c(162702.651909532,
2276.69448022733), F.value2 = c(71.4644205986244, NA), Pr..F.2 = c(9.89409632221545e-15,
NA), Sum.Sq1 = c(30031.0139578738, NA), Mean.Sq1 = c(30031.0139578738,
NA), NumDF1 = c(1L, NA), DenDF1 = c(17.0000010028433, NA), F.value1 = c(45.8530037127448,
NA), Pr..F.1 = c(3.26378804516025e-06, NA)), class = "data.frame", row.names = c(NA,
-2L), .Names = c("SOV", "Df2", "Sum.Sq2", "Mean.Sq2", "F.value2",
"Pr..F.2", "Sum.Sq1", "Mean.Sq1", "NumDF1", …
Run Code Online (Sandbox Code Playgroud) 我要在以下数据框中创建两列(OPop
和WPop
)Data
:
OState OCounty WState WCounty OYear
AL Autauga AL Baldwin 2004
AL Barbour AL Bibb 2001
CA Amador WY Weston 1985
CA Alameda CA Amador 1999
Run Code Online (Sandbox Code Playgroud)
的值OPop
和WPop
基于所述四个列(的值Pop1980
,Pop1990
, Pop2000
和Pop2010
另一数据帧的)Data1
State County Pop1980 Pop1990 Pop2000 Pop2010
AL Autauga 32259 34222 43671 54571
AL Baldwin 78556 98280 140415 182265
AK Aleutians East 7768 2464 2697 3141
AK Aleutians West NA 9478 5465 5561
CA Alameda …
Run Code Online (Sandbox Code Playgroud) 我可以使用该anova
函数来获得线性模型的ANOVA表.然而,这给出了每个解释变量对响应变量的单独影响.我想知道R中是否有任何函数可以获得overall ANOVA
所有解释变量对响应变量的总体影响.在此先感谢您的帮助.
set.seed(12345)
X1 <- 10*abs(rnorm(n=10, mean = 5, sd = 1))
X2 <- 20*abs(rnorm(n=10, mean = 4, sd = 2))
Y <- 50*abs(rnorm(n=10, mean = 10, sd = 4))
df <- data.frame(X1, X2, Y)
fm1 <- lm(formula=Y~X1+X2, data=df)
anova(fm1)
Analysis of Variance Table
Response: Y
Df Sum Sq Mean Sq F value Pr(>F)
X1 1 37842 37842 0.7815 0.406
X2 1 115774 115774 2.3910 0.166
Residuals 7 338941 48420
Run Code Online (Sandbox Code Playgroud)
编辑(2017-10-23)
所需的输出是
Analysis of Variance …
Run Code Online (Sandbox Code Playgroud) r ×8
regression ×2
anova ×1
broom ×1
dplyr ×1
editor ×1
formatting ×1
installation ×1
kable ×1
kableextra ×1
knitr ×1
lm ×1
multcompview ×1
python ×1
python-3.x ×1
rstudio ×1
simulation ×1
statistics ×1
tukey ×1
ubuntu ×1
ubuntu-18.04 ×1
updating ×1
xtable ×1