Dear R users:
I have run a logistic regression, used Gelman et al.'s car package to simulate the parameter estimates of that model, and have plotted the probability (using Gelman et al.'s invlogit() function) of the dependent variable being 1 given the value of a particular independent variable is at its mean. The plot has probabilities on the y-axis and the number (1-1000) of the simulation run on the x-axis. What I would like to do is to make the points that make up the 95% CI a different color from the points outside that CI. In other words, I would like the points from 1-24, and 976-1000 to be one color (the default color is fine), and the points 25-975 to be a different color. How would I do this? In case there is some confusion, here is example code, with only one predictor: set.seed(23) y<-rbinom(100,1,0.1) x<-rnorm(100) fit.1<-glm(y~x1, family=binomial(link="logit")) library(car) sim.fit.1<-sim(fit.1, 1000) #Simulate the parameter estimates of fit.1 1000 times plot(sort(invlogit(sim.fit.1$beta[,1]+sim.fit.2$beta[,2]*mean(x1)))) Thanks, Josip ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
> I have run a logistic regression, used Gelman et al.'s car package
onepredictor:
> to simulate the parameter estimates of that model, and have plotted > the probability (using Gelman et al.'s invlogit() function) of the > dependent variable being 1 given the value of a particular > independent variable is at its mean. The plot has probabilities on > the y-axis and the number (1-1000) of the simulation run on the x-axis. > > What I would like to do is to make the points that make up the 95% > CI a different color from the points outside that CI. In other > words, I would like the points from 1-24, and 976-1000 to be one > color (the default color is fine), and the points 25-975 to be a > different color. How would I do this? > > In case there is some confusion, here is example code, with only > > set.seed(23) > y<-rbinom(100,1,0.1) > x<-rnorm(100) > fit.1<-glm(y~x1, family=binomial(link="logit")) > library(car) > sim.fit.1<-sim(fit.1, 1000) #Simulate the parameter estimates of > fit.1 1000 times > plot(sort(invlogit(sim.fit.1$beta[,1]+sim.fit.2$beta[,2]*mean(x1)))) Running your code throws an error for me (can't find the 'sim' function - is it in another library?). I think this is what you are trying to achieve though plot(1:20, col=c(rep("red",5), rep("blue",10), rep("red",5))) Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by Josip Dasovic
Josip Dasovic <jjd9 <at> sfu.ca> writes:
> I have run a logistic regression, used Gelman et al.'s car package to >> simulate the parameter estimates of "car" is by John Fox. You meant "arm". > I would like the points from 1-24, and 976-1000 to be one color (the default color is > fine), and the points 25-975 to be a different color. Please check your code in a fresh window before you submit it. There were 7 errors in your code that I almost gave up, and I am sure other people had the same problem. Dieter library(arm) set.seed(23) y<-rbinom(100,1,0.1) x<-rnorm(100) fit.1<-glm(y~x, family=binomial(link="logit")) sim.fit.1<-sim(fit.1, 1000) plotdt =sort(invlogit(sim.fit.1$beta[,1]+sim.fit.1$beta[,2]*mean(x))) col = rep("black",length(plotdt)) col[1:24] = "red" plot(plotdt,col=col) ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by Josip Dasovic
Thank you, Dieter:
I apologize to all of those who tried to help and who couldn't get my code to work. I now know three things: 1) stop working at midnight; 2) always provide the correct package name (I meant arm(), not car(); and 3) when testing code make sure you do it in a new R window. Dieter has kindly provided a clean version of my code below with a resolution to my plotting requirements. Thank you, Josip ----- Original Message ----- From: "Dieter Menne" <[hidden email]> To: [hidden email] Sent: Wednesday, October 1, 2008 3:09:25 AM GMT -08:00 US/Canada Pacific Subject: Re: [R] Change color of plot points based on values of a variable Josip Dasovic <jjd9 <at> sfu.ca> writes: > I have run a logistic regression, used Gelman et al.'s car package to >> simulate the parameter estimates of "car" is by John Fox. You meant "arm". > I would like the points from 1-24, and 976-1000 to be one color (the default color is > fine), and the points 25-975 to be a different color. Please check your code in a fresh window before you submit it. There were 7 errors in your code that I almost gave up, and I am sure other people had the same problem. Dieter library(arm) set.seed(23) y<-rbinom(100,1,0.1) x<-rnorm(100) fit.1<-glm(y~x, family=binomial(link="logit")) sim.fit.1<-sim(fit.1, 1000) plotdt =sort(invlogit(sim.fit.1$beta[,1]+sim.fit.1$beta[,2]*mean(x))) col = rep("black",length(plotdt)) col[1:24] = "red" plot(plotdt,col=col) ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Free forum by Nabble | Edit this page |