#***************************************************************************** # Script: fitGLM2Data.r # # Description: This script uses the glm and step functions to calculate the best # fit generalized linear model to the users data using the AIC. The script fits a # logistical or 'logit' model. Before the script is run the variables theTable and # theFormula must be set. # # Written by: Vickie Backus # # Date: October 3, 2008 #****************************************************************************** #load libraries library(foreign) library(stats) #read data file #dat <- read.dbf("D:/pythonScripts/testData/2001_2004_10m_pres_abs.dbf", as.is=FALSE) dat <- read.table(theTable, header=TRUE, sep = " ", as.is=FALSE) #create glm #genLinModel <- glm(CIAR ~ ROADDIST + TRAILDIST + ELEV + SLOPE + COSASP + SINASP + SOLRAD + BURN + TREE + BAND1 + BAND2 + BAND3 + BAND4 + BAND5 + BAND7,family=binomial(link="logit"), data = dat, na.action=na.exclude, control=glm.control(maxit=50)) genLinModel <- glm(theFormula,family=binomial(link="logit"), data = dat, na.action=na.exclude, control=glm.control(maxit=50)) #use AIC step function to select bestFitGLM <-step(genLinModel, steps=500)