Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #assign values to x and y axis
  2. xvalue<-c(2,3,5,7,11)
  3. yvalue<-c(4,7,9,11,15)
  4. #calculate regression and print slope, intercept and add graph
  5. #weighting: no weight
  6. reg<-lm(yvalue~xvalue)
  7. plot(xvalue,yvalue,main="no weighting") #plot values for graph
  8. abline(reg) #plot line on regression
  9. SLOPE=reg$coefficients[[2]]
  10. INTERCEPT=reg$coefficients[[1]]
  11. SLOPE
  12. INTERCEPT
  13. #weighting: 1/x
  14. reg1<-lm(yvalue~xvalue,weights=1/xvalue)
  15. plot(xvalue,yvalue,main="1/x") #plot values for graph
  16. abline(reg1) #plot line on regression
  17. SLOPE1=reg1$coefficients[[2]
  18. INTERCEPT1=reg1$coefficients[[1]]
  19. SLOPE1
  20. INTERCEPT1
  21. # weighting: 1/x^2
  22. reg2<-lm(yvalue~xvalue,weights=1/(xvalue^2))
  23. plot(xvalue,yvalue,main="1/x^2") #plot values for graph
  24. abline(reg2) #plot line on regression
  25. SLOPE2=reg2$coefficients[[2]]
  26. INTERCEPT2=reg2$coefficients[[1]]
  27. SLOPE2
  28. INTERCEPT2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement