Skip to content

Instantly share code, notes, and snippets.

@jtrecenti
Created June 27, 2014 15:46
Show Gist options
  • Save jtrecenti/5bdea5780df47d0116d7 to your computer and use it in GitHub Desktop.
Save jtrecenti/5bdea5780df47d0116d7 to your computer and use it in GitHub Desktop.
exemplo onde y é explicado por x + z mas não por z
x <- rnorm(1000)
z <- runif(1000)
d <- data.frame(x = x, z = z, y= x + z/10 + rnorm(1000, sd=.001))
cor(d)
summary(lm(y~x+z, data=d))
summary(lm(y~x, data=d))
summary(lm(y~z, data=d))
@jtrecenti
Copy link
Author

Outro exemplo: aqui eu gero o y como uma função determinística de x, z1, z2, z3, z4, z5.
Parece que a função glm dá bug, mas a função step acaba tirando as variáveis z...

x <- rnorm(1000)
z1 <- runif(1000)
z2 <- runif(1000)
z3 <- runif(1000)
z4 <- runif(1000)
z5 <- runif(1000)
z <-runif(1000)/1000
y=ifelse(x + (z1+z2+z3+z4+z5)/1000 > .2, 1, 0)
d <- data.frame(x=x, z=z, z1=z1, z2=z2, z3=z3, z4=z4, z5=z5, y=y)
cor(d)
summary(glm(y~., data=d, family=binomial))
step(glm(y~., data=d, family=binomial))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment