0

R ggplot linear regression model containing log function - is this valid, are we allowed to perform linear regression on model whereby both dependent and independent variable contains log terms.

Example:

mdl1 <- lm(log(abs(y)) ~ log(abs(x1)) + log(abs(x2)) + x3 + x4, data)

predicted_mdl1 <- data %>%
  data_grid(x1, # parameter to check the effect on the model
            x2=1, #log term set to 1 to make it zero
            x3, # categorical variable
            x4) %>%
  add_predictions(mdl1)

predicted_mdl1 %>% 
  ggplot(aes(x = log(x1), y = pred, color = factor(x3))
  )

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295
learning
  • 47
  • 6
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What additional packages are you using besides `ggplot2` here? What exactly is your question? – MrFlick Dec 13 '20 at 06:45
  • Hi, I'm trying to fit in a linear regression line to show relationship between x and y variable, wondering whether its is a valid expectation to fit a linear regression line for variable containing log terms. Packages used: modelr, ggplot2 – learning Dec 13 '20 at 06:56
  • 1
    Who determines what's "valid"? Is this a statistical question? If so, then you should ask at [stats.se] instead. I don't see a specific programming question here that's appropriate for Stack Overflow. – MrFlick Dec 13 '20 at 06:59

0 Answers0