R: [R] lines and glm
Guazzetti Stefano
Stefano.Guazzetti at ausl.re.it
Thu Apr 8 14:00:23 CEST 2004
You probably mean something like:
ti <- 1:1000
e1 <- rnorm(1000)
e2 <- rnorm(1000)
x <- 0.0001*ti+e1
y2 <- -2+x+e2
y <- ifelse(y2>0,1,0)
plot(x, y, pch = 16, col = "darkblue",
main = expression(paste("Scatter diagram of ",
italic(y[t]), "against ", italic(x[t]))),
xlab = expression(italic(x[t])),
ylab = expression(italic(y[t])))
model<-glm(y ~ x, family = binomial)
predProbs<-predict(model,data.frame(x=seq(min(x), max(x), length.out=100)), type="response")
lines(seq(min(x), max(x), length.out=100), predProbs, col=2, lwd=2)
Note also that it is not a good idea to name "t" a R object, since the name is reserved for a special function.
Stefano
> -----Messaggio originale-----
> Da: Jan P. Smit [mailto:jps at srres.com]
> Inviato: giovedì 8 aprile 2004 13.38
> A: r-help at stat.math.ethz.ch
> Oggetto: [R] lines and glm
>
>
> Dear R-helpers,
>
> I'm a beginner using R 1.8.1 on Windows 2000. I'm trying to
> replicate some
> examples in Franses' & Paap's Quantitative Models in
> Marketing Research.
>
> > t <- 1:1000
> > e1 <- rnorm(1000)
> > e2 <- rnorm(1000)
> > x <- 0.0001*t+e1
> > y2 <- -2+x+e2
> > y <- ifelse(y2>0,1,0)
> >
> > plot(x, y, pch = 16, col = "darkblue",
> + main = expression(paste("Scatter diagram of ", italic(y[t]), "
> against ",
> + italic(x[t]))),
> + xlab = expression(italic(x[t])),
> + ylab = expression(italic(y[t])))
> > lines(glm(y ~ x, family = binomial))
>
> Error in xy.coords(x, y) : x and y lengths differ
>
> However,
>
> > length(x)
> [1] 1000
> > length(y)
> [1] 1000
>
> as it should be.
>
> I'm sure I must be missing something obvious, but it is not
> clear to me
> (after reading the Introduction, FAQ and the relevant
> functions help pages)
> what.
>
> Sincerely,
>
> Jan Smit
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list