###Lecture 5 - Evaluation of RSF's and RSPF's ### First import our model data set - used to create the model datum=read.csv(file.choose()) ### next import our test data set- used to test the model datum2=read.csv(file.choose()) ### make sure we imported the data correctly head(datum) head(datum2) # run the global model results=glm(Presence~PreyDens+Elevation,data=datum,family=binomial) summary(results) ## Low prey density isn't significant, so take it out results=glm(Presence~Medium+High+Elevation,data=datum,family=binomial) summary(results) ### Evaluate the meaning of the variables exp(1.7318711) #High prey density habitat is 5.65 times as likely to be used as low or absent prey density habitat exp(2.329074)/(1+exp(2.329074)) ###this is the absolute probability of a low prey density habitat being used at 0 elevation exp(2.329074+1.7318711)/(1+exp(2.329074+1.7318711)) ### this is absolute probability of a high prey density habitat being used at 0 elevaton 0.9112565/0.089 ### this is the odds of a low prey density habitat being used at zero elevation 0.9830592/0.017 ### this is the odds of a high prey density habitat being used at zero elevation 57.82/10.23 ### this is the odds ratio comparing high prey density habitat to low prey density habitat (elevation is irrelevant) exp(2.329074+1.7318711+100*-0.0040843)/(1+exp(2.329074+1.7318711-100*0.0040843)) ##probability of high prey density habitat being used at 100 meters elevation exp(2.329074+100*-0.0040843)/(1+exp(2.329074-100*0.0040843)) ## Probability of a low prey density habitat being used at 100 meters elevation 0.9747/0.026 ### odds of a high prey density habitat being used at 100 meter elevation 0.8722/0.13 ### odds of a low prey density habitat being used at 100 meter elevation 37.48846/6.709 ### this is the odds ratio comparing high prey density habitat to low prey density habitat (elevation is irrelevant) exp(-1.3466897) ### Medium prey density is 0.26 times as likely to be used as low prey density 1/0.26 ### low prey density is 3.84 times as likely to be used as medium prey density exp(-0.004) ### For each 1 meter increase in elevaton, you are 0.996 times as likely to encounter the animal exp(-0.004*100) ### for each 100 meter increase in elevation, you are 0.67 times as likely to encounter the animal exp(-0.004*1000) #### you are 0.018 times as likely to encounter the animal at highest elevation compared to lowest elevation 1/0.01831564 ### you are 54.5 times as likely to encounter tha animal at lowest elevation relative to highest elevation library(ROCR) ### load the ROCR package ### Create a vector called "testing" that is the predicted probability of use ### as determined by the model testing=exp(2.3290743-1.3477897*datum$Medium+1.731*datum$High-0.0040843*datum$Elevation)/ (1+exp(2.3290743-1.3477897*datum$Medium+1.731*datum$High-0.0040843*datum$Elevation)) ### Compare the predicted probability with the true probability head(testing) head(datum$Proportion) ### Create an object that compares predicted probability with observed presence/absence pred=prediction(testing,datum$Presence) ### Calculate the true positive rate and the false positive rate, and plot the ROC curve perf=performance(pred,"tpr","fpr") plot(perf) ### Calculate the Area under the curve perf=performance(pred,"auc") perf #repeat the analysis for the 'test' data head(datum2) ### Create a vector called "testing" that is the predicted probability of use ### as determined by the model testing=exp(2.3290743-1.3477897*datum2$Medium+1.731*datum2$High-0.0040843*datum2$Elevation)/ (1+exp(2.3290743-1.3477897*datum2$Medium+1.731*datum2$High-0.0040843*datum2$Elevation)) ### Create an object that compares predicted probability with observed presence/absence pred=prediction(testing,datum2$Presence) ### Calculate the Area under the curve perf=performance(pred,"auc") perf