找回密码
 注册
查看: 584|回复: 0

R语言 rockchalk包 predictOMatic()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-27 22:44:12 | 显示全部楼层 |阅读模式
predictOMatic(rockchalk)
predictOMatic()所属R语言包:rockchalk

                                        predictOMatic creates predicted values for a fitted regression model.
                                         predictOMatic创建一个拟合回归模型的预测值。

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

If a "focus list" is supplied, predictOMatic supplies predicted values only for those selected input values. If no "focus list" is supplied, predictOMatic supplies a prediction summary for each separate independent variable. That is, in a model with formula y ~ x1 + x2 + x3, then separate tables of predicted values will be supplied, one for each of x1, x2, and x3.
如果“关注名单”提供,predictOMatic的供应预测值只有那些被选中的输入值。如果没有“关注名单”提供,predictOMatic预测汇总为每个单独的独立变量。也就是说,在一个模型中与公式y~X1 + X2 + X3,然后单独的表的预测值将被提供的,每一个用于为x1,x2和x3。


用法----------Usage----------


  predictOMatic(model = NULL, fl = NULL,
    divider = "quantile", n = 3, ...)



参数----------Arguments----------

参数:model
Required. A fitted regression model
必需的。一个合身的回归模型


参数:fl
(focus list). Optional. A named list of variables and values, such as fl = list("x1" = c(1,2,3), "x2" = c("M","F"), "x3" = quantile(dat$x3)). Must name only predictors that are fitted in model.  Need not include all predictors in a model. Predictor variables in model that are not named in fl will be set to mean or mode values. See details and examples.
(关注名单)。可选。命名的变量和值,如佛罗里达州=列表(“X1”= C(1,2,3),“X2”= C(“M”,“F”),“X3” =位数(那$×3))。必须命名的预测,安装在model。不包括所有的预测模型中的。预测变量的model这将意味着没有被命名,在佛罗里达州或模式值。细节和例子。


参数:divider
Optional. If fl is not specified, automatic selection of predictor values is employed. divider determines the method of selection. Should be one of c("quantile","std.dev","table"). This determines whether values selected are quantile values, values based on the mean plus-or-minus standard deviation values, or a table of most frequently occurring values. Documentation for the details can be found in the functions cutByTable, cutByQuantile, and cutBySD.
可选。如果未指定佛罗里达州的预测值,自动选择。 divider决定选择的方法。应该是C(“位数”,“std.dev”,“表”)。这确定值是否选择的分量的值,基于平均值加上或减的标准偏差值的值,或最频繁出现的值的表。文件的详细信息,可以发现在功能cutByTable,cutByQuantile和cutBySD。


参数:n
If fl is not specified, automatic selection of predictor values is employed. This determines the number of values for which predictions are sought.
如果未指定佛罗里达州的预测值,自动选择。这确定寻求预测的值的数目。


参数:...
Optional arguments to be passed to the predict function
可选参数传递的预测功能


Details

详细信息----------Details----------

It may be important to make sure that diagnostic plots and summaries of predictions are calculated with the exact same data that was used to fit the model. The function model.data is intended to facilitate that comparison. One can fit a model, use model.data to get the data that was used, and then use that extracted data to decide on values to be set in the focus list.
这可能是重要的,以确保诊断图和摘要完全相同的数据被用来拟合模型的预测计算。函数model.data目的是为了方便,比较。一个可以拟合模型,使用model.data得到被使用的数据,然后使用该提取的数据来决定的值将被设定在聚焦列表。

For example, create a copy of the data from a model m1 with
例如,创建一个副本的数据从一个模型M1

m1dat <- model.data(m1)
m1dat < -  model.data(M1)

and then use m1dat to select values that might be predicted in a command like
,然后使用m1dat选择预测值可能在这样的命令

