I am working with a dataset that contains:
- a dependent variable (DV) taking both positive and negative values
- a binary independent variable (IV).
And I'm interested in the following specification:
$ ln(DV) = \beta\cdot IV + \epsilon $
The issue is that $ln(DV)$ is undefined where $DV \le 0$.
I've read that a common workaround is to subtract the minimum value of $DV$ (a negative number) from all DV values to ensure all values of the $DV$ are positive. However, whilst this does not affect the statistical significance of $\beta$, it results in an estimate smaller than its true value (see illustration below).
I'm wondering whether there is a standard procedure to adjust $\beta$ to reflect its true value.
# Load packages
library(tidyverse)
library(broom)
options(scipen = 9999999)
# Case where negative values are present. Estimated beta ~= .0057
# Create Dataframe described above
df1 <-
# Create DV
data_frame(DV = rnorm(n = 1000000,10, 3)) %>%
# Create IV
mutate(IV = row_number() %in% sample(row_number(),max(row_number())/2,replace = F)) %>%
# Introduce effect of IV on DV
mutate(DV = DV + 0.01*abs(DV)*IV) %>%
mutate(DV = DV + abs(min(DV- 1)))
# Estimate beta
lm(log(DV)~ IV,data = df1) %>% broom::tidy()
#> # A tibble: 2 x 5
#> term estimate std.error statistic p.value
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 2.67 0.000306 8725. 0.
#> 2 IVTRUE 0.00665 0.000433 15.4 2.60e-53
# Case where negative values are not present. Estimated beta ~= .01
# Create Dataframe described above
df2 <-
# Create DV
data_frame(DV = rnorm(n = 1000000,mean = 10,1.5)) %>%
# Create IV
mutate(IV = row_number() %in% sample(row_number(),max(row_number())/2,replace = F)) %>%
# Introduce effect of IV on DV
mutate(DV = DV + 0.01*DV*IV)
# Estimate beta
lm(log(DV)~ IV,data = df2) %>% broom::tidy()
#> # A tibble: 2 x 5
#> term estimate std.error statistic p.value
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 2.29 0.000219 10475. 0.
#> 2 IVTRUE 0.0101 0.000309 32.6 3.09e-233
Created on 2018-11-28 by the reprex package (v0.2.1)
DV
was negative and got reasonable estimates with a log link. So I don't know why yourglm
is dropping observations. $\endgroup$