[R] Creating a loop with code from the mblm package

Bailey Hewitt bailster at hotmail.com
Sun Sep 4 03:43:45 CEST 2016


Hello,


I am a novice in coding in R and have come across an error I am having a hard time fixing. I am trying to use the mblm package to run a Theil-Sen linear model. The code for this function is:

mblm(Y ~ X, dataframe, repeated = FALSE)

My goal is to put this into a loop so that I can calculate the Theil-Sen slope of each column in my csv. file. The file contains one column of years (x value) and 3 columns of days of the year (y values). All columns are the same length. The code I currently have is:


read.csv("~/Documents/NH- Lake Mendota_SenSlope_Data2.csv", header = TRUE, sep = ",")

mydata= read.csv("~/Documents/NH- Lake Mendota_SenSlope_Data2.csv", header = TRUE, sep = ",")


attach(mydata)


install.packages("mblm")

library("mblm")


for (i in c(1:3)){

  x <- mblm(mydata[,i] ~ Year, mydata, repeated = FALSE)

  print(x)

}


Which gives me the following error:

Error in names(res$residuals) = as.character(1:length(res$residuals)) :

  'names' attribute [2] must be the same length as the vector [0]


Which I cannot seem to solve although as I understand it it is an error that I am causing in the mblm package. If anyone has any insight into how I could start fixing this that would be greatly appreciated!


Bailey


	[[alternative HTML version deleted]]



More information about the R-help mailing list