model.data(rockchalk)
model.data()所属R语言包:rockchalk
Creates a "raw" (UNTRANSFORMED) data frame equivalent
创建一个“原始”(未变形)的数据框相当于
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Unlike model.frame and model.matrix, this does not return transformed variables.
不像model.frame和model.matrix,这并不返回变换后的变量。
用法----------Usage----------
model.data(model)
参数----------Arguments----------
参数:model
A fitted regression model in which the data argument is specified. This function will fail if the model was not fit with the data option.
已安装的回归模型,其中的数据参数指定。此函数将失败,如果该模型不适合使用的数据选项。
值----------Value----------
A data frame
一个数据框
(作者)----------Author(s)----------
Paul E. Johnson <pauljohn@ku.edu>
实例----------Examples----------
library(rockchalk)
## check if model.data works when there is no data argument[#检查model.data工作时,有没有数据参数]
set.seed(12345)
x1 <- rpois(100, l=6)
x2 <- rnorm(100, m=50, s=10)
x3 <- rnorm(100)
y <- rnorm(100)
m0 <- lm(y ~ x1 + x2 + x3)
m0.data <- model.data(m0)
x1[4:5] <- NA
m0 <- lm(y ~ x1 + x2 + x3)
m0.data <- model.data(m0)
head(m0.data)
## check numeric and categorical predictors[#检查数字和分类预测]
x1 <- rpois(100, l=6)
x2 <- rnorm(100, m=50, s=10)
x3 <- rnorm(100)
xcat1 <- gl(2,50, labels=c("M","F"))
xcat2 <- cut(rnorm(100), breaks=c(-Inf, 0, 0.4, 0.9, 1, Inf), labels=c("R", "M", "D", "P", "G"))
dat <- data.frame(x1, x2, x3, xcat1, xcat2)
rm(x1, x2, x3, xcat1, xcat2)
xcat1n <- with(dat, contrasts(xcat1)[xcat1, ,drop=FALSE])
xcat2n <- with(dat, contrasts(xcat2)[xcat2, ])
STDE <- 20
dat$y <- 0.03 + 0.8*dat$x1 + 0.1*dat$x2 + 0.7*dat$x3 + xcat1n %*% c(2) + xcat2n %*% c(0.1,-2,0.3, 0.1) + STDE*rnorm(100)
rownames(dat$y) <- NULL
## rownames don't match dat, I've not seen that problem before[#行名不匹配,DAT,我没有看到这个问题之前]
## Will fail because m0 has no data argument[#M0将失败,因为没有数据参数]
## m0 <- lm(y ~ log(10+x1) + x2)[#M0 - LM(Y~log(10 + X1)+ X2)]
## m0.data <- model.data(m0) # should fail[#m0.data < - model.data(M0)应该失败]
m1 <- lm(y ~ poly(x1, 2), data=dat)
m1.data <- model.data(m1)
head(m1.data)
attr(m1.data, "varNamesRHS")
## Check to make sure d is not mistaken for a data column[#检查,以确保ð不会被误解为一个数据列]
d <- 2
m2 <- lm(y ~ poly(x1, d), data=dat)
m2.data <- model.data(m2)
head(m2.data)
attr(m2.data, "varNamesRHS")
## Check to see how the 10 in log is handled[#检查,看看如何处理的10个log]
m3 <- lm(y ~ log(10 + x1) + poly(x1, d) + sin(x2), data=dat)
m3.data <- model.data(m3)
head(m3.data)
attr(m3.data, "varNamesRHS")
m4 <- lm(log(50+y) ~ log(d+10+x1) + poly(x1, 2), data=dat)
m4.data <- model.data(m4)
head(m4.data)
attr(m4.data, "varNamesRHS")
m4 <- lm(y ~ x1*x1, data=dat)
m4.data <- model.data(m4)
head(m4.data)
attr(m4.data, "varNamesRHS")
m4 <- lm(y ~ x1 + I(x1^2), data=dat)
m4.data <- model.data(m4)
head(m4.data)
attr(m4.data, "varNamesRHS")
## Put in some missings.[#将一些missings。]
## poly doesn't work if there are missings, but[#聚不工作,如果有missings,但]
## can test with log[#可以测试log]
dat$x1[sample(100, 5)] <- NA
dat$y[sample(100, 5)] <- NA
dat$x2[sample(100, 5)] <- NA
dat$x3[sample(100,10)] <- NA
m1 <- lm(y ~ log(10 + x1), data=dat)
m1.data <- model.data(m1)
head(m1.data)
summarize(m1.data)
attr(m1.data, "varNamesRHS")
m2 <- lm(y ~ log(x1 + 10), data=dat)
m1.data <- model.data(m1)
head(m1.data)
summarize(m1.data)
attr(m1.data, "varNamesRHS")
d <- 2
m3 <- lm(log(50+y) ~ log(d+10+x1) + x2 + sin(x3), data=dat)
m3.data <- model.data(m3)
head(m3.data)
summarize(m3.data)
attr(m3.data, "varNamesRHS")
m4 <- lm(y ~ x1^3 + log(x2), data=dat)
m4.data <- model.data(m4)
summarize(m4.data)
attr(m4.data, "varNamesRHS")
m5 <- lm(y ~ x1 + I(x1^2) + cos(x2), data=dat)
m5.data <- model.data(m5)
head(m5.data)
summarize(m5.data)
attr(m5.data, "varNamesRHS")
## Now try with some variables in the dataframe, some not[#现在尝试用一些变量的数据框,一些不]
x10 <- rnorm(100)
x11 <- rnorm(100)
m6 <- lm(y ~ x1 + I(x1^2) + cos(x2) + log(10 + x10) + sin(x11) + x10*x11, data=dat)
m6.data <- model.data(m6)
head(m6.data)
dim(m6.data)
summarize(m5.data)
attr(m6.data, "varNamesRHS")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|