Advertisement
Guest User

Untitled

a guest
May 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.61 KB | None | 0 0
  1. #Passo 1: dados
  2. x <- c(10, 20, 30)
  3. y <- c(20, 25, 45)
  4.  
  5. x2 <- x^2
  6. #Passo 2: plotando os dados
  7. plot(y, type="l", lwd=2, col="blue",
  8.    xlab="Obs.", ylim=c(0,50))
  9. lines(x, type="l", lwd=2, col="red",
  10.      xlab="Obs.")
  11. lines(x, type="p", lwd=2, col="black")
  12. lines(y, type="p", lwd=2, col="black")
  13. legend("topleft", c("x", "y"), lwd=2, col=c("blue", "red"))
  14.  
  15. plot(x, y, type="p", lwd=2, col="black", main="Scatter Plot",
  16.      pch=16, xlim=c(0,50), ylim=c(0, 50))
  17. abline(lm(y~x), lwd=2, col="red")
  18.  
  19.  
  20. #Passo 3: estimando y = b1 + b2x
  21. mod <- lm(y~x)
  22. summary(mod)
  23. yhay <- fitted.values(mod)
  24. sum((y - yhay)^2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement