Hello,

I've put the short version here and if anyone wants to run the code with
CollocInfer, I've given the full version in the file "analysis".

  I come at the question of array attributes and dimnames
 to try to simplify.

In a CollocInfer LS.profile analysis using this array 'Y' constructed
as follows:



w=rnorm(41,.05)
z=rnorm(41,.06)

yX<-cbind(w,z)
y<-as.array(yX)
colnames(y)=c("V","R")

        Y<-array(0,c(41,2,2))
        Y[,1,]=y
        Y[,2,]=y

        

 I receive an error

Error in as.array.default(Y) : attempt to set an attribute on NULL


So I think to name the attributes :

        varnames=c("V","R")

        rownames(Y)<-rownames(Y, do.NULL = FALSE, prefix = "Obs.")
        colnames(Y)[1:2]=c("one","two")

        assign("dimnames(Y)",list(rownames(Y),varnames,colnames(Y)))

        Y2<-as.array(Y,dimnames=dimnames(Y))
        assign("Y",Y2)

then rerun the analysis with the same result

Now traceback() gives:


7: as.array.default(Y)
6: as.array(Y)
5: kronecker(X, Y)
4: kronecker(X, Y)
3: diag(rep(1, nrep)) %x% basisvals$bvals.obs
2: LS.setup(pars, coefs, fn, basisvals, lambda, fd.obj, more, data,
       weights, times, quadrature, eps = 1e-06, posproc, poslik,
       discrete, names, sparse)
1: Profile.LS(fhn, data = data2, times = times, pars = pars, coefs = coefs,
       lambda = lambda, out.meth = "nls", control.in = control.in,
       control.out = control.out)

the first four numbers here(7..4) seem okay when I call each; but in number 3:
calling the given text produces the error:

        error in evaluating the argument 'X' in selecting a method for
function 'kronecker': Error in diag(rep(1, nrep)) :
        error in evaluating the argument 'x' in selecting a method for
function 'diag': Error: object 'nrep' not found

At the outset in the manual, Hooker refers to the diagonal matrix,  it
seems without further explanation:

        In order to demonstrate replicated observations, we make use of another 
set of
        data generated at dierent initial conditions. We then need
concatenate these ob-
        servations in time, and create new values for bvals and weights. The 
function
        diag.block from the simex package is used below, but there are several 
packages
        in R that provide block-diagonal matrices.

I have a feeling this diagonal matrix is a component of R analysis
that, if corrected here,
could produce results, and I would be grateful if anyone who has
experience with its use
could offer some help.

A
Okay here I come at the question of attributes and dimnames
from another direction.


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()
w=rnorm(41,.05)
z=rnorm(41,.06)

yX<-cbind(w,z)
y<-as.array(yX)
colnames(y)=c("V","R")

#a perturbation:#

u=rnorm(41,.02)
v=rnorm(41,.02)

m13=w+u
m14=w+v

m15<-cbind(m13,m14)

data<-m15
 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)))
   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)


#(This is 'y' for an initial analysis of the FhN data.)#


#so far no problem: the arrays 'y' and 'data' are both acceptable

now we want to extend this to two replicates of the data to be analyzed:#

        data2 = array(0,c(41,2,2))

        m16<-rnorm(41,.2)




        m20=cbind(m16,m16)
        m21<-as.array(m20,dim=c(41,2))
        m22<-rnorm(41,.1)
        m20=cbind(m22,m22)
        m23<-as.array(m20,dim=c(41,2))

        data2[,1,]=m21+y
        data2[,2,]=m23+y

        fd.data2 = array(data2,c(nrow(data2),2,ncol(data2)))
        DEfd2 = Data2fd(fd.data2, times, bbasis,
        fdnames=list(NULL,NULL,varnames))
        res3 = Profile.LS(fhn, data=data2, times=times, pars=pars,
        coefs=coefs, lambda=lambda, out.meth='nls',
        control.in=control.in, control.out=control.out)

#Rather than parameter estimates, as with the single replicate analysis, this 
produces the error:

        Error in as.array.default(Y) : attempt to set an attribute on NULL
  
So thinking that the dimnames of either array are the "NULL" that R is 
referring to, 
I supply dimnames to the two arrays involved, data2, and y:#

        rownames(data2)<-rownames(data2, do.NULL = FALSE, prefix = "Obs.")
        colnames(data2)[1:2]=c("one","two")

        dimnames(data2)=list(rownames(data2),colnames(data2),varnames)
        data2a<-as.array(data2,dim=c(41,2,2),dimnames=dimnames(data2))

        assign("data2",data2a)

        Y<-array(0,c(41,2,2))
         Y[,1,]=y
         Y[,2,]=y


#Then rerun the analysis with same result.

Now traceback() gives:#


        7: as.array.default(Y)
        6: as.array(Y)
        5: kronecker(X, Y)
        4: kronecker(X, Y)
        3: diag(rep(1, nrep)) %x% basisvals$bvals.obs
        2: LS.setup(pars, coefs, fn, basisvals, lambda, fd.obj, more, data, 
       weights, times, quadrature, eps = 1e-06, posproc, poslik, 
       discrete, names, sparse)
        1: Profile.LS(fhn, data = data2, times = times, pars = pars, coefs = 
coefs, 
       lambda = lambda, out.meth = "nls", control.in = control.in, 
       control.out = control.out)

#the first four numbers here(7..4) seem okay when I call each; but in number 3:
calling the given text produces the error:

        error in evaluating the argument 'X' in selecting a method for function 
'kronecker': Error in diag(rep(1, nrep)) : 
        error in evaluating the argument 'x' in selecting a method for function 
'diag': Error: object 'nrep' not found

At the outset in the manual, Hooker refers to the diagonal matrix,  it seems 
without further explanation:

        In order to demonstrate replicated observations, we make use of another 
set of
        data generated at dierent initial conditions. We then need concatenate 
these ob-
        servations in time, and create new values for bvals and weights. The 
function
        diag.block from the simex package is used below, but there are several 
packages
        in R that provide block-diagonal matrices.

I have a feeling this diagonal matrix is a component of R analysis that, if 
corrected here,
could produce results, and I would be grateful if anyone who has experience 
with its use
could offer some help.

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.

Reply via email to