Plotting splines and data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Plotting splines and data
The files embedded below are intended to produce and plot splines like those
produced by the S+ function asr.pvsplot(), but with a confidence band around
each spline, and with fitted values for individual observations superimposed
as a scatter of points. The idea is not to plot the raw data, but values
showing how the data are scattered round the model after spatial adjustment,
elimination of row and column effects, etc. The splines and the confidence
bands look okay, but the individual observations are incorrect, for various
reasons.
Firstly, in the lines of the .pin file that obtain the fitted value for each
observation, the spline component of the model is not included. A linear
term can be used with the appropriate X value as a coefficient to get the
estimate for a particular data point, but there doesn't seem to be any way
to do the equivalent thing with spline terms. Is there any way round this?
Second question. I have included the term COL.ROW in the linear model with
the intention of getting estimates for the deviations of individual data
points from the rest of the model. I expected that the residual values
would then be zero. But that isn't what's happened: the COL.ROW values are
near zero, and the residual values are still there. An alternative would
be to use the residual values themselves, but ASREML doesn't seem to allow
this: if you try to refer to the residual values in the .pin file, it tells
you that your coefficient number is too large.
The remaining questions concern S+ rather than ASREML itself, but I'm hoping
that someone out there can help me.
The S+ function asr.pvsplot2() that I've defined has two arguments, xvar and
group, which are supposed to be used to refer to columns of the matrix df2.
But when I set xvar=ESTAB and group=Variety I get an error message, and I'm
having to refer to these columns directly within the function. How can I
get these columns specified by arguments?
How can I get different plotting symbols used for the points at each level
of variety?
Why does only the second call of the list() function produce any output?
Nick Galwey
______________________
file 96wh14.as
Restricted branching lupin - density trials
Variety 3 !A
TDENS 6
Rep 5
PLOT 90
COL 2
ROW 54
THA
ESTAB
C:\DOCS\Dracup_M\96WH14\96WH14.dat !skip 1 !maxit 20 !spline 6
THA ~ mu mv c(Variety) ESTAB c(Variety).ESTAB,
!r spl(ESTAB) Variety.spl(ESTAB) COL.ROW
1 2
ROW ROW AR .1 .1
COL COL IDEN
___________________________________
file 96wh14.pin
# A is vector of the 6 knot points
# B is vector of the spline for Tallerack
C = C + B # Add Merrit curve to Tallerack curve
D = D + B # Add 85SO46-37 curve to Tallerack curve
Group1 C 1 A 3 A 4 26 # Spline for Merrit
Group2 D 2 A 3 A 5 26 # Spline for 85SO46-37
Group3 B 3 A 26 # Spline for Tallerack
# Individual data points
# Variety
ESTAB
Estp1 1 * 93.2 3 * 93.2 4 26 43 # MERRIT
93.2
Estp2 2 * 100 3 * 100 5 26 44 # 85SO46-37
100
Estp3 3 * 105.4 26 45 # TALLERACK
105.4
Estp4 2 * 116.4 3 * 116.4 5 26 46 # 85SO46-37
116.4
Estp5 1 * 85 3 * 85 4 26 47 # MERRIT
85
Estp6 3 * 118.8 26 48 # TALLERACK
118.8
Estp7 3 * 120.6 26 49 # TALLERACK
120.6
Estp8 3 * 42.8 26 50 # TALLERACK
42.8
Estp9 1 * 117.4 3 * 117.4 4 26 51 # MERRIT
117.4
Estp10 2 * 64.8 3 * 64.8 5 26 52 # 85SO46-37
64.8
Estp11 1 * 56.2 3 * 56.2 4 26 53 # MERRIT
56.2
Estp12 3 * 52.2 26 54 # TALLERACK
52.2
Estp13 3 * 45.2 26 55 # TALLERACK
45.2
Estp14 1 * 50.4 3 * 50.4 4 26 56 # MERRIT
50.4
Estp15 1 * 60.6 3 * 60.6 4 26 57 # MERRIT
60.6
Estp16 3 * 25 26 58 # TALLERACK
25
Estp17 2 * 26.8 3 * 26.8 5 26 59 # 85SO46-37
26.8
Estp18 1 * 24.2 3 * 24.2 4 26 60 # MERRIT
24.2
Estp19 1 * 55.6 3 * 55.6 4 26 61 # MERRIT
55.6
Estp20 3 * 65.2 26 62 # TALLERACK
65.2
Estp21 2 * 50.2 3 * 50.2 5 26 63 # 85SO46-37
50.2
Estp22 2 * 24 3 * 24 5 26 64 # 85SO46-37
24
Estp23 3 * 21.8 26 65 # TALLERACK
21.8
Estp24 1 * 26.8 3 * 26.8 4 26 66 # MERRIT
26.8
Estp25 1 * 56.2 3 * 56.2 4 26 67 # MERRIT
56.2
Estp26 3 * 57.4 26 68 # TALLERACK
57.4
Estp27 2 * 69.4 3 * 69.4 5 26 69 # 85SO46-37
69.4
Estp28 2 * 130.8 3 * 130.8 5 26 70 # 85SO46-37
130.8
Estp29 1 * 137.6 3 * 137.6 4 26 71 # MERRIT
137.6
Estp30 3 * 111 26 72 # TALLERACK
111
Estp31 1 * 115.2 3 * 115.2 4 26 73 # MERRIT
115.2
Estp32 3 * 79.8 26 74 # TALLERACK
79.8
Estp33 2 * 103.8 3 * 103.8 5 26 75 # 85SO46-37
103.8
Estp34 2 * 72.8 3 * 72.8 5 26 76 # 85SO46-37
72.8
Estp35 3 * 63.4 26 77 # TALLERACK
63.4
Estp36 1 * 75.8 3 * 75.8 4 26 78 # MERRIT
75.8
Estp37 3 * 21.8 26 79 # TALLERACK
21.8
Estp38 1 * 33 3 * 33 4 26 80 # MERRIT
33
Estp39 2 * 28.2 3 * 28.2 5 26 81 # 85SO46-37
28.2
Estp40 1 * 76.2 3 * 76.2 4 26 82 # MERRIT
76.2
Estp41 3 * 63.8 26 83 # TALLERACK
63.8
Estp42 2 * 71.8 3 * 71.8 5 26 84 # 85SO46-37
71.8
Estp43 1 * 95.6 3 * 95.6 4 26 85 # MERRIT
95.6
Estp44 2 * 98.4 3 * 98.4 5 26 86 # 85SO46-37
98.4
Estp45 3 * 87.6 26 87 # TALLERACK
87.6
Estp46 2 * 41.2 3 * 41.2 5 26 88 # 85SO46-37
41.2
Estp47 1 * 48.4 3 * 48.4 4 26 89 # MERRIT
48.4
Estp48 3 * 43 26 90 # TALLERACK
43
Estp49 1 * 70.4 3 * 70.4 4 26 91 # MERRIT
70.4
Estp50 2 * 64.2 3 * 64.2 5 26 92 # 85SO46-37
64.2
Estp51 3 * 54 26 93 # TALLERACK
54
Estp52 1 * 122.8 3 * 122.8 4 26 94 # MERRIT
122.8
Estp53 3 * 121.4 26 95 # TALLERACK
121.4
Estp54 2 * 115.8 3 * 115.8 5 26 96 # 85SO46-37
115.8
Estp55 3 * 82.4 26 97 # TALLERACK
82.4
Estp56 2 * 87.4 3 * 87.4 5 26 98 # 85SO46-37
87.4
Estp57 1 * 106.2 3 * 106.2 4 26 99 # MERRIT
106.2
Estp58 3 * 59 26 100 # TALLERACK
59
Estp59 1 * 130.8 3 * 130.8 4 26 101 # MERRIT
130.8
Estp60 2 * 91.6 3 * 91.6 5 26 102 # 85SO46-37
91.6
Estp61 2 * 122.6 3 * 122.6 5 26 103 # 85SO46-37
122.6
Estp62 2 * 50 3 * 50 5 26 104 # 85SO46-37
50
Estp63 1 * 46.6 3 * 46.6 4 26 105 # MERRIT
46.6
Estp64 1 * 89.4 3 * 89.4 4 26 106 # MERRIT
89.4
Estp65 3 * 52.2 26 107 # TALLERACK
52.2
Estp66 2 * 79.2 3 * 79.2 5 26 108 # 85SO46-37
79.2
Estp67 3 * 52.6 26 109 # TALLERACK
52.6
Estp68 2 * 54.4 3 * 54.4 5 26 110 # 85SO46-37
54.4
Estp69 2 * 37.4 3 * 37.4 5 26 111 # 85SO46-37
37.4
Estp70 1 * 50.8 3 * 50.8 4 26 112 # MERRIT
50.8
Estp71 2 * 26.8 3 * 26.8 5 26 113 # 85SO46-37
26.8
Estp72 3 * 27.8 26 114 # TALLERACK
27.8
Estp73 1 * 98.8 3 * 98.8 4 26 115 # MERRIT
98.8
Estp74 3 * 98.8 26 116 # TALLERACK
98.8
Estp75 2 * 93.6 3 * 93.6 5 26 117 # 85SO46-37
93.6
Estp76 1 * 52.6 3 * 52.6 4 26 118 # MERRIT
52.6
Estp77 2 * 46.6 3 * 46.6 5 26 119 # 85SO46-37
46.6
Estp78 3 * 44 26 120 # TALLERACK
44
Estp79 2 * 58 3 * 58 5 26 121 # 85SO46-37
58
Estp80 3 * 62.8 26 122 # TALLERACK
62.8
Estp81 1 * 63.4 3 * 63.4 4 26 123 # MERRIT
63.4
Estp82 2 * 114.8 3 * 114.8 5 26 124 # 85SO46-37
114.8
Estp83 1 * 128.4 3 * 128.4 4 26 125 # MERRIT
128.4
Estp84 3 * 98.4 26 126 # TALLERACK
98.4
Estp85 1 * 29.8 3 * 29.8 4 26 127 # MERRIT
29.8
Estp86 3 * 19.6 26 128 # TALLERACK
19.6
Estp87 2 * 32.6 3 * 32.6 5 26 129 # 85SO46-37
32.6
Estp88 3 * 71 26 130 # TALLERACK
71
Estp89 1 * 80.8 3 * 80.8 4 26 131 # MERRIT
80.8
Estp90 2 * 86.8 3 * 86.8 5 26 132 # 85SO46-37
86.8
Estp91 1 * 90 3 * 90 4 26 133 # MERRIT *
Estp92 1 * 90 3 * 90 4 26 134 # MERRIT *
Estp93 1 * 90 3 * 90 4 26 135 # MERRIT *
Estp94 1 * 90 3 * 90 4 26 136 # MERRIT *
Estp95 1 * 90 3 * 90 4 26 137 # MERRIT *
Estp96 1 * 90 3 * 90 4 26 138 # MERRIT *
Estp97 1 * 90 3 * 90 4 26 139 # MERRIT *
Estp98 1 * 90 3 * 90 4 26 140 # MERRIT *
Estp99 1 * 90 3 * 90 4 26 141 # MERRIT *
Estp100 1 * 90 3 * 90 4 26 142 # MERRIT *
Estp101 1 * 90 3 * 90 4 26 143 # MERRIT *
Estp102 1 * 90 3 * 90 4 26 144 # MERRIT *
Estp103 1 * 90 3 * 90 4 26 145 # MERRIT *
Estp104 1 * 90 3 * 90 4 26 146 # MERRIT *
Estp105 1 * 90 3 * 90 4 26 147 # MERRIT *
Estp106 1 * 90 3 * 90 4 26 148 # MERRIT *
Estp107 1 * 90 3 * 90 4 26 149 # MERRIT *
Estp108 1 * 90 3 * 90 4 26 150 # MERRIT *
________________________
S+ function to plot splines, confidence bands and points
asr.pvsplot2 <-
function(filenam1, row1=1, nlin=1, npts=1, filenam2, xvar, group, ndat = 1)
{
# Simple function to do the following:
# 1. Extract rows 'row1' ... 'row1'+'nlin'*'npts'-1
# from a .pvs file 'filename1'
# and plot V3 against V2 as 'nlin' lines
# 2. Extract rows 'row1' + 'nlin' * 'npts' ... 'row1'+ 'nlin' * 'npts' + 'ndat'
# from 'filename1'. Column V4 to be used.
# Extract rows 1 ... ndat from 'filename2'. Columns ESTAB and Variety
# to be used. Plot V4 against ESTAB. (Variety is intended to be used
# to determine plotting symbols, but this is not yet implemented.)
# filename may be a dataframe or a filename
if(is.character(filenam1)) df1 <- read.table(filenam1, header = F,
row.names = NULL) else if(is.data.frame(filenam1))
df1 <- filenam1
else return()
if(is.character(filenam2)) df2 <- read.table(filenam2, header = T,
row.names = NULL) else if(is.data.frame(filenam2))
df1 <- filenam2
else return()
x <- matrix(df1$V2[row1:(row1 - 1 + nlin * npts)], npts, nlin)
y <- matrix(df1$V3[row1:(row1 - 1 + nlin * npts)], npts, nlin)
s <- matrix(df1$V4[row1:(row1 - 1 + nlin * npts)], npts, nlin)
yp <- y + s
ym <- y - s
yobs <- matrix(df1$V3[(row1 + nlin * npts):(row1 + nlin * npts + ndat)],
ndat, 1)
xobs <- matrix(df2$ESTAB[1:ndat], ndat, 1)
variety <- matrix(df2$Variety[1:ndat], ndat, 1)
xall <- cbind(x, x, x)
yall <- cbind(y, yp, ym)
matplot(xall, yall, type = "l", lty = 1:nlin)
matpoints(xobs, yobs, type = "p", pch="*")
list(XALL = xall, YALL = yall)
list(YOBS = yobs, XOBS = xobs, VARIETY = variety)
}
__________________________
S+ statements to call the above function (with appropriate changes to file
names)
win.graph()
source("c:\\docs\\dracup_m\\96wh14\\pvsplot2.s")
asr.pvsplot2("c:\\docs\\dracup_m\\96wh14\\96wh14.pvs", 1, 3, 6,
"c:\\docs\\dracup_m\\96wh14\\96wh14.dat", ESTAB, Variety, 108)
___________________________
file 96wh14.dat
Variety TDENS Rep PLOT COL ROW THA ESTAB
MERRIT 100 1 1 1 1 0.883 93.2
85SO46-37 100 1 2 1 2 0.909 100
TALLERACK 100 1 3 1 3 * 105.4
85SO46-37 125 4 4 1 4 * 116.4
MERRIT 75 1 5 1 5 0.857 85
TALLERACK 125 4 6 1 6 0.753 118.8
TALLERACK 125 1 7 1 7 0.935 120.6
TALLERACK 45 4 8 1 8 0.883 42.8
MERRIT 125 1 9 1 9 1.09 117.4
85SO46-37 60 1 10 1 10 0.831 64.8
MERRIT 60 1 11 1 11 1.038 56.2
TALLERACK 60 1 12 1 12 1.038 52.2
TALLERACK 45 1 13 1 13 1.064 45.2
MERRIT 45 1 14 1 14 0.961 50.4
MERRIT 60 4 15 1 15 0.805 60.6
TALLERACK 25 1 16 1 16 1.298 25
85SO46-37 25 1 17 1 17 1.324 26.8
MERRIT 25 1 18 1 18 1.402 24.2
MERRIT 45 2 19 1 19 1.402 55.6
TALLERACK 45 2 20 1 20 1.194 65.2
85SO46-37 45 2 21 1 21 1.22 50.2
85SO46-37 25 2 22 1 22 1.35 24
TALLERACK 25 2 23 1 23 1.168 21.8
MERRIT 25 2 24 1 24 1.194 26.8
MERRIT 60 2 25 1 25 0.987 56.2
TALLERACK 60 2 26 1 26 1.038 57.4
85SO46-37 60 2 27 1 27 0.909 69.4
85SO46-37 125 2 28 1 28 0.753 130.8
MERRIT 125 2 29 1 29 0.883 137.6
TALLERACK 125 2 30 1 30 0.883 111
MERRIT 100 2 31 1 31 0.831 115.2
TALLERACK 100 2 32 1 32 0.961 79.8
85SO46-37 100 2 33 1 33 0.909 103.8
85SO46-37 75 2 34 1 34 0.961 72.8
TALLERACK 75 2 35 1 35 1.012 63.4
MERRIT 75 2 36 1 36 1.194 75.8
TALLERACK 25 3 37 1 37 1.142 21.8
MERRIT 25 3 38 1 38 1.246 33
85SO46-37 25 3 39 1 39 1.168 28.2
MERRIT 75 3 40 1 40 1.168 76.2
TALLERACK 75 3 41 1 41 1.142 63.8
85SO46-37 75 3 42 1 42 1.064 71.8
MERRIT 100 3 43 1 43 1.09 95.6
85SO46-37 100 3 44 1 44 0.961 98.4
TALLERACK 100 3 45 1 45 1.142 87.6
85SO46-37 45 3 46 1 46 1.194 41.2
MERRIT 45 3 47 1 47 1.324 48.4
TALLERACK 45 3 48 1 48 1.298 43
MERRIT 60 3 49 1 49 1.428 70.4
85SO46-37 60 3 50 1 50 1.246 64.2
TALLERACK 60 3 51 1 51 1.194 54
MERRIT 125 3 52 1 52 1.272 122.8
TALLERACK 125 3 53 1 53 1.116 121.4
85SO46-37 125 3 54 1 54 1.012 115.8
TALLERACK 100 4 55 2 1 1.038 82.4
85SO46-37 100 4 56 2 2 0.935 87.4
MERRIT 100 4 57 2 3 0.857 106.2
TALLERACK 75 1 58 2 4 0.935 59
MERRIT 125 4 59 2 5 0.805 130.8
85SO46-37 75 1 60 2 6 0.961 91.6
85SO46-37 125 1 61 2 7 0.909 122.6
85SO46-37 45 4 62 2 8 0.987 50
MERRIT 45 4 63 2 9 0.831 46.6
MERRIT 75 4 64 2 10 0.805 89.4
TALLERACK 75 4 65 2 11 0.805 52.2
85SO46-37 75 4 66 2 12 0.805 79.2
TALLERACK 60 4 67 2 13 1.012 52.6
85SO46-37 60 4 68 2 14 0.883 54.4
85SO46-37 45 1 69 2 15 1.35 37.4
MERRIT 25 4 70 2 16 0.753 50.8
85SO46-37 25 4 71 2 17 0.909 26.8
TALLERACK 25 4 72 2 18 0.805 27.8
MERRIT 100 5 73 2 19 0.857 98.8
TALLERACK 100 5 74 2 20 0.831 98.8
85SO46-37 100 5 75 2 21 0.909 93.6
MERRIT 45 5 76 2 22 0.987 52.6
85SO46-37 45 5 77 2 23 1.012 46.6
TALLERACK 45 5 78 2 24 0.961 44
85SO46-37 60 5 79 2 25 0.987 58
TALLERACK 60 5 80 2 26 0.883 62.8
MERRIT 60 5 81 2 27 0.961 63.4
85SO46-37 125 5 82 2 28 0.805 114.8
MERRIT 125 5 83 2 29 0.779 128.4
TALLERACK 125 5 84 2 30 0.909 98.4
MERRIT 25 5 85 2 31 0.961 29.8
TALLERACK 25 5 86 2 32 1.116 19.6
85SO46-37 25 5 87 2 33 1.09 32.6
TALLERACK 75 5 88 2 34 0.961 71
MERRIT 75 5 89 2 35 0.805 80.8
85SO46-37 75 5 90 2 36 0.909 86.8
MERRIT 25 1 1 2 37 NA NA
MERRIT 25 1 1 2 38 NA NA
MERRIT 25 1 1 2 39 NA NA
MERRIT 25 1 1 2 40 NA NA
MERRIT 25 1 1 2 41 NA NA
MERRIT 25 1 1 2 42 NA NA
MERRIT 25 1 1 2 43 NA NA
MERRIT 25 1 1 2 44 NA NA
MERRIT 25 1 1 2 45 NA NA
MERRIT 25 1 1 2 46 NA NA
MERRIT 25 1 1 2 47 NA NA
MERRIT 25 1 1 2 48 NA NA
MERRIT 25 1 1 2 49 NA NA
MERRIT 25 1 1 2 50 NA NA
MERRIT 25 1 1 2 51 NA NA
MERRIT 25 1 1 2 52 NA NA
MERRIT 25 1 1 2 53 NA NA
MERRIT 25 1 1 2 54 NA NA
_____________________________________________________________________
N.W. Galwey,
Faculty of Agriculture,
University of Western Australia,
Nedlands, WA 6709, Australia.
Tel.: +61 9 380 1959 (direct line)
+61 9 380 2554 (switchboard)
Fax: +61 9 380 1108