[R] diagonal matrix, array attributes and how to keep from setting an attribute on "NULL"

aleksandr russell sss736 at gmail.com
Fri Aug 24 11:50:53 CEST 2012


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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: analysis.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120824/19f49f7b/attachment.txt>


More information about the R-help mailing list