knitr&x2B;lyx:精确logistic回归实践中的一个错误
你们可能知道,有一种技术,叫做精确逻辑回归。加州大学洛杉矶分校的idre提供了极好的分析示例。() 当我使用示例分析进行练习时,我会遇到knitr(+lyx)的错误 在网页中的语法列表中间,下面的语法会产生错误。Knitr似乎能很好地解释区块,但lyx产生了一个与pdf输出相关的错误knitr&x2B;lyx:精确logistic回归实践中的一个错误,r,knitr,lyx,verbatim,R,Knitr,Lyx,Verbatim,你们可能知道,有一种技术,叫做精确逻辑回归。加州大学洛杉矶分校的idre提供了极好的分析示例。() 当我使用示例分析进行练习时,我会遇到knitr(+lyx)的错误 在网页中的语法列表中间,下面的语法会产生错误。Knitr似乎能很好地解释区块,但lyx产生了一个与pdf输出相关的错误 <<>>= ## model with female predictor only' m.female <- elrm(formula = admit/ntrials ~ female
<<>>=
## model with female predictor only'
m.female <- elrm(formula = admit/ntrials ~ female, interest = ~female, iter = 22000, dataset = cdat, burnIn = 2000)
@
同时,在lyx的错误框中,我看到以下消息:
\end{verbatim}
You need to provide a definition with \DeclareInputText or \DeclareInputMath before using this key
然而,区块中的上述语法在R终端中运行良好,没有任何问题。我应该为块添加knitr选项吗?那是什么?先谢谢你
钟华
require(knitr)
require(elrm)
dat <- read.table(text = "
female apcalc admit num
0 0 0 7
0 0 1 1
0 1 0 3
0 1 1 7
1 0 0 5
1 0 1 1
1 1 0 0
1 1 1 6",
header = TRUE)
dat
summary(dat)
dat <- dat[rep(1:nrow(dat), dat$num), -4]
summary(dat)
xtabs(~ female + apcalc, data=dat)
xtabs(~ female + admit, data=dat)
xtabs(~ apcalc + admit, data=dat)
xtabs(~ female + apcalc + admit, data=dat)
x <- xtabs(~admit + interaction(female, apcalc), data = dat)
x # view cross tabs
cdat <- data.frame(female = rep(1:0, 2), apcalc = rep(1:0, each = 2), admit = x[1, ], ntrials = colSums(x))
cdat # view collapsed data set
## model with female predictor only
m.female <- elrm(formula = admit/ntrials ~ female, interest = ~female, iter = 22000, dataset = cdat, burnIn = 2000)
####### the last syntax causes an error in lyx (+ knitr)
require(knitr)
需要(elrm)
dat问题来自进度条(特别是退格\b
)。两种可能的解决办法:
联系elrm
的作者,在elrm()
中请求一个参数progress=TRUE/FALSE
,以便您可以使用来抑制进度条,例如elrm(…,progress=FALSE)
李>
将对elrm()
的调用移动到单独的块中,并隐藏进度条的输出,例如
<<>>=
require(elrm)
dat <- read.table(text = "
female apcalc admit num
0 0 0 7
0 0 1 1
0 1 0 3
0 1 1 7
1 0 0 5
1 0 1 1
1 1 0 0
1 1 1 6",
header = TRUE)
dat
summary(dat)
dat <- dat[rep(1:nrow(dat), dat$num), -4]
summary(dat)
xtabs(~ female + apcalc, data=dat)
xtabs(~ female + admit, data=dat)
xtabs(~ apcalc + admit, data=dat)
xtabs(~ female + apcalc + admit, data=dat)
x <- xtabs(~admit + interaction(female, apcalc), data = dat)
x # view cross tabs
cdat <- data.frame(female = rep(1:0, 2), apcalc = rep(1:0, each = 2), admit = x[1, ], ntrials = colSums(x))
cdat # view collapsed data set
## model with female predictor only
@
<<results='hide'>>=
m.female <- elrm(formula = admit/ntrials ~ female, interest = ~female, iter = 22000, dataset = cdat, burnIn = 2000)
@
<<>>=
summary(m.female)
@
=
需要(elrm)
dat 1。如果可能的话,请给出一个简单的例子;2.同时发布库(knitr)的输出;sessionInfo()
。摘自Jong Hwa:R版本2.15.2(2012-10-26)平台:i686 pc linux gnu(32位)语言环境:[1]LC_CTYPE=ko_KR.UTF-8 LC_NUMERIC=C[3]LC_TIME=ko_KR.UTF-8 LC_COLLATE=ko_KR.UTF-8[5]LC_MONETARY=ko_KR.UTF-8 LC_MESSAGES=ko_KR.UTF-8[7]LC_PAPER=C_NAME=C_[9] LC_ADDRESS=C LC_TELEPHONE=C[11]LC_MEASUREMENT=ko_KR.UTF-8 LC_IDENTIFICATION=C感谢您的建议。当我遇到一些带有进度条的函数时,“results='hide''选项和将summary()从中分离出来非常有用。谢谢。
<<>>=
require(elrm)
dat <- read.table(text = "
female apcalc admit num
0 0 0 7
0 0 1 1
0 1 0 3
0 1 1 7
1 0 0 5
1 0 1 1
1 1 0 0
1 1 1 6",
header = TRUE)
dat
summary(dat)
dat <- dat[rep(1:nrow(dat), dat$num), -4]
summary(dat)
xtabs(~ female + apcalc, data=dat)
xtabs(~ female + admit, data=dat)
xtabs(~ apcalc + admit, data=dat)
xtabs(~ female + apcalc + admit, data=dat)
x <- xtabs(~admit + interaction(female, apcalc), data = dat)
x # view cross tabs
cdat <- data.frame(female = rep(1:0, 2), apcalc = rep(1:0, each = 2), admit = x[1, ], ntrials = colSums(x))
cdat # view collapsed data set
## model with female predictor only
@
<<results='hide'>>=
m.female <- elrm(formula = admit/ntrials ~ female, interest = ~female, iter = 22000, dataset = cdat, burnIn = 2000)
@
<<>>=
summary(m.female)
@