[Rd] Problem with predict.nlme
Kjetil Brinchmann Halvorsen
kjetil@entelnet.bo
Tue Dec 31 00:47:02 2002
--------------Boundary-00=_KZHY36E1VA4000000000
Content-Type: Multipart/Alternative;
boundary="------------Boundary-00=_KZHYYHI1VA4000000000"
--------------Boundary-00=_KZHYYHI1VA4000000000
Content-Type: Text/Plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hola!=0D
=0D
plot( augPred(papas2.nlme.5), layout=3Dc(5,5,6) )=0D
Error in predict.nlme(object, value[1:(nrow(value)/nL), , drop =3D FALSE]=
, : =0D
Levels 1,2,3,4,5 not allowed for medio=0D
=0D
plot( augPred(papas2.nlme.2), layout=3Dc(5,5,6) )=0D
... succeeds=0D
plot( augPred(papas2.nlme.2,level=3D0:1), layout=3Dc(5,5,6) )=0D
... succeeds=0D
> plot( augPred(papas2.nlme.3), layout=3Dc(5,5,6) )=0D
Error in predict.nlme(object, value[1:(nrow(value)/nL), , drop =3D FALSE]=
, : =0D
Levels 1,2,3,4,5 not allowed for medio=0D
> plot( augPred(papas2.nlme.4), layout=3Dc(5,5,6) )=0D
Error in predict.nlme(object, value[1:(nrow(value)/nL), , drop =3D FALSE]=
, : =0D
Levels 1,2,3,4,5 not allowed for medio=0D
=0D
The difference between the object papas2.nlme.2 where it succeeds and =0D
papas2.nlme.3, papas2.nlme.4, papas2.nlme.5 where it not, is that in the
last =0D
objects the argument fixed to nlme models the parameters as regressions o=
n =0D
covariables (factors), while in the first object the parametrs have only =
an
intercept. =0D
The covariables are constant in each group (plant), so the augPred plot =0D
seems to make sense, no averaging should be necessary. =0D
An excerpt from debug(predict.nlme) follows:=0D
> plot( augPred(papas2.nlme.5), layout=3Dc(5,5,6) )=0D
debugging in: predict.nlme(object, value[1:(nrow(value)/nL), , drop =3D F=
ALSE]
=0D
.=0D
.=0D
.=0D
debug: revOrder <- match(origOrder, row.names(dataMix))=0D
Browse[1]> n=0D
debug: contr <- object$contrasts=0D
Browse[1]> n=0D
debug: for (i in names(dataMix)) {=0D
if (inherits(dataMix[, i], "factor") && !is.null(contr[[i]])) {=0D
levs <- levels(dataMix[, i])=0D
levsC <- dimnames(contr[[i]])[[1]]=0D
if (any(wch <- is.na(match(levs, levsC)))) {=0D
stop(paste("Levels", paste(levs[wch], collapse =3D ","), =0D
"not allowed for", i))=0D
}=0D
attr(dataMix[, i], "contrasts") <- contr[[i]][levs, , =0D
drop =3D FALSE]=0D
}=0D
}=0D
Browse[1]> contr=0D
$medio=0D
[1] "contr.treatment"=0D
$variedad=0D
[1] "contr.treatment"=0D
# contr have names of functions supposed to construct contrast matrices.=0D
Browse[1]> dimnames(contr[["medio"]])=0D
NULL=0D
Browse[1]> n=0D
debug: i=0D
Browse[1]> n=0D
debug: if (inherits(dataMix[, i], "factor") && !is.null(contr[[i]])) {=0D
levs <- levels(dataMix[, i])=0D
levsC <- dimnames(contr[[i]])[[1]]=0D
if (any(wch <- is.na(match(levs, levsC)))) {=0D
# the code seems to assume that contr has the actual contrast matrix!=0D
stop(paste("Levels", paste(levs[wch], collapse =3D ","), =0D
"not allowed for", i))=0D
}=0D
attr(dataMix[, i], "contrasts") <- contr[[i]][levs, , drop =3D FALSE]=
=0D
}=0D
=2E=0D
=2E=0D
=2E=0D
=2E=0D
debug: levs <- levels(dataMix[, i])=0D
Browse[1]> n=0D
debug: levsC <- dimnames(contr[[i]])[[1]]=0D
Browse[1]> levs=0D
[1] "1" "2" "3" "4" "5"=0D
Browse[1]> n=0D
debug: if (any(wch <- is.na(match(levs, levsC)))) {=0D
stop(paste("Levels", paste(levs[wch], collapse =3D ","), "not allowed=
for"
=0D
i))=0D
}=0D
Browse[1]> n=0D
debug: stop(paste("Levels", paste(levs[wch], collapse =3D ","), "not allo=
wed
for", =0D
i))=0D
Browse[1]> n=0D
Error in predict.nlme(object, value[1:(nrow(value)/nL), , drop =3D FALSE]=
, : =0D
Levels 1,2,3,4,5 not allowed for medio=0D
# because dimnames of "contr.treatment" is NULL!=0D
=0D
Kjetil Halvorsen
--------------Boundary-00=_KZHYYHI1VA4000000000
Content-Type: Text/HTML;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-885=
9-1"><html>
<head>
<meta name=3D"GENERATOR" content=3D"IncrediMail 1.0">=0D
<!--IncrdiXMLRemarkStart>
<IncrdiX-Info>
<X-FID>BA285063-5BCE-11D4-AF8D-0050DAC67E11</X-FID>
<X-FVER>2.0</X-FVER>
<X-FIT>Letter</X-FIT>
<X-FCOL>Elegant Paper</X-FCOL>
<X-FCAT>Stationery</X-FCAT>
<X-FDIS>Rice Fields</X-FDIS>
<X-Extensions>SU1CTDEsNDEsgUmBSTAkkcGNgZmVTY0wNCxNhYUoiU0kOMEoTYGBjYEoJDS=
ZnSyFhUksSU1CTDIsMCwsSU1CTDMsMCws</X-Extensions>
<X-BG>8F283858-1599-4CA4-A962-FEA2F09D0D6A</X-BG>
<X-BGT>repeat</X-BGT>
<X-BGC>#dce0e3</X-BGC>
<X-BGPX>0px</X-BGPX>
<X-BGPY>0px</X-BGPY>
<X-ASN>ANIM3D00-NONE-0000-0000-000000000000</X-ASN>
<X-ASNF>0</X-ASNF>
<X-ASH>ANIM3D00-NONE-0000-0000-000000000000</X-ASH>
<X-ASHF>1</X-ASHF>
<X-AN>6486DDE0-3EFD-11D4-BA3D-0050DAC68030</X-AN>
<X-ANF>0</X-ANF>
<X-AP>6486DDE0-3EFD-11D4-BA3D-0050DAC68030</X-AP>
<X-APF>1</X-APF>
<X-AD>C3C52140-4147-11D4-BA3D-0050DAC68030</X-AD>
<X-ADF>0</X-ADF>
<X-AUTO>X-ASN,X-ASH,X-AN,X-AP,X-AD</X-AUTO>
<X-CNT>;</X-CNT>
</IncrdiX-Info>
<IncrdiXMLRemarkEnd-->
=0A</head>
<BODY style=3D"BACKGROUND-POSITION: 0px 0px; FONT-SIZE: 12pt; MARGIN: 0px=
10px 10px; BACKGROUND-REPEAT: repeat; FONT-FAMILY: Comic Sans MS" text=3D=
#000040 bgColor=3D#dce0e3 background=3Dcid:8F283858-1599-4CA4-A962-FEA2F0=
9D0D6A scroll=3D"yes" X-FIT=3D"Letter" X-FCAT=3D"Elegant Paper" X-FCOL=3D=
"Elegant Paper" X-FDIS=3D"Rice Fields" X-FID=3D"BA285063-5BCE-11D4-AF8D-0=
050DAC67E11" X-FVER=3D"2.0" X-ASN=3D"ANIM3D00-NONE-0000-0000-000000000000=
" X-ASNF=3D"0" X-ASH =3D"ANIM3D00-NONE-0000-0000-000000000000" X-ASHF =3D=
"1" X-AN =3D"6486DDE0-3EFD-11D4-BA3D-0050DAC68030" X-ANF=3D"0" X-AP=3D"64=
86DDE0-3EFD-11D4-BA3D-0050DAC68030" X-APF=3D"1" X-AD=3D"C3C52140-4147-11D=
4-BA3D-0050DAC68030" X-ADF=3D"0" SIGCOLOR=3D"0" ORGYPOS=3D"0"><TABLE id=3D=
INCREDIMAINTABLE cellSpacing=3D0 cellPadding=3D2 width=3D"95%" border=3D0=
>
<TBODY>
<TR>
<TD id=3DINCREDITEXTREGION style=3D"PADDING-RIGHT: 7px; PADDING-LEFT: 7px=
; FONT-SIZE: 10pt; FONT-FAMILY: Comic Sans MS"=20
width=3D"100%">
<DIV>Hola!</DIV>
<DIV><BR>plot( augPred(papas2.nlme.5), layout=3Dc(5,5,6) )<BR>Error=
in=20
predict.nlme(object, value[1:(nrow(value)/nL), , drop =3D FALSE],&n=
bsp; :=20
<BR> Levels 1,2,3,4,5 not=
=20
allowed for medio</DIV>
<DIV><BR> plot( augPred(papas2.nlme.2), layout=3Dc(5,5,6)=20
)<BR> ... succeeds</DIV>
<DIV>plot( augPred(papas2.nlme.2,level=3D0:1), layout=3Dc(5,5,6)=20
)<BR> ... succeeds</DIV>
<DIV>> plot( augPred(papas2.nlme.3), layout=3Dc(5,5,6) )<BR>Erro=
r in=20
predict.nlme(object, value[1:(nrow(value)/nL), , drop =3D FALSE],&n=
bsp; :=20
<BR> Levels 1,2,3,4,5 not=
=20
allowed for medio<BR>> plot( augPred(papas2.nlme.4), layout=3Dc(=
5,5,6)=20
)<BR>Error in predict.nlme(object, value[1:(nrow(value)/nL), , drop=
=3D=20
FALSE], : <BR> Leve=
ls=20
1,2,3,4,5 not allowed for medio</DIV>
<DIV><BR>The difference between the object papas2.nlme.2 where it s=
ucceeds=20
and <BR>papas2.nlme.3, papas2.nlme.4, papas2.nlme.5 where it not, i=
s that=20
in the last <BR>objects the argument fixed to nlme models the param=
eters=20
as regressions on <BR>covariables (factors), while in the first obj=
ect the=20
parametrs have only an intercept. <BR>The covariables are constant =
in each=20
group (plant), so the augPred plot <BR>seems to make sense, no aver=
aging=20
should be necessary. </DIV>
<DIV>An excerpt from debug(predict.nlme) follows:</DIV>
<DIV>> plot( augPred(papas2.nlme.5), layout=3Dc(5,5,6) )<BR>debu=
gging in:=20
predict.nlme(object, value[1:(nrow(value)/nL), , drop =3D FALSE],=20
<BR> .<BR> .<BR> .</DIV>
<DIV>debug: revOrder <- match(origOrder,=20
row.names(dataMix))<BR>Browse[1]> n<BR>debug: contr <-=20
object$contrasts<BR>Browse[1]> n<BR>debug: for (i in names(dataM=
ix))=20
{<BR> if (inherits(dataMix[, i], "factor") &&=
amp;=20
!is.null(contr[[i]])) {<BR> &nbs=
p; levs=20
<- levels(dataMix[, i])<BR> &=
nbsp;=20
levsC <-=20
dimnames(contr[[i]])[[1]]<BR> &n=
bsp; if=20
(any(wch <- is.na(match(levs, levsC))))=20
{<BR> &n=
bsp;=20
stop(paste("Levels", paste(levs[wch], collapse =3D ","),=20
<BR> &nb=
sp; =20
"not allowed for", i))<BR>  =
;=20
}<BR> attr(dataMix[, i],=20
"contrasts") <- contr[[i]][levs, ,=20
<BR> &nb=
sp;=20
drop =3D FALSE]<BR> }<BR>}<BR>Browse[1]>=20
contr<BR>$medio<BR>[1] "contr.treatment"</DIV>
<DIV>$variedad<BR>[1] "contr.treatment"</DIV>
<DIV># contr have names of functions supposed to construct contrast=
=20
matrices.</DIV>
<DIV>Browse[1]> dimnames(contr[["medio"]])<BR>NULL<BR>Browse[1]&=
gt;=20
n<BR>debug: i<BR>Browse[1]> n<BR>debug: if (inherits(dataMix[, i=
],=20
"factor") && !is.null(contr[[i]])) {<BR> =
levs=20
<- levels(dataMix[, i])<BR> levsC <-=20
dimnames(contr[[i]])[[1]]<BR> if (any(wch <-=20
is.na(match(levs, levsC)))) {</DIV>
<DIV> # the code seems to assume that contr has the actual con=
trast=20
matrix!</DIV>
<DIV> stop(paste("Levels"=
,=20
paste(levs[wch], collapse =3D ","),=20
<BR> &nb=
sp;=20
"not allowed for", i))<BR> }<BR>  =
;=20
attr(dataMix[, i], "contrasts") <- contr[[i]][levs, , drop =3D=20
FALSE]<BR>}<BR>.<BR>.<BR>.<BR>.</DIV>
<DIV>debug: levs <- levels(dataMix[, i])<BR>Browse[1]> n<BR>d=
ebug:=20
levsC <- dimnames(contr[[i]])[[1]]<BR>Browse[1]> levs<BR>[1] =
"1" "2"=20
"3" "4" "5"<BR>Browse[1]> n<BR>debug: if (any(wch <-=20
is.na(match(levs, levsC)))) {<BR> stop(paste("Lev=
els",=20
paste(levs[wch], collapse =3D ","), "not allowed for",=20
<BR> i))<BR>}<BR>Browse[1=
]>=20
n<BR>debug: stop(paste("Levels", paste(levs[wch], collapse =3D ",")=
, "not=20
allowed for", <BR> i))<BR>Browse[1]> n<BR>Erro=
r in=20
predict.nlme(object, value[1:(nrow(value)/nL), , drop =3D FALSE],&n=
bsp; :=20
<BR> Levels 1,2,3,4,5 not=
=20
allowed for medio</DIV>
<DIV># because dimnames of "contr.treatment" is NULL!</DIV>
<DIV> </DIV>
<DIV>Kjetil Halvorsen</DIV>
<DIV> </DIV></TD></TR>
<TR>
<TD id=3DINCREDIFOOTER width=3D"100%">
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%">
<TBODY>
<TR>
<TD width=3D"100%"></TD>
<TD id=3DINCREDISOUND vAlign=3Dbottom align=3Dmiddle></TD>
<TD id=3DINCREDIANIM vAlign=3Dbottom align=3Dmiddle></TD></TR></TBODY></T=
ABLE></TD></TR></TBODY></TABLE><SPAN=20
id=3DIncrediStamp><SPAN dir=3Dltr><FONT face=3D"Arial, Helvetica, sans-se=
rif"=20
size=3D2>____________________________________________________<BR><FONT=20
face=3D"Comic Sans MS" size=3D2><A=20
href=3D"http://www.incredimail.com/redir.asp?ad_id=3D309&lang=3D9"><I=
MG alt=3D""=20
hspace=3D0 src=3D"cid:1EB49B54-4A05-473A-A477-BD6136BC92F4" align=3Dbasel=
ine=20
border=3D0></A> <I>IncrediMail</I> - <B>Email has finally evolved</=
B> -=20
</FONT><A href=3D"http://www.incredimail.com/redir.asp?ad_id=3D309&la=
ng=3D9"><FONT=20
face=3D"Times New Roman" size=3D3><B><U>Click=20
Here</U></B></FONT></A></SPAN></SPAN></FONT></BODY></html>
--------------Boundary-00=_KZHYYHI1VA4000000000--
--------------Boundary-00=_KZHY36E1VA4000000000
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-ID: <1EB49B54-4A05-473A-A477-BD6136BC92F4>
R0lGODlhFAAPALMIAP9gAM9gAM8vAM9gL/+QL5AvAGAvAP9gL////wAAAAAAAAAAAAAAAAAAAAAA
AAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJFAAIACwAAAAAFAAPAAAEVRDJSaudJuudrxlEKI6B
URlCUYyjKpgYAKSgOBSCDEuGDKgrAtC3Q/R+hkPJEDgYCjpKr5A8WK9OaPFZwHoPqm3366VKyeRt
E30tVVRscMHDqV/u+AgAIfkEBWQACAAsAAAAABQADwAABBIQyUmrvTjrzbv/YCiOZGmeaAQAIfkE
CRQACAAsAgABABAADQAABEoQIUOrpXIOwrsPxiQUheeRAgUA49YNhbCqK1kS9grQhXGAhsDBUJgZ
AL2Dcqkk7ogFpvRAokSn0p4PO6UIuUsQggSmFjKXdAgRAQAh+QQFCgAIACwAAAAAFAAPAAAEEhDJ
Sau9OOvNu/9gKI5kaZ5oBAAh+QQJFAAIACwCAAEAEAANAAAEShAhQ6ulcg7Cuw/GJBSF55ECBQDj
1g2FsKorWRL2CtCFcYCGwMFQmBkAvYNyqSTuiAWm9ECiRKfSng87pQi5SxCCBKYWMpd0CBEBACH5
BAVkAAgALAAAAAAUAA8AAAQSEMlJq7046827/2AojmRpnmgEADs=
--------------Boundary-00=_KZHY36E1VA4000000000
Content-Type: Image/jpeg
Content-ID: <8F283858-1599-4CA4-A962-FEA2F09D0D6A>
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAHgAA/+4AIUFkb2JlAGTAAAAAAQMA
EAMCAwYAAAHbAAAC1gAABZX/2wCEABALCwsMCxAMDBAXDw0PFxsUEBAUGx8XFxcXFx8eFxoaGhoX
Hh4jJSclIx4vLzMzLy9AQEBAQEBAQEBAQEBAQEABEQ8PERMRFRISFRQRFBEUGhQWFhQaJhoaHBoa
JjAjHh4eHiMwKy4nJycuKzU1MDA1NUBAP0BAQEBAQEBAQEBAQP/CABEIAGUAcwMBIgACEQEDEQH/
xACAAAEBAQEAAAAAAAAAAAAAAAAAAQIGAQEBAAAAAAAAAAAAAAAAAAAAARABAAICAwEAAgMAAAAA
AAAAAQARIQIxQRIiQDIQMFARAAICAgIBBAIDAQEAAAAAAAERACExQVFhcYGRobECEsHhMtHxEgEA
AAAAAAAAAAAAAAAAAABQ/9oADAMBAAIRAxEAAADtRZYE1ASghQFgUZoCkKSwLmhcllAEqkSkqFAl
hUomoAS3IoJqFlDNpFEAQFE1AIVYAWIVKAJRNZpYCwVmmshKACA0CBAUCBYGwf/aAAgBAgABBQD8
B/yP/9oACAEDAAEFAPz6/or8H//aAAgBAQABBQC2+ZeHjbD+saX6hwXeDW1Rg4xLLTa+m7ZiIEsI
1MTiHP1dYpvFADiFM1/X6nq9byuwdPPz5oFofWlEMQ9ULKrWq2ppG9Y2J6INQma9lVTRdlUKgHzX
XSEECw1SYu5WsGoJPkisZYpx31GvXZQ/JM3VwShzVTs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