Adding the predictor variable “H” to a code written for only one predictor variable

15 views Asked by At

I want to add the predictor variable “H” to the code below which already contains the response variable “vol” and another predictor variable “dbh”. #Code:

Dry.vol.hat <- function (dbh.cm, 
    +    ht.dbh.lm = Dry.lm.ld, 
    +    correct = TRUE) { 
    +    Dry.hat <- data.frame(dbh.cm = dbh.cm) 
    +    Dry.hat$log.dbh.cm <- log (Dry.hat$dbh.cm) type here

correction.2 <- ifelse (correct,
    +   exp(summary (ht.dbh.lm)$sigma^2 / 2), 1) 

Dry.hat$vol.m3 <- exp(predict(ht.dbh.lm, newdata = Dry.hat)) * correction.2
   + return(Dry.hat$vol.m3) 
   + } 

#and then use the function 

Dry.vol.hat (value dbh, value H, Dry.lm.ld)

#I tried to fix the code by doing the following:

Dry.vol.hat <- function(dbh.cm, 
    +    H.m, ht.dbh.lm,ht.H.m= Dry.lm.ld, correct = TRUE) { 
    + Dry.hat <- data.frame(dbh.cm = dbh.cm, H.m = H.m) 
    + Dry.hat$log.dbh.cm <- log(Dry.hat$dbh.cm) 

Dry.hat$log.H.m <- log(Dry.hat$H.m) 
    + correction.2 <- ifelse(correct, exp(summary(ht.dbh.lm,ht.H.lm)$sigma^2 / 2), 
    + 1) Dry.hat$vol.m3 <- exp(predict(ht.dbh.lm,ht.H.lm, newdata = Dry.hat)) * correction.2

return(Dry.hat$vol.m3) }

Example usage Dry.vol.hat(10, 5, Dry.lm.ld)

0

There are 0 answers