Return of the original scale in a prediction function

Asked

Viewed 144 times

2

I created a simple function to perform prediction of tree heights through regression models built for this purpose (symmetric relation models). The function predicts the heights, and inserts them in a new column in the date.frame by merging them with the heights used to adjust the model, but some models of the symmetric ratio change the original scale of the heights (response variable)such as models that use log. Would have some way to make the function predict ( for example), return the values in the original scale, identifying in the model the scale change factor?

The function is as follows :

pp <-           
  function(model,data)
  { 
{
  vetor <- data[is.na(data$AltMed),]        
  vetor <- predict (model,vetor)    

  data$ALTMISTA <- data$AltMed          
  data$ALTMISTA[is.na(data$ALTMISTA)] <- vetor
}

return (data)       
}

The models I’m encountering are as follows::

modelo 1 = lm(log(Altura) ~ I(1/Dap) + log(AlturaD), data=data)

modelo 2 = nls(I(Altura/AlturaD) ~ a1*(1-a2*exp(-a3*I(Dap/Q))), data=data, start=list(a1=3.348296, a2=-11.675862, a3=1.88852))

These models change the scale of the response variable.

  • Yes, I would, but without a concrete example it’s practically impossible to help.

  • You can see about a reproducible example here: http://meta.pt.stackoverflow.com/questions/824/como-crea-um-exemplo-m%C3%Adnimo-reproduces%C3%Advel-em-r/825#825

  • Hello, I edited my question.

  • 1

    @Forestry, your example is not reproducible. Ideally I could copy and paste your code and see what the problem is. I won’t be able to generate your model without your data. The ideal would be to generate a small data.frame per simulation, make a small model and show your problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.