#Ponderosa Pine Lab R Script #Initialize variables #These following steps allow us to create objects in R that correspond to our data variables. Recall that these are case sensitive and must be entered EXACTLY as we define them during analysis. Data MUST be in a comma separated file format (cvs) trees<-read.csv(file.choose(), header=TRUE) el <- trees[,2] # [row, column] In this case, we are assigning the second column of the file (elevation) to the object "el" (elevation) el <-as.numeric(el) # this tells R the variable is numeric DBH <- trees[,3] DBH <-as.numeric(DBH) Height <- trees[,4] Height <-as.numeric(Height) DBH_nearest <- trees[,5] DBH_nearest <- as.numeric(DBH_nearest) Height_nearest <- trees[,6] Height_nearest <-as.numeric(Height_nearest) rings <- trees[,7] rings <-as.numeric(rings) rate <- trees[,8] rate <-as.numeric(rate) density <- trees[,9] density <-as.numeric(density) #Descriptive Statistics #Substitute x with the variable of interest mean(x, na.rm= TRUE) # One type of average (Sum of all values/number of values) var(x, na.rm= TRUE) #The variance of a sample is a non-negative number which gives an idea of how widely spread the values of sample are likely to be; the larger the variance, the more scattered the observations around the mean. sd(x, na.rm= TRUE) #68% of the data lies within one standard deviation on either side of the mean, if our data is normally distributed. It's another measure of data dispersion. The steps are: (1) Compute the mean for the data set. (2)Compute the deviation by subtracting the mean from each value. (3)Square each individual deviation.(4) Add up the squared deviations.(5)Divide by one less than the sample size.(6)Take the square root. se<-function(x) {sqrt(var(x)/length(x))} #leave x as is in this line of code. a <-na.omit (variable)#Put the variable or object name in parentheses here se(a) hist(x) #6) Run the program. ÊHighlight all the code in your document and the click Edit -> Execute. The program will bring up a browser window for you to select the excel file where you saved the file. Ê #Scatter Plot plot(x,y) #This will show a plot of x vs y (predictor vs. response variable) #Simple Linear Regression model <- lm (y~x) #In this line of code we create the model model #This runs the model summary (model) #This creates our data output #Multiple Linear Regression model <- lm(rate ~ a + b + c) #Include here predictor variables of interest as a function of a response variable model summary(model) #Paired T-test t.test(A,B, paired=TRUE) #A and B are the paired variables of interest #Unpaired T-test t.test (A,B, paired= FALSE) # In this case, the variables are un-paired