### General Code for running a regression in R ### import the data datum=read.csv(file.choose()) #imports data # Note that the data file must be saved as a csv file # The imported data object will be called 'datum' ### Make sure the data imported correctly head(datum) #displays the column headings of data plus first 6 rows ### Plot Data plot(Y~X,data=datum) #plots the data. Be sure to replace 'Y' with the response variable ### and 'X' with the x-variable from your excel file. ### Run regression analysis results=lm(Y~X,data=datum) #runs a regression # Note that R won't seem to do anything, instead it is creating a new # object called 'results' that contains the important information # 'Y' is the response in your excel file. BE SURE TO CHANGE THE NAME # 'X' is the x-variable in your excel file. BE SURE TO CHANGE THE NAME ### Get the information from the 'results' object summary(results) # gives output. ###Example output #Call: #lm(formula = Understory ~ Canopy, data = datum) # #Residuals: # Min 1Q Median 3Q Max #-18.203 -3.203 1.087 3.419 13.189 # #Coefficients: # Estimate Std. Error t value Pr(>|t|) #(Intercept) 51.5253 2.5345 20.329 < 2e-16 *** ###Estimate is Beta0 #Canopy -1.1576 0.1518 -7.626 9.27e-10 *** ### Estmate is Beta1 and p-value for test of H0: slope=0 #--- #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # #Residual standard error: 6.676 on 47 degrees of freedom #This is the estimate of sigma #Multiple R-squared: 0.553, Adjusted R-squared: 0.5435 #F-statistic: 58.15 on 1 and 47 DF, p-value: 9.271e-10 ###Plot line on plot abline(results) #where 'results' is an lm object ### Get information from ANOVA table anova(results) # gives similar results in ANOVA table format