Is there are a way to perform OLS only on selected records/years from my feature layer? I am trying to analyze species occurrence over time. I have a "Year" field that denotes different years worth of data. I am using ArcGIS 10.1 SP1 on Win7 x64
Thanks!
Hi Robert,If you have a lot of years in your data you may want to consider using Python:import arcpy, os
from arcpy import env
ws = "c:/Folder/yourFileGeodatabase.gdb" # change this
fcName = "yourFC" # change this
# fields in input FC
fldYear = "Year"
fldID = "yourUniqueIDfieldName" # change this
fldDepVar = "Rainfall" # change this: Dependent_Variable
fldExpVar = "Temperature;..." # change this: Explanatory_Variables
Coefficient_Output_Table = "olsCoefTab"
Diagnostic_Output_Table = "olsDiagTab"
olsReport = "c:/Folder/OLSreport"
# set workspace
env.workspace = ws
# create unique set of values in Year field
fc = ws + os.sep + fcName
values = [row[0] for row in arcpy.da.SearchCursor(fc, (fldYear))]
uniqueYears = set(values)
# loop through the values
for year in uniqueYears:
# create feature layer for year
qDef = "{0} = {1}".format(fldYear,year)
fcFL = "Year_{0}".format(year)
arcpy.MakeFeatureLayer_management(fc,fcFL,qDef,"#")
# perform OLS on feasturelayer
fcOLS = "OLS_{0}".format(year)
ols = arcpy.OrdinaryLeastSquares_stats(fcFL, fldID, fcOLS, fldDepVar, fldExpVar, "{0}{1}".format(Coefficient_Output_Table,year),"{0}{1}".format(Diagnostic_Output_Table,year),"{0}{1}.pdf".format(olsReport,year))
This code will make a unique list of years, and then loop through the years, create a featurelayer based on that year and perform an OLS on it. The result for the year 2000 will be:
- OLS_2000 (OLS featureclass)
- olsCoefTab2000 (Coefficient Output Table)
- olsDiagTab2000 (Diagnostic Output Table)
- OLSreport2000.pdf (OLS report as PDF)
I haven't tested the code. See for more explanation on how to define the required variables for OLS:Ordinary Least Squares (OLS) (Spatial Statistics) Kind regards,Xander