##### Code for Basic linear Regression in R ### Importing data #Don't call your data 'data' - that word already has a meaning in R datum=read.csv(file.choose()) ### creates a data frame named datum from csv file ### check data was imported properly head(datum) ### column headers of data file plus first 6 rows of data ### Create a scatterplot of data #plot(Y~X,data=datum) ### creates a scatter plot between 'Y' and 'X' variables #Replace 'Y' and 'X' with whatever those columns are actually called plot(Mass~Protein,data=datum) ### scatterplot of data used in example ### Run regression using linear model #results=lm(Y~X,data=datum) ### runs a regression between 'Y' and 'X' #Creates and object called 'results' that hold results of analysis #Replace 'Y' and 'X' with whatever those columns are actually called results2=lm(Mass~Protein,data=datum) ### linear regression of example data summary(results) ### prints a summary of 'results' anova(results2) ### generate an anova table of regression ### Generate confidence intervals for parameters confint(results2) #calculates confidence limits on slope and intercept ### Plot regression line over data # requires either a lm object or values for a (intercept) and b (slope) abline(results2) ### plots results on the already created plot # Note must have run regression first # Note won't do anything if you haven't plotted data.