Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #assign values to x and y axis
- xvalue<-c(2,3,5,7,11)
- yvalue<-c(4,7,9,11,15)
- #calculate regression and print slope, intercept and add graph
- #weighting: no weight
- reg<-lm(yvalue~xvalue)
- plot(xvalue,yvalue,main="no weighting") #plot values for graph
- abline(reg) #plot line on regression
- SLOPE=reg$coefficients[[2]]
- INTERCEPT=reg$coefficients[[1]]
- SLOPE
- INTERCEPT
- #weighting: 1/x
- reg1<-lm(yvalue~xvalue,weights=1/xvalue)
- plot(xvalue,yvalue,main="1/x") #plot values for graph
- abline(reg1) #plot line on regression
- SLOPE1=reg1$coefficients[[2]
- INTERCEPT1=reg1$coefficients[[1]]
- SLOPE1
- INTERCEPT1
- # weighting: 1/x^2
- reg2<-lm(yvalue~xvalue,weights=1/(xvalue^2))
- plot(xvalue,yvalue,main="1/x^2") #plot values for graph
- abline(reg2) #plot line on regression
- SLOPE2=reg2$coefficients[[2]]
- INTERCEPT2=reg2$coefficients[[1]]
- SLOPE2
- INTERCEPT2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement