[R] Plot binomial regression line
Uwe Ligges
ligges at statistik.tu-dortmund.de
Thu May 26 12:09:02 CEST 2011
On 26.05.2011 10:45, Jörgen Svan wrote:
> Dear all,
>
> I am quite new with R and I have a problem with plotting a binomial
> regression line in a plot.
>
> This is what I type in:
>> model<-glm(Para~Size,binomial)
>> par(mfrow=c(1,1))
>> xv<-seq(3.2,4.5,0.01)
>> yv<-predict(model,list(area=xv),type="response")
>> plot(Size,Para)
>> lines(xv,yv)
Several things I'd improve, hence the whole code:
dat <- read.table("clipboard", header=TRUE)
dat$Para <- factor(dat$Para)
model <- glm(Para ~ Size, data=dat, family="binomial")
xv <- seq(3.2,4.5,0.01)
yv <- predict(model, newdata=data.frame(Size=xv), type="response")
with(dat, plot(Size, as.integer(Para)-1))
lines(xv, yv)
Best,
Uwe Ligges
> The error message that I get is:
>
>> Error in xy.coords(x, y) : 'x' and 'y' lengths differ
>
> My txt-file is attached. Could someone please help me to find out what I did
> wrong.
>
> Thank you on beforehand,
> Jörgen
>
>
> PerBinom.txt
>
>
> Para Size
> 1 4.464285714
> 1 4.196428571
> 1 4.151785714
> 1 4.151785714
> 1 3.973214286
> 1 4.285714286
> 1 4.0625
> 1 4.241071429
> 1 4.0625
> 1 4.017857143
> 1 4.0625
> 1 4.017857143
> 1 4.241071429
> 1 4.151785714
> 1 4.0625
> 1 4.285714286
> 1 4.196428571
> 1 4.107142857
> 1 4.0625
> 1 4.330357143
> 1 4.375
> 1 4.196428571
> 1 4.196428571
> 1 3.928571429
> 1 4.0625
> 1 4.0625
> 1 4.107142857
> 1 4.196428571
> 1 3.928571429
> 1 4.151785714
> 1 3.705357143
> 1 3.75
> 1 4.107142857
> 1 3.839285714
> 1 3.616071429
> 1 4.0625
> 1 3.75
> 1 4.017857143
> 1 3.571428571
> 1 4.151785714
> 1 3.883928571
> 1 3.705357143
> 1 4.017857143
> 1 4.0625
> 1 4.0625
> 1 4.196428571
> 1 3.839285714
> 1 4.107142857
> 1 4.017857143
> 1 3.839285714
> 1 3.526785714
> 1 4.196428571
> 1 4.017857143
> 1 3.883928571
> 1 4.0625
> 1 4.107142857
> 1 4.285714286
> 1 3.928571429
> 1 3.794642857
> 1 4.107142857
> 1 4.107142857
> 1 3.839285714
> 1 4.241071429
> 1 4.285714286
> 1 4.375
> 0 4.115044248
> 0 3.495575221
> 0 4.203539823
> 0 3.982300885
> 0 4.026548673
> 0 4.07079646
> 0 3.805309735
> 0 4.07079646
> 0 3.982300885
> 0 4.247787611
> 0 4.203539823
> 0 3.982300885
> 0 3.849557522
> 0 4.115044248
> 0 3.849557522
> 0 4.07079646
> 0 4.203539823
> 0 3.849557522
> 0 4.247787611
> 0 4.026548673
> 0 4.07079646
> 0 4.203539823
> 0 4.026548673
> 0 3.982300885
> 0 4.026548673
> 0 3.584070796
> 0 4.026548673
> 0 3.982300885
> 0 3.761061947
> 0 3.230088496
> 0 3.495575221
> 0 3.982300885
> 0 3.938053097
> 0 3.849557522
> 0 3.982300885
> 0 3.849557522
> 0 4.026548673
> 0 3.938053097
> 0 4.159292035
> 0 3.849557522
> 0 4.026548673
> 0 3.672566372
> 0 4.159292035
> 0 3.761061947
> 0 4.247787611
> 0 4.115044248
> 0 3.539823009
> 0 3.89380531
> 0 4.115044248
> 0 3.849557522
> 0 4.115044248
> 0 4.115044248
> 0 4.07079646
> 0 3.584070796
> 0 3.407079646
> 0 4.203539823
>
>
>
> ______________________________________________
> R-help at r-project.org 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.
More information about the R-help
mailing list