[R] Double Hierarchical Generalized Linear Models

David Winsemius dwinsemius at comcast.net
Thu May 28 02:26:14 CEST 2015


On May 27, 2015, at 10:00 AM, Mariana Velasque wrote:

> I am new modeling and I am trying to analyse my data using the package Double Hierarchical Generalized Linear Models.

> However, I always get the same sort of error:
> 
> Error in z %*% v_h : non-conformable arguments. 

It means the either one or more of those are not matrices or that dim(z)[2] is not equal to dim(v_h)[1]

Cannot multiply matrix and array
> matrix(1:4, 2) %*% array(1:8, c(2,2,2))
Error in matrix(1:4, 2) %*% array(1:8, c(2, 2, 2)) : 
  non-conformable arguments


> matrix(1:4, 2) %*% matrix(1:8, 2)
     [,1] [,2] [,3] [,4]
[1,]    7   15   23   31
[2,]   10   22   34   46

> dim(matrix(1:4, 2))[2] == dim( matrix(1:8, 2))[1]
[1] TRUE

> matrix(1:4, 2) %*% matrix(1:8, 4)
Error in matrix(1:4, 2) %*% matrix(1:8, 4) : non-conformable arguments

Suggests to me that you are sending the function a data layout that it was not designed to handle.


> I think that this error indicates that the matrices are created with non-calculable dimensions, but I don't know how to solve it.
> 
> I am creating my model with two fixed and two random effects. with this format:
> 
> # rm(list=ls(all=TRUE))

Many people think it is rather discourteous to leave this code in without a comment symbol in front of it as a warning.

> library("dhglm")
> 
> data=read.csv("log_data.csv", header=TRUE)

Since we cannot see these 'data', none of the rest of the code will be meaningful other than letting us see that none of your objects had those names. (But perhaps one of your columns was named "z" or "v_h"? The error is apparently not being trapped in the setup process for matrix algebra, so the maintainer is the only person who has a good chance of debugging.  You are advised in the posting guide to first send questions about rarely used packages ... along with the data ... to the package maintainer.


> phi<-matrix(1,n<-nrow(data),1)
> lambda<-matrix(1,n<-nrow(data),1)
> data<-cbind(data,phi,lambda)
> 
> sr <- as.numeric(data$SR)   ##Dependent variable
> 
> id <- as.numeric(data$ID)    ##individual number
>    obs <- as.numeric(data$Obs)    ##Observation number
> 
> o2r <- as.numeric(data$O2R)    ##Fixed factor 1 (oxygen consumption 1)
>    o2a <-as.numeric(data$O2A)    ##Fixed factor 2 (oxygen consumption 2)
> 
> lambda <-as.numeric(data$lambda)
> 
> phi<-as.numeric(data$phi)
> 
> 
> model_mu<-DHGLMMODELING(Model="mean",
> Link="log",
> LinPred= sr~o2a+ o2r + (1|id) + (1|obs),
> RandDist= c("inverse-gamma", "gamma"),
> LinPredRandVariance=lambda~ 1 +(1|id) + (1|obs) ,
> RandDistRandVariance=c("gaussian", "gaussian"))
> 
> model_phi<-DHGLMMODELING(Model="dispersion", 
> Link="log", 
> LinPred = phi~o2a+ o2r + (1|id) + (1|obs), 
> RandDist= c("gaussian", "gaussian"))   
> 
> res_glm<-dhglmfit(RespDist="gaussian",    
>                  DataMain=data,
>                  MeanModel=model_mu,
>                  DispersionModel=model_phi,
>                PhiFix=NULL, LamFix=NULL,mord=1,dord=1,Maxiter=200,convergence=1e-06)
> 
> Mariana Velasque 
> 
> PhD Student 
> Marine Biology & Ecology Research Centre | School of Marine Science and Engineering | 


snipped

> 
> 	[[alternative HTML version deleted]]

Please learn to use your mail client to send plain text. (It's not hard to do this with gmail.)

> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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
Alameda, CA, USA



More information about the R-help mailing list