Re: [R] Error in dimnames(x) for Poisson EWMA model

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Wed, 20 Apr 2011 15:56:01 -0400

On Apr 20, 2011, at 3:05 PM, Ashley E. Jochim wrote:

> I am attempting to run a Poisson EWMA model using Patrick Brandt's
> source code. I get the following error when I run the code:
>
> Error in dimnames(x) <- dn :
> length of 'dimnames' [1] not equal to array extent
>
> Dimnames(x) looks like this:
>
> [[1]]
> NULL
>
> [[2]]
> [1] "mip" "div" "nom" "unity" "mood"
> "times"
> [7] "hmajparty" "smajparty" "pres"
>
> It seems to me that the NULL value here is causing the problem but I
> can't figure out (1) why the null value is showing up and (2) how to
> get rid of it. Background code is as follows:
>
> cr.pois<- glm(countlaw ~ mip + div + nom + unity + mood + times +
> hmajparty + smajparty + pres, family = poisson)
> summary(cr.pois)
>
> init <- coef(cr.pois)
>
> x<- cbind(mip,div,nom,unity,mood,times,hmajparty,smajparty,pres)

This returns a matrix, i.e an object with two dimensions and dimnames returns a list with two character vectors (one of which is null.

 > a = 1
 > b=2
 > cc=3
 > cbind(a,b,cc)
      a b cc

[1,] 1 2 3
 > dim(cbind(a,b,cc))
[1] 1 3
 > dimnames(cbind(a,b,cc))
[[1]]
NULL [[2]]
[1] "a" "b" "cc"

If you wanted to assert that the other dimname should be something then you need to insert a value into just the first element:

dimnames(x)[[1]] <- "something"

E.g.:

 > dimnames(x)[[1]] <- "something"
 > x

           a b cc
something 1 2 3

>
> cr.PEWMA<-
> Pewma
> (y=countlaw,x=as.matrix(x),init.param=c(0.8,init[2:length(init)]))

Not sure why the error occurs. This appears to be using a package which you have chosen not to name.

-- 
David.



>
> Which results in this output:
>
> N = 10, M = 5 machine precision = 2.22045e-16
>
> iterations 34
> function evaluations 45
> segments explored during Cauchy searches 35
> BFGS updates skipped 0
> active bounds at final generalized Cauchy point 1
> norm of the final projected gradient 0.00806577
> final function value 1.78439
>
> final value 1.784390
> converged
> Error in dimnames(x) <- dn :
> length of 'dimnames' [1] not equal to array extent
>
> Any thoughts on what's going on here and how to fix it?
>
> Many thanks in advance.
>
> Ashley
> --
> Ashley E. Jochim
> Graduate Fellow
> Center for American Politics & Public Policy
> Department of Political Science
> University of Washington
> aew9_at_u.washington.edu
> http://students.washington.edu/aew9
>
> ______________________________________________
> R-help_at_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.
David Winsemius, MD West Hartford, CT ______________________________________________ R-help_at_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.
Received on Wed 20 Apr 2011 - 19:58:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Apr 2011 - 20:20:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive