File: logit.R

package info (click to toggle)
car 2.1-4-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,800 kB
  • sloc: makefile: 1
file content (21 lines) | stat: -rw-r--r-- 744 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# logit transformation of proportion or percent (J. Fox)

# last modified 2012-06-24 by J. Fox

logit <- function(p, percents=range.p[2] > 1, adjust){
	range.p <- range(p, na.rm=TRUE)
	if (percents){
		if (range.p[1] < 0 || range.p[1] > 100) stop("p must be in the range 0 to 100")
		p <- p/100
		range.p <- range.p/100
	}
	else if (range.p[1] < 0 || range.p[1] > 1) stop("p must be in the range 0 to 1")
	a <-if (missing(adjust)) {
				if (isTRUE(all.equal(range.p[1], 0)) || isTRUE(all.equal(range.p[2], 1))) .025 else 0
			}
			else adjust
	if (missing(adjust) && a != 0) warning(paste("proportions remapped to (", a, ", ", 1-a, ")", sep=""))
	a <- 1 - 2*a
	log((0.50 + a*(p - 0.50))/(1 - (0.50 + a*(p - 0.50))))
}