1 ## PsN R script for plotting results of llp
6 ## autogenerated code begins
7 ## we can set other things, like colours, line types, layout, etc here if we wish
9 ofv <- 3.843 # set this to the desired llp ofv tolerance
10 ci.lines <- TRUE # do we want grey broken lines for outer CI limits?
11 dofv.line <- TRUE # do we want grey broken line for final model parameter estimate?
12 hline <- TRUE # do we want grey broken line for desired llp ofv tolerance?
14 ## autogenerated code ends
17 llp.data <- read.csv("llplog1.csv")
19 ## get number of parameters
20 n <- (length(colnames(llp.data)) - 1) / 2
31 ## create data frame for each parameter
32 p1 <- c(llp.data[i],llp.data[i+1])
33 p1 <- as.data.frame(p1)
34 p1 <- p1[!(apply(is.na(p1),1,any)),]
36 parmlabel <- names(p1)[1]
38 names(p1) <- c("Parameter", "dOFV")
40 ## 3rd order polynomial
41 fit <- lm(p1$dOFV~p1$Parameter+I(p1$Parameter^2)+I(p1$Parameter^3))
42 ## 4th order polynomial
43 fit2 <- lm(p1$dOFV~p1$Parameter+I(p1$Parameter^2)+I(p1$Parameter^3)+I(p1$Parameter^4))
45 if (max(p1$Parameter) > 0) {
46 pmn <- min(p1$Parameter) - (max(p1$Parameter)/10)
47 pmx <- max(p1$Parameter) + (max(p1$Parameter)/10)
49 pmn <- min(p1$Parameter) + (max(p1$Parameter)/10)
50 pmx <- max(p1$Parameter) - (max(p1$Parameter)/10)
63 ip <- 0 ## inflections - down is bad
69 ## try third order first
71 pfit <- as.vector( fit$coefficients[1] +
72 (fit$coefficients[2] * pcur) +
73 (fit$coefficients[3] * (pcur^2)) +
74 (fit$coefficients[4] * (pcur^3))
76 addrow <- c(pcur, pfit)
77 mat.txt <- c(mat.txt, addrow)
86 if ((pfit <= ofv) && (pprev >= ofv)) {
87 if (abs(pfit-ofv) <= abs(pprev-ofv)) {
93 ## we have a number for int1
98 if ((pfit >= ofv) && (pprev <= ofv)) {
99 if (abs(pfit-ofv) <= abs(pprev-ofv)) {
105 ## we have a number for int2
109 ## have we reached the nadir of the parabola?
113 if ((ip == 1) && (pfit < pprev)) {
124 ## try fourth order fit
139 pfit <- as.vector( fit2$coefficients[1] +
140 (fit2$coefficients[2] * pcur) +
141 (fit2$coefficients[3] * (pcur^2)) +
142 (fit2$coefficients[4] * (pcur^3)) +
143 (fit2$coefficients[5] * (pcur^4))
145 addrow <- c(pcur, pfit)
146 mat.txt <- c(mat.txt, addrow)
155 if ((pfit <= ofv) && (pprev >= ofv)) {
156 if (abs(pfit-ofv) <= abs(pprev-ofv)) {
162 ## we have a number for int1
167 if ((pfit >= ofv) && (pprev <= ofv)) {
168 if (abs(pfit-ofv) <= abs(pprev-ofv)) {
174 ## we have a number for int2
178 ## have we reached the nadir of the parabola?
182 if ((ip == 1) && (pfit < pprev)) {
193 mdat <- matrix(mat.txt, nrow = pno, ncol=2, byrow=TRUE,
194 dimnames = list(c(), c("Parameter", "dOFV")))
196 llp.parabola <- as.data.frame(mdat)
198 postscript(file=paste("llp.", parmlabel, ".ps", sep=""), paper="a4",
199 title=paste("Log-likelihood profile - ", parmlabel, sep=""),
202 plot (llp.parabola$Parameter, llp.parabola$dOFV,
204 # ylim=c(0,max(data.main$DV)),
207 main=paste("Log-likelihood profile - ", parmlabel, sep="")
208 #sub="Binning tolerance: 0.25, occasion: 0"
211 points(p1$Parameter, p1$dOFV, col="red", pch=21)
212 abline(v=pint1, col="red", lty=2)
213 abline(v=pint2, col="red", lty=2)
214 text(pint1, ofv, labels=signif(pint1, digits = 3), cex = .8, adj = c(0,0), pos='4')
215 text(pint2, ofv, labels=signif(pint2, digits = 3), cex = .8, adj = c(0,0), pos='4')
216 text(p1[1,1], 0, labels=signif(p1[1,1], digits = 3), cex = .8, adj = c(0,0), pos='3')
219 abline(v=min(p1$Parameter), col="gray", lty=2)
220 abline(v=max(p1$Parameter), col="gray", lty=2)
224 abline(v=p1[1,1], col="gray", lty=2)
228 abline(h=ofv, col="gray", lty=2)