As you may know, there is a technique, called exact logistic regression. The idre from UCLA provides excellent analysis example. ( http://www.ats.ucla.edu/stat/r/dae/exlogit.htm ) When I exercise with the example analysis, I face an error for knitr (+ lyx).
In the middle of a list of syntax in the Webpage, the syntax below produces an error. Knitr seems to interpret the chunk well, but lyx produces an error related to pdf output.
<<>>=
## model with female predictor only'
m.female <- elrm(formula = admit/ntrials ~ female, interest = ~female, iter = 22000, dataset = cdat, burnIn = 2000)
@
lyx produces an error message like this:
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
Meanwhile, In the error box of lyx, I see the message below:
\end{verbatim}
You need to provide a definition with \DeclareInputText or \DeclareInputMath before using this key
The syntax above in the chunk, however, works well in R terminal without any problem. Should I add an knitr option for the chunk? Then, what is it? Thank you in advance.
Jong-Hwa
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)
The problem came from the progress bar (specifically the backspace \\b
). Two possible solutions:
elrm
and request an argument progress = TRUE/FALSE
in elrm()
so that you can suppress the progress bar with, eg, elrm(..., progress = FALSE)
; Move the call to elrm()
to a separate chunk and hide the output of the progress bar, eg,
<<>>= 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) @
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.