In the 'doBy' package there is an esticon() function for calculating linear 
contrasts for various model types. I have defined an S3-method 'esticon.mer()' 
for 'mer' objects from the lme4 package. Building the package and invoking the 
method gives:

> esticon(fm1, c(1,1))
Confidence interval ( WALD ) level = 0.95
Error in as.integer(x) :
  cannot coerce type 'S4' to vector of type 'integer'
However, if is source the source code into R then I get what I expected:
> esticon(fm1, c(1,1))
Confidence interval ( WALD ) level = 0.95
  beta0 Estimate Std.Error X2.value DF Pr(>|X^2|) Lower.CI Upper.CI
1     0 261.8724  6.786701 1488.888  1          0 248.5707 275.1741
The problem above arises because esticon.mer() uses the variance-covariance 
matrix of the fixed effects (vcv below) in a calculation (cm is a matrix):
  cm %*% vcv %*% t(cm). The result is:

1 x 1 Matrix of class "dgeMatrix"
         [,1]
[1,] 46.05931
- and taking diag() of that matrix causes the error above... However, things 
work fine if I use as.matrix() as is:  diag(as.matrix(cm %*% vcv %*% t(cm))).

- This tentatively suggests that there is no diag() method for 'dgeMatrix' 
objects (can hardly be the case!), but why then does my code work when it is 
sourced into R???

- Does anyone have an idea about what goes wrong? )

- Is there anything 'special' that one must do in connection with defining 
S3-methods for S4 objects (e.g. in connection with package building)??

I use R 2.9.2 on windows XP. I am sure that such issues must have come up for 
others in the past but I've been unable to find questions/answers in the 
archives. Sorry if the topic has already been covered.

Regards
Søren Højsgaard


        [[alternative HTML version deleted]]

______________________________________________
[email protected] 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