Skip to content

Instantly share code, notes, and snippets.

@mbk0asis
Last active November 9, 2017 09:02
Show Gist options
  • Save mbk0asis/ecba8a1c62f866b62d54d5467eb06d1f to your computer and use it in GitHub Desktop.
Save mbk0asis/ecba8a1c62f866b62d54d5467eb06d1f to your computer and use it in GitHub Desktop.
# drawing a scatter plot and regression line
# draw a scatter plot
library(LSD)
heatscatter( dta$a, dta$b, cor = TRUE, method = "pearson" )
# add regression line
abline( lm( dta$b ~ dta$a ) ) # switch columns (a<-->b)
# FYI of linear modeling
lmodel <- lm( dta$b ~ dta$a ) # linear modeling
summary( lmodel ) # just looking at the results
coef( lmodel )
intcp <- coef(lmodel)[1] # extract intercept value
slp <- coef(lmodel)[2] # extract slope value
abline(intcp, slp) # draw regression line using slope and intercept values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment