Hi, Thank you for the suggestions. I've attached the code in the text file "test"; to run this one needs the CollocInfer package(available under R 2.14, now I think if you have 2.14 on your system you can download CollocInfer from CRAN).
I've tried the 'error' options you suggest; using the syntax "dimnames(data2)[1:2]" does seem to give an improvement of the attributes of the array, But even with the attributes seeming to be in as good order as they might be(i.e., each boxcar, [[1]],[[2]],[[3]] contains the correct number of names), rerunning the analysis with the revised array returns the same error. traceback() gives 4: `colnames<-`(`*tmp*`, value = c("V", "R")) 3: objective(.par, ...) 2: nlminb(coefs, SplineCoefsErr, gradient = SplineCoefsDC, hessian = Hessian, control = control.in, times = times, data = data, lik = lik, proc = proc, pars = pars) 1: inneropt(coefs = DEfd2$coefs, times = times, data = data2, lik = lik, proc = proc, pars = spars, in.meth = "nlminb", control.in = control.out) To my (untrained) eye, this points again to some kind of mismatch between the array 'data2' and its dimnames. Again I'll be grateful if anyone can see what the problem is. regards, A (recover() also is unfruitful) Fri, 17 Aug 2012 15:28:19 +0000 от William Dunlap <wdun...@tibco.com>: > > > > >Have you showed us how to reproduce your original problem? > Have you showed us the output of traceback() after encountering > the error? Have you tried setting options(error=recover) before > encountering the error and then using recover() to look at the dimensions > and dimnames of the array that caused the problem? > > This error message > > > Error in `colnames<-`(`*tmp*`, value = c("V", "R")) : > > > length of 'dimnames' [2] not equal to array extent > comes from a nested replacement operation. One such such case is > mat <- matrix(1:6,nrow=2,ncol=3) > colnames(mat)[1:2] <- c("V", "R") > where the nested replacement gets expanded into > tmp <- colnames(mat) # tmp becomes NULL > tmp[1:2] <- c("V", "R") # tmp becomes c("V","R"), length is 2 > colnames(tmp) <- tmp # error: 2 colnames for 3 columns > (R uses `*tmp*` where I used tmp - the former is for internal use only.) > > There are lots of other possibilities, but you need to at least show the > output of traceback() to pin it down. > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > > > > -----Original Message----- > > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > > Of aleksandr shfets > > Sent: Friday, August 17, 2012 6:25 AM > > To: R. Michael Weylandt > > Cc: r-help@r-project.org > > Subject: Re: [R] dimnames in an array(I'll be grateful if this message will > be passed to all > > list users) > > > > > > Michael, > > Thank you for suggestions; > > it seems to me that there's a fundamental lacuna with respect to names of a > three > > dimensional array: > > that is, rownames fits dimension 1, colnames fits another dimension(that is, > 3, if I read it > > correctly), > > but there is no specific name for the third dimension. I've tried "setnames" > thinking that > > this would be appropriate > > for naming the sets, but there is no such R function. > > > > On the other hand you're right, the suggestion > > dimnames(data11a)[[2]]=c("V","R") > > > > doesn't ameliorate the analysis: while now dimnames(data11a)[[2]] > > > > comes out as > > [2] > > > > returning to the original analysis the same error comes up, that is, that the > length of > > dimnames[2] doesn't agree with thee. > > 'array extent' -- that is, even though the boxcar contents are two in number, > it evaluates > > the analysis on the basis of the > > dimnames(data11a)[2] value. > > > > I'm using colloc infer (available under R 2.14) and trying to do the > FHN(FitzHugh Nagumo) > > analysis in section 9.1 of the manual; it's very complex work, but I doubt > the program is > > in error. > > > > It seems to me in any case that, if R demands that the length of 'dimnames[2] > must be > > equal to the array extent, then there must be a way to make the length of the > names > > equal to the extent of the array, am I right? > > Otherwise R would be inconsistent with itself, like Nomad on Startrek, and > I've never > > seen a case where it was thus. > > > > This is again why I ask if others with extensive experience with dimnames of > an array > > have seen anything similar. > > Certainly someone might know what is the significance of the dimnames of the > array, > > how much can the length of them be altered for use generally? > > > > regards, > > A > > Thu, 16 Aug 2012 00:00:35 -0400 от "R. Michael Weylandt" > > <michael.weyla...@gmail.com>: > > > > > > > > > > > > > > > > > > > > > > > > >On Wed, Aug 15, 2012 at 3:57 AM, aleksandr shfets <a_shf...@mail.ru> wrote: > > > > > > Hi Michael, > > > > > > Thanks for help on double brackets: I wasn't aware of this use of them. > > > > > > > > > > > > I went back to readjust my array so the dimnames(data11a)[[2]] would have > > > > > > two elements, and remade the array to include the new dimnames: > > > > > > > > > > > > dimnames(data11a)[[2]]=c("V","R") > > > > > > > > > > > > so that inside the second car of the train would > > > > > > be two items? > > > > > > > > Yes. > > > > > > > > > > > > > > > There seems to be no way to define dimnames(data11a)[2] to be two elements > > > > > > rather than one[as you say we have no way to combine the elements of the > > > > > > train except using the train]. > > > > > > > > You could do this: > > > > > > > > dimnames(data11a)[2] <- list(c("V","R")) > > > > > > > > but I'm not sure that's any clearer. To keep the metaphor rolling (get > > > > > it!), list() puts your stuff in a boxcar so now you can put it > > > > > directly on the train. > > > > > > > > > So having tried to do what I can to make the > > > > > > middle element of the list to two rather than one, I rerun the analysis with > > > > > > the same result. > > > > > > > > > > > > if I read the thing right, regardless of how I define the "inside" of the > > > > > > boxcar, the analysis that I referred to > > > > > > > > > > > > res11a = inneropt(coefs, times=times, data=data11a, > > > > > > lik=lik, > > > > > > proc=proc, pars=spars, in.meth='nlminb', > > > > > > control.in=control.out) > > > > > > > > > > > > > > Where is this inneropt function from? It could be an error in that. If > > > > > it's from a package, give me the name and I'll take a look at it and > > > > > you can also contact the maintainer: get contact info using the > > > > > maintainer() function. > > > > > > > > Also, some of the advice here will probably be helpful in seeking follow-up: > > > > > >http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible- > > example > > > > > > > > Cheers, > > > > > Michael > > > > > > > > > still won't look at the 'contents' of the car, but gives the same message: > > > > > > > > > > > > Error in `colnames<-`(`*tmp*`, value = c("V", "R")) : > > > > > > length of 'dimnames' [2] not equal to array extent > > > > > > > > > > > > > > > > > > I've tried a couple of other things like, after defining the second boxcar > > > > > > as: > > > > > > > > > > > > dimnames(data11a)[[2]]=c("V","R") > > > > > > > > > > > > > > > > > > then > > > > > > > > > > > > > > > > > > dimnames(data11a)[2]=list(dimnames(data11a)[[2]]) > > > > > > > > > > > > > > > > > > but this last generates an error. > > > > > > > > > > > > Somehow I think that that the clue to the thing is in the error message: > > > > > > what I see[ with my untrained eye] is that there should be some way to > > > > > > reconcile the three-- colnames, dimnames and the array- to a greater degree > > > > > > than their present agreement. > > > > > > Am I right? > > > > > > regards, > > > > > > Russell > > > > > > > > > > > > Tue, 14 Aug 2012 01:27:50 -0400 от "R. Michael Weylandt" > > > > > > <michael.weyla...@gmail.com>: > > > > > > > > > > > > On Mon, Aug 13, 2012 at 5:10 AM, aleksandr russell <sss...@gmail.com> wrote: > > > > > >> Hello, > > > > > >> > > > > > >> I'm hoping someone with a wide experience with R may be able to see > > > > > >> what the program is trying to tell me. > > > > > >> > > > > > >> I've got an array: > > > > > >> > > > > > >> y1=rnorm(41,0.2) > > > > > >> y2=rnorm(41,0.2) > > > > > >> y3=rbind(y1,y2) > > > > > >> > > > > > >> > > > > > >> > > > > > >> data11<-array(0,c(41,2,2)) > > > > > >> data11[,1,]=y3 > > > > > >> data11[,2,]=y3 > > > > > >> rownames(data11)<-rownames(data11, do.NULL = FALSE, prefix = "Obs.") > > > > > >> colnames=c("V","R") > > > > > >> varnames=c("one","two") > > > > > >> dimnames(data11)<-list(rownames(data11), varnames, colnames) > > > > > >> > > > > > >> > > > > > >> > > > > > >> data11a<-as.array(data11, dimnames=dimnames(data11)) > > > > > > > > > > > > # No effect here > > > > > > identical(data11, data11a) # TRUE > > > > > > > > > > > >> > > > > > >> The analysis that I would like to do with R(CollocInfer) runs as > > > > > >> follows(I print for the sake of introduction here though to run this > > > > > >> line of code requires extensive setup) > > > > > >> > > > > > >> res11a = inneropt(coefs, times=times, data=data11a, lik=lik, > > > > > >> proc=proc, pars=spars, in.meth='nlminb', control.in=control.out) > > > > > >> > > > > > >> > > > > > >> > > > > > >> The response I get is > > > > > >> > > > > > >> Error in 'colnames<-'('*tmp*', value = c("V","R")) : > > > > > >> length of 'dimnames' [2] not equal to array extent > > > > > >> > > > > > >> > > > > > >> > > > > > >> It seems to me that there is a fundamental match of 'dimnames' with > > > > > >> the array that is being referred to. > > > > > >> > > > > > >> I have learned that the normal length of dimnames for an array is one > > > > > >> for each element in the list: thus as I've set up the array, the > > > > > >> length(dimnames(data11a)[2]) gives me > > > > > >> > > > > > >> [1] > > > > > > > > > > > > I believe you are looking for > > > > > > > > > > > > length(dimnames(data11a)[[2]]) # 2 > > > > > > > > > > > > Look into the difference between `[` and `[[` for subsetting a list. > > > > > > See ?Extract for the gorey details, but I like my little train > > > > > > metaphor: > > > > > > > > > > > > If the list "x", is a train: x[2] is the "sub-train" consisting only > > > > > > of the second car, while x[[2]] is the contents of that second car. > > > > > > Hence we can do x[1:3] to give a well defined train, but not x[[1:3]] > > > > > > because we have no way to combine the elements of the first three cars > > > > > > other than using a train. > > > > > > > > > > > > Cheers, > > > > > > Michael > > > > > > > > > > > >> > > > > > >> I would like to ask :Is it not evident from R's response that there is > > > > > >> some other possibility for the dimnames[2] of the array? > > > > > >> > > > > > >> If so, what is it? > > > > > >> > > > > > >> regards, > > > > > >> A > > > > > >> > > > > > >> ______________________________________________ > > > > > >> R-help@r-project.org mailing list > > > > > >> https://stat.ethz.ch/mailman/listinfo/r-help > > > > > >> PLEASE do read the posting guide > > > > > >> http://www.R-project.org/posting-guide.html > > > > > >> and provide commented, minimal, self-contained, reproducible code. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > [[alternative HTML version deleted]] > >
times = seq(0,20,0.5) pars = c(0.2,0.2,3) names(pars) = c('a','b','c') x0 = c(-1,1) names(x0) = c('V','R') fhn = make.fhn() y = lsoda(x0,times,fhn$fn.ode,pars) y = y[,2:3] w=rnorm(41,.05) z=rnorm(41,.05) g=y+w assign("y", lsoda(x0,times,fhn$fn.ode,pars) ) y=y[,2:3] knots = seq(0,20,0.2) norder = 3 nbasis = length(knots) + norder - 2 range = c(0,20) bbasis = create.bspline.basis(range=range, nbasis=nbasis, norder=norder, breaks=knots) fd.data = array(data,c(nrow(data),1,ncol(data))) m2<- cbind(.29, 1:41) m3=m2[,1] m4<-rbind(m3,m3) m6<- cbind(.29, 1:82) m7<-as.array(m6,dim=c(41,2)) m8<-cbind(.29,1:41) m9<-as.array(m8,dim=c(41,2)) data<-y+m9 fd.data = array(data,c(nrow(data),1,ncol(data))) fd.data = array(data,c(nrow(data),1,ncol(data))) varnames=c("V","R") DEfd = Data2fd(fd.data, times, bbasis, fdnames=list(NULL,NULL,varnames) ) coefs = DEfd$coefs colnames(coefs) = varnames control=list() control$trace = 0 control$maxit = 1000 control$maxtry = 10 control$reltol = 1e-6 control$meth = "BFGS" control.in = control control.in$reltol = 1e-12 control.in$print.level = 0 control.in$iterlim = 1000 control.out = control control.out$trace = 2 lambda = c(10000,10000) res0 = Profile.LS(fhn,data,times,pars,coefs=coefs,basisvals=bbasis, lambda=lambda,in.meth='nlminb',out.meth='ProfileGN', control.in=control.in,control.out=control.out) res1 = Profile.LS(fhn$fn, data, times, pars=spars, coefs=coefs, lambda=lambda, in.meth='nlminb', out.meth='nls', control.in=control.in, control.out=control.out) spars=c(0.3,0.1,2) res1 = Profile.LS(fhn$fn, data, times, pars=spars, coefs=coefs, lambda=lambda, in.meth='nlminb', out.meth='nls', control.in=control.in, control.out=control.out) profile.obj = LS.setup(pars=pars, fn=fhn, basisvals=bbasis, lambda=10000, times=times, fd.obj=DEfd) lik = profile.obj$lik proc = profile.obj$proc qpts = knots qwts = rep(1/length(knots),length(knots)) qwts = qwts %*% t(lambda) weights = array(1,dim(data)) likmore = make.id() likmore$weights = weights lik = make.SSElik() lik$more = likmore lik$bvals = eval.basis(times,bbasis) procmore = make.fhn() procmore$weights = qwts procmore$qpts = qpts procmore$names = varnames parnames=c("a","b","c") procmore$parnames = parnames procmore$parnames = parnames proc = make.SSEproc() proc$more = procmore proc$bvals = list(bvals = eval.basis(procmore$qpts,bbasis,0), dbvals = eval.basis(procmore$qpts,bbasis,1)) spars = c(0.3,0.1,2) res0 = inneropt(coefs, times=times, data=data, lik=lik, proc=proc, pars=spars, in.meth='nlminb', control.in=control.out) ncoefs = res0$coefs res1 = outeropt(data=data, times=times, pars=pars, coefs=coefs, lik=lik, proc=proc, in.meth="nlminb", out.meth="nls", control.in=control.in, control.out=control.out) res2 = outeropt(data=data, times=times, pars=pars, coefs=coefs, lik=lik, proc=proc, in.meth="nlminb", out.meth="nlminb", control.in=control.in, control.out=control.out) Profile.covariance(pars=res1$pars, times=times, data=data, coefs=res1$coefs, lik=lik, proc=proc) data2 = array(0,c(41,2,2)) dim(y) dim(w) m2<- cbind(.29, 1:41) m3=m2[,1] m4<-rbind(m3,m3) m6<- cbind(.29, 1:82) m7<-as.array(m6,dim=c(41,2)) m8<-cbind(.29,1:41) m9<-as.array(m8,dim=c(41,2)) data<-y+m9 data2[,1,] = y+m9 data2[,2,] = y+m9 fd.data2 = array(data2,c(nrow(data2),2,ncol(data2))) DEfd2 = Data2fd(fd.data2, times, bbasis, fdnames=list(NULL,NULL,varnames)) rownames(data2)<-rownames(data2, do.NULL = FALSE, prefix = "Obs.") colnames(data2)[1:2]=c("one","two") varnames(data2)[1:2]=c("V","R") dimnames(data2)=list(rownames(data2),colnames(data2),varnames) data2a<-as.array(data2,dim=c(41,2,2),dimnames=dimnames(data2)) profile2.obj=LS.setup(pars,DEfd2$coefs,fhn,basisvals=bbasis,lambda,fd.obj=NULL, more=NULL,data=data2,weights=NULL,times=times,quadrature=NULL,eps=1e-6, posproc=FALSE,poslik=FALSE,discrete=FALSE,names=NULL,sparse=FALSE) assign("proc", profile2.obj$proc) qpts = knots qwts = rep(1/length(knots),length(knots)) qwts = qwts %*% t(lambda) weights = array(1,dim(data2)) likmore = make.id() likmore$weights = weights lik = make.SSElik() lik$more = likmore lik$bvals = eval.basis(times,bbasis) procmore = make.fhn() procmore$weights = qwts procmore$qpts = qpts procmore$names = varnames procmore$parnames = parnames proc = make.SSEproc() proc$more = procmore proc$bvals = list(bvals = eval.basis(procmore$qpts,bbasis,0), dbvals = eval.basis(procmore$qpts,bbasis,1)) res10 = inneropt(coefs=DEfd2$coefs, times=times, data=data2, lik=lik, proc=proc, pars=spars, in.meth='nlminb', control.in=control.out)
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.