<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Dear Bruce,</p>
    <p>thanks for catching this bug!</p>
    <p>The functions below should solve this problem. They will be
      incorporated in the next version of IPMpack. The following two
      lines should work with these new functions:</p>
    <p><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Console'; font-size: 17px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20px; orphans: 2; text-align: -webkit-left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(225, 226, 229); "><pre tabindex="0" class="GAKS5OJBBCB" id="rstudio_console_output" style="font-family: 'Lucida Console'; font-size: 13pt !important; outline-style: none; outline-width: initial; outline-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; white-space: pre-wrap !important; word-break: break-all; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; -webkit-user-select: text; line-height: 1.2; "><span class="GAKS5OJBIBB ace_keyword" style="color: rgb(127, 0, 85); ">makeSurvObj(Formula = surv ~ size, coeff = c(1,1))
</span><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Lucida Console'; font-size: 17px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20px; orphans: 2; text-align: -webkit-left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(225, 226, 229); "><pre tabindex="0" class="GAKS5OJBBCB" id="rstudio_console_output" style="font-family: 'Lucida Console'; font-size: 13pt !important; outline-style: none; outline-width: initial; outline-color: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; white-space: pre-wrap !important; word-break: break-all; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; -webkit-user-select: text; line-height: 1.2; "><span class="GAKS5OJBIBB ace_keyword" style="color: rgb(127, 0, 85); ">makeSurvObj(Formula = surv ~ -1 + size, coeff = c(1))</span></pre></span>
</pre></span></p>
    <p>cheers,<br>
      Eelke</p>
    <p><br>
    </p>
    <p>.createSurvObj <- function (Formula = surv ~ size, coeff =
      c(1, 1)) <br>
      {<br>
        var.names <- attr(terms(Formula),"term.labels")<br>
        if (attr(terms(Formula),"intercept")==1) var.names
      <-c("(Intercept)",var.names)<br>
        if (length(coeff) != (length(var.names))) stop("not enough
      coefficients supplied for the chosen Formula")<br>
        dataf <- as.data.frame(matrix(rnorm(21 * length(var.names)),
      21, length(var.names)))<br>
        colnames(dataf) <- var.names<br>
        dataf$surv <- sample(c(0, 1), nrow(dataf), replace = TRUE)<br>
        fit <- glm(Formula, data = dataf, family = binomial)<br>
        sv1 <- new("survObj")<br>
        sv1@fit <- fit<br>
        for (i in 1:length(coeff)) sv1@fit$coefficients[[i]] <-
      coeff[i]<br>
        return(sv1)<br>
      }<br>
      <br>
      .createGrowthObj <- function (Formula = sizeNext ~ size, coeff
      = c(1, 1), sd = 1) <br>
      {<br>
        var.names <- attr(terms(Formula),"term.labels")<br>
        if (attr(terms(Formula),"intercept")==1) var.names
      <-c("(Intercept)",var.names)<br>
        if (length(coeff) != (length(var.names))) stop("not enough
      coefficients supplied for the chosen Formula")<br>
        dataf <- as.data.frame(matrix(rnorm(21 *
      (length(all.vars(Formula)))), 21, length(all.vars(Formula))))<br>
        colnames(dataf) <- all.vars(Formula)<br>
        fit <- lm(Formula, data = dataf)<br>
        if (length(grep("sizeNext", as.character(Formula))) > 0) {<br>
          gr1 <- new("growthObj")<br>
          gr1@fit <- fit<br>
          for (i in 1:length(coeff)) gr1@fit$coefficients[i] <-
      coeff[i]<br>
          gr1@sd <- sd<br>
        }<br>
        if (length(grep("incr", as.character(Formula))) > 0) {<br>
          gr1 <- new("growthObjIncr")<br>
          gr1@fit <- fit<br>
          for (i in 1:length(coeff)) gr1@fit$coefficients[i] <-
      coeff[i]<br>
          gr1@sd <- sd<br>
        }<br>
        return(gr1)<br>
      }<br>
      <br>
      makeSurvObj <- function (dataf = NULL, Formula = surv ~ size +
      size2, coeff = NULL) <br>
      {<br>
        if (!is.null(dataf)) {<br>
          dataf <- subset(dataf, is.na(dataf$surv) == FALSE)<br>
          if (length(dataf$offspringNext) > 0) dataf <-
      subset(dataf, !dataf$offspringNext %in% c("sexual", "clonal"))<br>
          dataf$size2 <- dataf$size^2<br>
          dataf$size3 <- dataf$size^3<br>
          if (length(grep("expsize", as.character(Formula))) > 0) <br>
            dataf$expsize <- exp(dataf$size)<br>
          if (length(grep("logsize", as.character(Formula))) > 0) <br>
            dataf$logsize <- log(dataf$size)<br>
          if ("covariate" %in% unlist(strsplit(as.character(Formula),
      "[+-\\* ]")) & length(dataf$covariate) > 0) {<br>
            dataf$covariate <- as.factor(dataf$covariate)<br>
            levels(dataf$covariate) <-
      1:length(unique(dataf$covariate))<br>
          }<br>
          if ("covariateNext" %in%
      unlist(strsplit(as.character(Formula), "[+-\\* ]")) &
      length(dataf$covariateNext) > 0) {<br>
            dataf$covariateNext <- as.factor(dataf$covariateNext)<br>
            levels(dataf$covariateNext) <-
      1:length(unique(dataf$covariateNext))<br>
          }<br>
          if (length(intersect(all.vars(Formula), colnames(dataf))) <
      length(all.vars(Formula))) <br>
            print("warning: not all variables in the formula are present
      in dataf; model cannot be fit")<br>
          fit <- glm(Formula, family = binomial, data = dataf)<br>
          sv1 <- new("survObj")<br>
          sv1@fit <- fit<br>
        }<br>
        else {<br>
          if (is.null(coeff)) stop("require coefficients if data is not
      supplied")<br>
          sv1 <- .createSurvObj(Formula = Formula, coeff = coeff)<br>
        }<br>
        return(sv1)<br>
      }<br>
      <br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 22-Aug-16 7:01 PM, Bruce Kendall
      wrote:<br>
    </div>
    <blockquote
      cite="mid:0AA4B4D5-E039-429B-8D9B-FAC937F21221@bren.ucsb.edu"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      I think I've found a bug in makeSurvObj(). When building a
      function without data (i.e., by specifying values for coeff), the
      specified coefficients are not actually applied to the model.
      <div class=""><br class="">
      </div>
      <div class="">To reproduce this, run the following code multiple
        times and notice the inconsistent coefficients:</div>
      <div class=""><br class="">
      </div>
      <div class="">makeSurvObj(Formula = surv ~ -1 + size, coeff =
        c(1,1))</div>
      <div class=""><br class="">
      </div>
      <div class="">The problem seems to be in .createSurvObj(), which,
        unlike .createGrowthObj() and .createFecObj(), does not update
        the coefficients in the fit slot after fitting the model to
        dummy data.</div>
      <div class=""><br class="">
      </div>
      <div class="">I should also point out that this function often
        throws a warning, because when the dummy survivals are all zero
        or all one then "glm.fit: fitted probabilities numerically 0 or
        1 occurred " results. This could be avoided by assigning, say,
        c(0,1,1) for the survival dummies.</div>
      <div class=""><br class="">
      </div>
      <div class="">Best,</div>
      <div class="">Bruce</div>
      <div class=""><br class="">
        <div class="">
          <div style="color: rgb(0, 0, 0); letter-spacing: normal;
            orphans: auto; text-align: start; text-indent: 0px;
            text-transform: none; white-space: normal; widows: auto;
            word-spacing: 0px; -webkit-text-stroke-width: 0px;
            word-wrap: break-word; -webkit-nbsp-mode: space;
            -webkit-line-break: after-white-space;" class="">
            <div style="color: rgb(0, 0, 0); letter-spacing: normal;
              orphans: auto; text-align: start; text-indent: 0px;
              text-transform: none; white-space: normal; widows: auto;
              word-spacing: 0px; -webkit-text-stroke-width: 0px;
              word-wrap: break-word; -webkit-nbsp-mode: space;
              -webkit-line-break: after-white-space;" class="">
              <div style="color: rgb(0, 0, 0); letter-spacing: normal;
                orphans: auto; text-align: start; text-indent: 0px;
                text-transform: none; white-space: normal; widows: auto;
                word-spacing: 0px; -webkit-text-stroke-width: 0px;
                word-wrap: break-word; -webkit-nbsp-mode: space;
                -webkit-line-break: after-white-space;" class="">
                <div style="color: rgb(0, 0, 0); letter-spacing: normal;
                  orphans: auto; text-align: start; text-indent: 0px;
                  text-transform: none; white-space: normal; widows:
                  auto; word-spacing: 0px; -webkit-text-stroke-width:
                  0px; word-wrap: break-word; -webkit-nbsp-mode: space;
                  -webkit-line-break: after-white-space;" class="">
                  <div style="orphans: auto; text-align: start;
                    text-indent: 0px; widows: auto; word-wrap:
                    break-word; -webkit-nbsp-mode: space;
                    -webkit-line-break: after-white-space;" class="">
                    <div style="orphans: auto; text-align: start;
                      text-indent: 0px; widows: auto; word-wrap:
                      break-word; -webkit-nbsp-mode: space;
                      -webkit-line-break: after-white-space;" class="">
                      <div style="orphans: auto; text-align: start;
                        text-indent: 0px; widows: auto; word-wrap:
                        break-word; -webkit-nbsp-mode: space;
                        -webkit-line-break: after-white-space;" class="">
                        <div style="orphans: auto; text-align: start;
                          text-indent: 0px; widows: auto; word-wrap:
                          break-word; -webkit-nbsp-mode: space;
                          -webkit-line-break: after-white-space;"
                          class="">
                          <div style="orphans: auto; text-align: start;
                            text-indent: 0px; widows: auto; word-wrap:
                            break-word; -webkit-nbsp-mode: space;
                            -webkit-line-break: after-white-space;"
                            class="">
                            <div style="orphans: auto; text-align:
                              start; text-indent: 0px; widows: auto;
                              word-wrap: break-word; -webkit-nbsp-mode:
                              space; -webkit-line-break:
                              after-white-space;" class="">
                              <div style="orphans: auto; text-align:
                                start; text-indent: 0px; widows: auto;
                                word-wrap: break-word;
                                -webkit-nbsp-mode: space;
                                -webkit-line-break: after-white-space;"
                                class="">
                                <div style="orphans: auto; text-align:
                                  start; text-indent: 0px; widows: auto;
                                  word-wrap: break-word;
                                  -webkit-nbsp-mode: space;
                                  -webkit-line-break:
                                  after-white-space;" class="">
                                  <div style="orphans: auto; text-align:
                                    start; text-indent: 0px; widows:
                                    auto; word-wrap: break-word;
                                    -webkit-nbsp-mode: space;
                                    -webkit-line-break:
                                    after-white-space;" class="">
                                    <div style="orphans: auto;
                                      text-align: start; text-indent:
                                      0px; widows: auto; word-wrap:
                                      break-word; -webkit-nbsp-mode:
                                      space; -webkit-line-break:
                                      after-white-space;" class="">
                                      <div style="orphans: auto;
                                        text-align: start; text-indent:
                                        0px; widows: auto; word-wrap:
                                        break-word; -webkit-nbsp-mode:
                                        space; -webkit-line-break:
                                        after-white-space;" class="">
                                        <div style="color: rgb(0, 0, 0);
                                          letter-spacing: normal;
                                          text-transform: none;
                                          white-space: normal;
                                          word-spacing: 0px;
                                          -webkit-text-stroke-width:
                                          0px;" class="">--</div>
                                        <div style="color: rgb(0, 0, 0);
                                          letter-spacing: normal;
                                          text-transform: none;
                                          white-space: normal;
                                          word-spacing: 0px;
                                          -webkit-text-stroke-width:
                                          0px;" class="">Bruce Kendall</div>
                                        <div style="color: rgb(0, 0, 0);
                                          letter-spacing: normal;
                                          text-transform: none;
                                          white-space: normal;
                                          word-spacing: 0px;
                                          -webkit-text-stroke-width:
                                          0px;" class=""><a
                                            moz-do-not-send="true"
                                            href="mailto:kendall@bren.ucsb.edu"
                                            class="">kendall@bren.ucsb.edu</a></div>
                                        <div style="color: rgb(0, 0, 0);
                                          letter-spacing: normal;
                                          text-transform: none;
                                          white-space: normal;
                                          word-spacing: 0px;
                                          -webkit-text-stroke-width:
                                          0px;" class=""><a
                                            moz-do-not-send="true"
                                            href="http://kendall.bren.ucsb.edu"
                                            class="">http://kendall.bren.ucsb.edu</a> </div>
                                        <div style="color: rgb(0, 0, 0);
                                          letter-spacing: normal;
                                          text-transform: none;
                                          white-space: normal;
                                          word-spacing: 0px;
                                          -webkit-text-stroke-width:
                                          0px;" class="">Skype:
                                          brucekendall64</div>
                                        <div style="color: rgb(0, 0, 0);
                                          letter-spacing: normal;
                                          text-transform: none;
                                          white-space: normal;
                                          word-spacing: 0px;
                                          -webkit-text-stroke-width:
                                          0px;" class=""><br class="">
                                        </div>
                                        <div style="color: rgb(0, 0, 0);
                                          letter-spacing: normal;
                                          text-transform: none;
                                          white-space: normal;
                                          word-spacing: 0px;
                                          -webkit-text-stroke-width:
                                          0px;" class="">           
                                           #########################################</div>
                                        <div style="color: rgb(0, 0, 0);
                                          letter-spacing: normal;
                                          text-transform: none;
                                          white-space: normal;
                                          word-spacing: 0px;
                                          -webkit-text-stroke-width:
                                          0px;" class="">           
                                           ####   I am on sabbatical
                                          through Sept 2016   ####</div>
                                        <div style="color: rgb(0, 0, 0);
                                          letter-spacing: normal;
                                          text-transform: none;
                                          white-space: normal;
                                          word-spacing: 0px;
                                          -webkit-text-stroke-width:
                                          0px;" class="">
                                          <div class="">           
                                             #########################################</div>
                                          <div class=""><br class="">
                                          </div>
                                          <div style="border: 0px;
                                            margin: 0px; padding: 0px;
                                            line-height: 18px;
                                            font-family: Arial,
                                            Helvetica, sans-serif;"
                                            class="">
                                            <div style="font-family:
                                              Helvetica; line-height:
                                              normal;" class="">=============================</div>
                                          </div>
                                        </div>
                                        <div style="border: 0px; margin:
                                          0px; padding: 0px;" class="">
                                          <div style="color: rgb(0, 0,
                                            0); letter-spacing: normal;
                                            text-transform: none;
                                            white-space: normal;
                                            word-spacing: 0px;
                                            -webkit-text-stroke-width:
                                            0px; font-family: Helvetica;
                                            line-height: normal;"
                                            class="">
                                            <div class="">Address
                                              through Aug. 2016:</div>
                                            <div class="">—————————————————</div>
                                            <div class="">Department of
                                              Zoology<br class="">
                                              University of Oxford<br
                                                class="">
                                              The Tinbergen Building<br
                                                class="">
                                              South Parks Road<br
                                                class="">
                                              Oxford<br class="">
                                              OX1 3PS<br class="">
                                              United Kingdom</div>
                                            <div class="">Tel:  <span
                                                class="Apple-converted-space"> </span><span class="Apple-tab-span" style="white-space: pre;">      </span>+44
                                              (0)1865 271139</div>
                                            <div class="">Mob:<span
                                                class="Apple-converted-space"> </span><span class="Apple-tab-span" style="white-space: pre;">      </span>+44
                                              (0)7534 514781</div>
                                            <div class="">Home:<span class="Apple-tab-span" style="white-space: pre;">        </span>+44
                                              (0)1865 515349</div>
                                          </div>
                                          <div style="color: rgb(0, 0,
                                            0); letter-spacing: normal;
                                            text-transform: none;
                                            white-space: normal;
                                            word-spacing: 0px;
                                            -webkit-text-stroke-width:
                                            0px; font-family: Helvetica;
                                            line-height: normal;"
                                            class=""><br class="">
                                          </div>
                                          <div class="">
                                            <div style="color: rgb(0, 0,
                                              0); font-family:
                                              Helvetica; letter-spacing:
                                              normal; line-height:
                                              normal; text-transform:
                                              none; white-space: normal;
                                              word-spacing: 0px;
                                              -webkit-text-stroke-width:
                                              0px;" class="">
                                              <div style="border: 0px;
                                                margin: 0px; padding:
                                                0px; line-height: 18px;
                                                font-family: Arial,
                                                Helvetica, sans-serif;"
                                                class="">
                                                <div style="font-family:
                                                  Helvetica;
                                                  line-height: normal;"
                                                  class=""><br class="">
                                                </div>
                                              </div>
                                            </div>
                                          </div>
                                          <div style="color: rgb(0, 0,
                                            0); letter-spacing: normal;
                                            text-transform: none;
                                            white-space: normal;
                                            word-spacing: 0px;
                                            -webkit-text-stroke-width:
                                            0px;" class="">
                                            <div style="font-family:
                                              Helvetica; line-height:
                                              normal;" class="">===========================================</div>
                                          </div>
                                          <div style="color: rgb(0, 0,
                                            0); letter-spacing: normal;
                                            text-transform: none;
                                            white-space: normal;
                                            word-spacing: 0px;
                                            -webkit-text-stroke-width:
                                            0px;" class="">
                                            <div class="">Permanent
                                              address:</div>
                                            <div class="">—————————————————————————</div>
                                          </div>
                                          <div style="color: rgb(0, 0,
                                            0); letter-spacing: normal;
                                            text-transform: none;
                                            white-space: normal;
                                            word-spacing: 0px;
                                            -webkit-text-stroke-width:
                                            0px;" class=""><span
                                              style="orphans: 2; widows:
                                              2;" class="">Bren School
                                              of Environmental Science</span><span
                                              style="orphans: 2; widows:
                                              2;" class=""> & Management</span></div>
                                          <div style="color: rgb(0, 0,
                                            0); letter-spacing: normal;
                                            text-transform: none;
                                            white-space: normal;
                                            word-spacing: 0px;
                                            -webkit-text-stroke-width:
                                            0px;" class=""><span
                                              style="orphans: 2; widows:
                                              2;" class="">University of
                                              California, Santa Barbara</span><br
                                              style="orphans: 2; widows:
                                              2;" class="">
                                            <span style="orphans: 2;
                                              widows: 2;" class="">Santa
                                              Barbara, CA 93106-5131</span></div>
                                          <div style="color: rgb(0, 0,
                                            0); letter-spacing: normal;
                                            text-transform: none;
                                            white-space: normal;
                                            word-spacing: 0px;
                                            -webkit-text-stroke-width:
                                            0px;" class="">USA<br
                                              style="orphans: 2; widows:
                                              2;" class="">
                                            <span style="orphans: 2;
                                              widows: 2;" class="">Tel:
                                              +1 (805) 893-7539</span></div>
                                          <div style="color: rgb(0, 0,
                                            0); letter-spacing: normal;
                                            text-transform: none;
                                            white-space: normal;
                                            word-spacing: 0px;
                                            -webkit-text-stroke-width:
                                            0px; orphans: 2; widows: 2;"
                                            class="">
                                            <div style="orphans: auto;
                                              widows: auto;" class="">===========================================</div>
                                          </div>
                                        </div>
                                      </div>
                                    </div>
                                    <br
                                      class="Apple-interchange-newline">
                                  </div>
                                  <br class="Apple-interchange-newline">
                                </div>
                                <br class="Apple-interchange-newline">
                              </div>
                              <br class="Apple-interchange-newline">
                            </div>
                            <br class="Apple-interchange-newline">
                          </div>
                          <br class="Apple-interchange-newline">
                        </div>
                        <br class="Apple-interchange-newline">
                      </div>
                      <br class="Apple-interchange-newline">
                    </div>
                    <br class="Apple-interchange-newline">
                  </div>
                  <br class="Apple-interchange-newline">
                </div>
                <br class="Apple-interchange-newline">
              </div>
              <br class="Apple-interchange-newline">
            </div>
            <br class="Apple-interchange-newline">
          </div>
          <br class="Apple-interchange-newline">
          <br class="Apple-interchange-newline">
        </div>
        <br class="">
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
IPMpack-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:IPMpack-users@lists.r-forge.r-project.org">IPMpack-users@lists.r-forge.r-project.org</a>
<a class="moz-txt-link-freetext" href="http://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/ipmpack-users">http://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/ipmpack-users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>