predictOMatic( m1, fl = list("x1" = median(m1dat$x1), "x2"=c(1,2,3), "x3" = quantile(m1dat$x3))
predictOMatic(M1,fl的=列表(“×1”=中位数(m1dat $×1),“×2”= C(1,2,3),“×3”=分位数(m1dat $×3))


值----------Value----------

A data frame or a list of data frames.
一个数据框或数据框的列表。


(作者)----------Author(s)----------



Paul E. Johnson &lt;pauljohn@ku.edu&gt;




实例----------Examples----------


library(rockchalk)

set.seed(12345)
N <- 100
x1 <- rpois(N, l=6)
x2 <- rnorm(N, m=50, s=10)
x3 <- rnorm(N)
xcat1 <- gl(2,50, labels=c("M","F"))
xcat2 <- cut(rnorm(N), 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 <- 15
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(N)
rownames(dat$y) <- NULL
## rownames of dat$y don't match rownames of dat. Humphf.[#DAT $ Y不匹配的行名行名的DAT。 Humphf。]
## I've not seen that problem before[#我从来没见过这个问题之前]

dat$x1[sample(N, 5)] <- NA
dat$x2[sample(N, 5)] <- NA
dat$x3[sample(N, 5)] <- NA
dat$xcat2[sample(N, 5)] <- NA
dat$xcat1[sample(N, 5)] <- NA
dat$y[sample(N, 5)] <- NA


m0 <- lm(y ~ x1 + x2 + xcat1, data = dat)
summary(m0)
m0.data <- model.data(m0)
summarize(m0.data)

(m0.p1 <- predictOMatic(m0))
(m0.p2 <- predictOMatic(m0, interval = "confidence"))

(m0.p3 <- predictOMatic(m0, divider="std.dev.", n=5))

(m0.p3 <- predictOMatic(m0, fl = list("x1" = c(6,7), "xcat1" = levels(m0.data$xcat1))))






m1 <- lm(y ~ log(10+x1) + sin(x2) + x3, data=dat)
m1.data <- model.data(m1)
summarize(m1.data)

(newdata(m1))
(newdata(m1, fl = list(x1=c(6, 8, 10))))
(newdata(m1, fl = list(x1 = c(6, 8, 10), x3 = c(-1,0,1))))
(newdata(m1, fl = list(x1 = c(6, 8, 10), x2 = quantile(m1.data$x2), x3 = c(-1,0,1))))

(m1.p1 <- predictOMatic(m1, divider="std.dev", n = 5))
(m1.p1 <- predictOMatic(m1, divider="quantile", n = 5))

(m1.p1 <- predictOMatic(m1, fl=list(x1=c(6, 8, 10), x2 = median(m1.data$x2, na.rm = TRUE))))
(m1.p1 <- predictOMatic(m1, fl=list(x1=c(6, 8, 10), x2 = quantile(m1.data$x2, na.rm = TRUE))))

(m1.p1 <- predictOMatic(m1))
(m1.p1 <- predictOMatic(m1, divider="std.dev."))
(m1.p1 <- predictOMatic(m1, divider="std.dev.", n=5))
(m1.p1 <- predictOMatic(m1, divider="std.dev.", interval="confidence"))




m2 <- lm(y ~ x1 + x2 + x3 + xcat1 + xcat2, data = dat)


##  has only columns and rows used in model fit[#只有列和行中使用的模型拟合]
m2.data <- model.data(m2)
summarize(m2.data)

newdata(m2, fl = list(xcat1 = levels(m2.data$xcat1)))
## mix and match all combinations of xcat1 and xcat2[#混合和匹配的所有组合xcat1和xcat2]
newdata(m2, fl = list(xcat1 = levels(m2.data$xcat1), xcat2 = levels(m2.data$xcat2)))

m2.new1 <- newdata(m2, fl = list(xcat1 = levels(m2.data$xcat1), xcat2 = levels(m2.data$xcat2)))

predict(m2, newdata = m2.new1)

## Pick some particular values for focus[#为重点挑选一些特定的值]
m2.new2 <- newdata(m2, fl = list(x1 = c(1,2,3), xcat2 = c("M","D")))
## Ask for predictions[#要求预测]
predict(m2, newdata = m2.new2)




## Compare: predictOMatic generates a newdata frame and predictions in one step[#比较:predictOMatic的生成newdata在一个步骤的框架和预测]

(m2.p1 <- predictOMatic(m2, fl = list(xcat1 = levels(m2.data$xcat1), xcat2 = levels(m2.data$xcat2))))


(m2.p2 <- predictOMatic(m2, fl = list(x1 = c(1,2,3), xcat2 = c("M","D"))))

(m2.p3 <- predictOMatic(m2, fl = list(x2 = c(0.25, 1.0), xcat2 = c("M","D"))))

(m2.p4 <- predictOMatic(m2, fl = list(x2 = plotSeq(m2.data$x2, 10) , xcat2 = c("M","D"))))

(m2.p5 <- predictOMatic(m2, fl = list(x2 = c(0.25, 1.0), xcat2 = c("M","D")), interval="conf"))

(predictOMatic(m2, interval="conf"))

(m2.p6 <- predictOMatic(m2, fl = list(x2 = c(49, 51), xcat2 = levels(m2.data$xcat2), x1=plotSeq(dat$x1))))

plot(y ~ x1, data= m2.data)
by(m2.p6, list(m2.p6$xcat2), function(x) {lines(x$x1, x$fit, col=x$xcat2, lty=as.numeric(x$xcat2))})

m2.newdata <- newdata(m2, fl = list(x2 = c(48, 50, 52), xcat2 = c("M","D")))
predict(m2, newdata = m2.newdata)

(m2.p7 <- predictOMatic(m2, fl = list(x2 = c(48, 50, 52), xcat2 = c("M","D"))))

(m2.p8 <- predictOMatic(m2, fl = list(x2 = range(m2.data$x2), xcat2 = c("M","D"))))

(m2.p9 <- predictOMatic(m2, fl = list(x2 = plotSeq(m2.data$x2), x1 = quantile(m2.data$x1, pr =c(0.33, 0.66), na.rm = TRUE), xcat2 = c("M","D"))))
plot(y ~ x2 , data = m2.data)
by(m2.p9, list(m2.p9$x1, m2.p9$xcat2), function(x) {lines(x$x2, x$fit)})



(predictOMatic(m2, fl = list(x2 = c(50, 60), xcat2 = c("M","D")), interval="conf"))


## create a dichotomous dependent variable[#建立一个二分因变量]
y2 <- ifelse(rnorm(N) > 0.3, 1, 0)
dat <- cbind(dat, y2)

m3 <- glm(y2 ~ x1 + x2 + x3 + xcat1, data=dat, family=binomial(logit))
summary(m3)
m3.data <- model.data(m3)
summarize(m3.data)

(m3.p1 <- predictOMatic(m3, divider="std.dev.", type="response"))

(m3.p2 <- predictOMatic(m3, fl = list(x2 = c(40, 50, 60), xcat1 = c("M","F")), divider="response", interval="conf"))

## Want a full accounting for each value of x2?[想要一个完整的会计X2的每个值吗?]
(m3.p3 <- predictOMatic(m3, fl = list(x2 = unique(m3.data$x2), xcat1 = c("M","F")), interval="conf", type="response"))


## Would like to write a more beautiful print method[#想写出更漂亮的印花方法]
## for output object, but don't want to obscure structure from user.[#输出对象,但并不想掩盖结构从用户。]
for (i in names(m3.p1)){
    dns <- cbind(m3.p1[[i]][i], m3.p1[[i]]$fit)
    colnames(dns) <- c(i, "predicted")
    print(dns)
}



转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-25 16:39 , Processed in 0.019424 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表