您可能知道,有一种技术,称为精确逻辑回归。来自 UCLA 的 idre 提供了出色的分析示例。( http://www.ats.ucla.edu/stat/r/dae/exlogit.htm ) 当我使用示例分析进行练习时,我遇到了 knitr (+ lyx) 的错误。
在网页中的语法列表中间,下面的语法会产生错误。Knitr 似乎可以很好地解释该块,但 lyx 会产生与 pdf 输出相关的错误。
<<>>=
## model with female predictor only'
m.female <- elrm(formula = admit/ntrials ~ female, interest = ~female, iter = 22000, dataset = cdat, burnIn = 2000)
@
lyx 会产生如下错误消息:
Running: pdflatex "logistics.regression.tex" > /dev/null
11:50:28.071: Error while exporting format: pdf2../../../src/support/Systemcall.cpp(270): Systemcall: 'pdflatex "logistics.regression.tex"' finished with exit code 1
同时,在 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)