## Example test=matrix(scan("http://civil.colorado.edu/~balajir/CVEN5454/R-sessions/sess5/Prob-11-77-data.txt"), ncol=2, byrow=T) Y = data[,2] X = data[,1] # fit a Kendall Thiel slope estimate.. # Chapter 10, pages 266-267 of Helsel and Hirsch library(mblm) zkt = mblm(Y ~ X) zlin = lsfit(X, Y) #Linear Regression plot(X, Y, xlab="Monthly energy usage (kilowatt hours)", ylab="Peak hour demand (kilowatts)") abline(zlin, col="red") abline(zkt, col="blue") #### Another example.. test=matrix(scan("http://civil.colorado.edu/~balajir/CVEN5454/R-sessions/sess5/Avg-SpringFlows-April1SWE-49-04.txt",skip=1), ncol=2, byrow=T) Y=test[,1] #Spring river flows X=test[,2] #April 1 Snow water equivalent zkt = mblm(Y ~ X) zlin = lsfit(X, Y) #Linear Regression plot(X, Y, xlab="Snow Water Equivalent)", ylab="Spring River flow") abline(zlin, col="red") abline(zkt, col="blue") # clearly the blue line based on Kendall-Thiel slope is robust to outlier ################ # Kendall slope is tested using the Kendall Tau # Chapter 8 pages 212-216 of Helsel and Hirsch cor.test(X,Y,method = c("kendall")) #Test on the Kendall's Tau statistic #Same as doing the significance on the slope of the # Kendall-Thiel line ## you can use argument's spearman or pearson to perform test on the ## Spearman's rank correlation or the traditional correlation (i.e. #Pearson's correlation) ####################### # You can also use the library Kendall library(Kendall) #install library Kendall help(Kendall) # read the help on the command Kendall zz = Kendall(X,Y) #computes the Kendall tau correlation zz$sl #gives you the p-value of the test. ################################################################# # Model Diagnostics # Use the commands in the file http://civil.colorado.edu/~balajir/CVEN5454/R-sessions/sess5/lsfit-diag-crossval-commands_elts.txt or in other files.. You can perform the diagnostics on the residuals from the Kendall-Thiel slope line and also from the Linear regression ########################################################################