]> git.donarmstrong.com Git - ape.git/blobdiff - R/compar.gee.R
new operators for "multiPhylo" + fixed small bug in bind.tree()
[ape.git] / R / compar.gee.R
index ecaa79aa9235a7cc5667101f261e3a9603f10725..488379c4b00d52775651515b4c3cba090790ba30 100644 (file)
@@ -1,8 +1,8 @@
-## compar.gee.R (2006-10-11)
+## compar.gee.R (2008-02-21)
 
 ##   Comparative Analysis with GEEs
 
-## Copyright 2002-2006 Emmanuel Paradis
+## Copyright 2002-2008 Emmanuel Paradis
 
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
@@ -10,6 +10,7 @@
 compar.gee <- function(formula, data = NULL, family = "gaussian", phy,
                        scale.fix = FALSE, scale.value = 1)
 {
+    require(gee, quietly = TRUE)
     if (is.null(data)) data <- parent.frame() else {
         if(!any(is.na(match(rownames(data), phy$tip.label))))
           data <- data[phy$tip.label, ]
@@ -19,18 +20,19 @@ do not match: the former were ignored in the analysis.")
     effect.assign <- attr(model.matrix(formula, data = data), "assign")
     for (i in all.vars(formula)) {
         if (any(is.na(eval(parse(text = i), envir = data))))
-          stop("the present method cannot (yet) be used directly with missing data: you may consider removing the species with missing data from your tree with the function `drop.tip'.")
+          stop("the present method cannot (yet) be used directly with missing data: you may consider removing the species with missing data from your tree with the function 'drop.tip'.")
     }
-    if (is.null(phy$edge.length))
-      stop("the tree has no branch lengths.")
+    if (is.null(phy$edge.length)) stop("the tree has no branch lengths.")
     R <- vcv.phylo(phy, cor = TRUE)
     id <- rep(1, dim(R)[1])
     geemod <- do.call("gee", list(formula, id, data = data, family = family, R = R,
                                   corstr = "fixed", scale.fix = scale.fix,
                                   scale.value = scale.value))
     W <- geemod$naive.variance
-    if (family == "binomial")
-      W <- summary(glm(formula, family = quasibinomial, data = data))$cov.scaled
+    fname <-
+        if (is.function(family)) deparse(substitute(family)) else family
+    if (fname == "binomial")
+        W <- summary(glm(formula, family = quasibinomial, data = data))$cov.scaled
     N <- geemod$nobs
     dfP <- sum(phy$edge.length)*N / sum(diag(vcv.phylo(phy)))
     obj <- list(call = geemod$call,