# # ############ Fun with ogives, binomials, & logistic regression. n <- 1000 x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = 1) plot(x,y, col = "lightblue") x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = .75) plot(x,y, col = "red") summary(x) summary(y) x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = .5) plot(x,y, col = "lightgreen") summary(x) summary(y) ############################################## for (i in 1:6){ x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = 1.5) plot(x,y, col = "yellow") Sys.sleep(.5) x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = 1.25) plot(x,y, col = "orange") Sys.sleep(.5) x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = 1) plot(x,y, col = "red") Sys.sleep(.5) x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = .75) plot(x,y, col = "darkgreen") Sys.sleep(.5) x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = .5) plot(x,y, col = "blue") Sys.sleep(.5) x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = .25) plot(x,y, col = "purple") Sys.sleep(.5) } ############################################################# x <- seq(-5, 5, length.out = n) y0 <- plogis(x, location = 0, scale = 1.5) y1 <- plogis(x, location = 0, scale = 1.25) y2 <- plogis(x, location = 0, scale = 1) y3 <- plogis(x, location = 0, scale = .75) y4 <- plogis(x, location = 0, scale = .5) y5 <- plogis(x, location = 0, scale = .25) plot(x,y0, col = "yellow", xlim = c(-5,5), ylim = c(0,1)) par(new=T) plot(x,y1, col = "orange", xlim = c(-5,5), ylim = c(0,1)) par(new=T) plot(x,y2, col = "red", xlim = c(-5,5), ylim = c(0,1)) par(new=T) plot(x,y3, col = "darkgreen", xlim = c(-5,5), ylim = c(0,1)) par(new=T) plot(x,y4, col = "blue", xlim = c(-5,5), ylim = c(0,1)) par(new=T) plot(x,y5, col = "purple", xlim = c(-5,5), ylim = c(0,1)) lines(x = c(-5,5), y = c(0,1.0), lwd = 2) ################################################################## n <- 200 z <- 5.0 my.colors <- c("darkgreen", "darkblue") v <- 1 x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = z) plot(x,y, col = my.colors[v], xlim = c(-5,5), ylim = c(0,1), xlab = "X", ylab = "Y", pch = ".") for (i in 1:24){ z <- z - 0.2 v <- sample(my.colors, 1) x <- seq(-5, 5, length.out = n) y <- plogis(x, location = 0, scale = z) par(new=T) plot(x,y, col = v, xlim = c(-5,5), ylim = c(0,1), xlab = "X", ylab = "Y", pch = ".") Sys.sleep(.5) } ####################################################### library(car) library(QuantPsyc) n <- 200 x <- seq(-5, 5, length.out = n) y1 <- plogis(x, location = 0, scale = 2.0) y2 <- plogis(x, location = 0, scale = 1.5) y3 <- plogis(x, location = 0, scale = 1.0) y4 <- plogis(x, location = 0, scale = 0.5) oldpar <- par(oma=c(0,0,3,0), mfrow=c(2,2)) plot(y1) plot(y2) plot(y3) plot(y4) par(oldpar) ### x1.1 <- x x1.2 <- y1*.6 + rnorm(200, 0, 1.0) x1.3 <- y1*.3 + rnorm(200, 0, 1.0) x1.4 <- y1*.8 + rnorm(200, 0, 0.2) x2.2 <- y2*.6 + rnorm(200, 0, 1.0) x2.3 <- y2*.3 + rnorm(200, 0, 1.0) x2.4 <- y2*.8 + rnorm(200, 0, 0.2) x3.2 <- y3*.6 + rnorm(200, 0, 1.0) x3.3 <- y3*.3 + rnorm(200, 0, 1.0) x3.4 <- y3*.8 + rnorm(200, 0, 0.2) x4.2 <- y4*.6 + rnorm(200, 0, 1.0) x4.3 <- y4*.3 + rnorm(200, 0, 1.0) x4.4 <- y4*.8 + rnorm(200, 0, 0.2) df <- data.frame(y1, x1.1, x1.2, x1.3, x1.4, y2, x2.2, x2.3, x2.4, y3, x3.2, x3.3, x3.4, y4, x4.2, x4.3, x4.4) subset.1 <- data.frame(y1, x1.1, x1.2, x1.3, x1.4) subset.2 <- data.frame(y2, x1.1, x2.2, x2.3, x2.4) subset.3 <- data.frame(y3, x1.1, x3.2, x3.3, x3.4) subset.4 <- data.frame(y4, x1.1, x4.2, x4.3, x4.4) rm(n, x, y1, x1.1, x1.2, x1.3, x1.4, y2, x2.2, x2.3, x2.4, y3, x3.2, x3.3, x3.4, y4, x4.2, x4.3, x4.4) summary(df) ls() ### cor(subset.1) lm.1 <- lm(y2 ~ x1.1 + x1.2 + x1.3 + x1.4, df) summary(lm.1) lm.beta(lm.1) cor(subset.2) lm.2 <- lm(y2 ~ x1.1 + x2.2 + x2.3 + x2.4, df) summary(lm.2) lm.beta(lm.2) cor(subset.3) lm.3 <- lm(y3 ~ x1.1 + x3.2 + x3.3 + x3.4, df) summary(lm.3) lm.beta(lm.3) cor(subset.4) lm.4 <- lm(y4 ~ x1.1 + x4.2 + x4.3 + x4.4, df) summary(lm.4) lm.beta(lm.4) ### oldpar <- par(oma=c(0,0,3,0), mfrow=c(2,2)) plot(lm.1) plot(lm.2) plot(lm.3) plot(lm.4) par(oldpar) ### glm.1 <- glm(y1 ~ x1.1 + x1.2 + x1.3 + x1.4, df, family = binomial(logit)) summary(glm.1) glm.2 <- glm(y2 ~ x1.1 + x2.2 + x2.3 + x2.4, df, family = binomial(logit)) summary(glm.2) glm.3 <- glm(y3 ~ x1.1 + x3.2 + x3.3 + x3.4, df, family = binomial(logit)) summary(glm.3) glm.4 <- glm(y4 ~ x1.1 + x4.2 + x4.3 + x4.4, df, family = binomial(logit)) summary(glm.4) ### oldpar <- par(oma=c(0,0,3,0), mfrow=c(2,2)) plot(df$y1, col = "darkblue", pch = 20) plot(df$y2, col = "lightblue1", pch = 20) plot(df$y3, col = "darkgreen", pch = 20) plot(df$y4, col = "lightgreen", pch = 20) par(oldpar) ls() rm(lm.1, lm.2, lm.3, lm.4, glm.1, glm.2, glm.3, glm.4) ls() ### scatterplotMatrix(subset.1) cor(subset.1) scatterplotMatrix(subset.2) cor(subset.2) scatterplotMatrix(subset.3) cor(subset.3) scatterplotMatrix(subset.4) cor(subset.4) rm(df, oldpar, subset.1, subset.2, subset.3, subset.4) # End; last updated: Apr. 18, 2011.