I've got a data frame that looks like this.
a[,2:25]
UT1 UT2 UT3 UT4 UT5 UT6 UT7 UT8 UT9 UT10 UT11 UT12 TR1 TR2 TR3 TR4
3094 9 0 1 37 6 2 8 1 1 6 3 1 3 0 0 1
3095 4 0 0 10 17 6 7 1 5 3 1 12 2 0 0 1
3096 18 0 0 4 6 15 14 0 7 9 3 8 5 2 1 2
3097 11 0 0 7 5 15 10 2 4 7 16 17 7 3 0 0
3098 18 0 11 2 5 11 7 3 2 1 1 0 3 3 1 1
3099 25 0 6 11 17 3 10 1 1 3 9 2 2 1 1 2
3100 1 0 1 27 12 28 27 0 2 11 6 0 1 7 4 6
3101 0 0 1 40 0 17 13 1 0 3 3 0 1 3 3 1
3102 2 0 0 30 1 9 2 1 1 5 0 0 1 3 3 0
3103 3 0 0 11 4 7 5 2 4 0 1 0 5 4 0 0
3104 5 0 0 3 1 10 4 2 3 0 3 0 7 2 1 0
TR5 TR6 TR7 TR8 TR9 TR10 TR11 TR12
3094 1 0 15 3 0 0 42 1
3095 1 0 4 29 0 0 42 0
3096 0 0 3 22 0 0 3 0
3097 1 0 4 14 0 0 2 0
3098 0 0 1 10 0 0 1 0
3099 0 0 4 41 1 0 3 0
3100 0 0 10 21 0 0 17 0
3101 0 0 2 1 1 0 13 3
3102 0 0 2 4 0 0 10 3
3103 1 0 3 4 0 0 12 1
3104 0 0 1 2 0 0 8 0
The first column of my data it's time so I separated it using
tiempo<-a$Tiempo
tiempo
[1] 618.6 618.8 619.0 619.2 619.4 619.6 619.8 620.0 620.2 620.4 620.6
In order to plot each column as a fucntion of time and do lm I used reshape package
and lattice
. I'm not sure that's the best option but almost gets me what I want.
The code looks like this:
m<-melt(a[,2:25])
f<-m$variable
xyplot(m$value~tiempo | f, panel=function(x,y,...){
panel.xyplot(x,y,...)
panel.lmline(x,y, col=2, lty=2)
})
And the output is this graph
I don't get why it gives this error, I expect them to be non-NA, I don't understand why it is a problem. In fact, the first panel worked just fine.
When I change the panel.lmline(...) part this happens:
xyplot(m$value~tiempo | f, panel=function(x,y,...){
panel.xyplot(tiempo,m$value,...)
panel.lmline(tiempo,m$value, col=2, lty=2)
})
I get this lenght error but I think it's because each panel is using all datapoints from m when it should be using only 11.
The lm regression function I use is separated from the plotting and this doesn't mess with my statistical analysis but I'm trying to put everything together and won't be able to do it if I can't plot the data. I want visual information about the regression in order to be able to remove outliers if the Rsquared is too low or maybe not even consider that observation.
I hope I've made myself clear. Thank you very much
Edited with suggestions