2
$\begingroup$

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)

$\endgroup$
  • 1
    $\begingroup$ What about using a glm with a log link? Also: What is your ultimate goal? Why do you need to transform the DV logarithmically? $\endgroup$ – COOLSerdash Nov 28 '18 at 9:28
  • $\begingroup$ I'm taking the logarithm because I'm interested in estimating the effect of the independent variable on growth of the dependent variable. $\endgroup$ – Ian Nov 28 '18 at 9:46
  • $\begingroup$ Have looked into glm with log link and it seems to be working - thanks! $\endgroup$ – Ian Nov 28 '18 at 9:54
  • $\begingroup$ After a second look, I can see that the log link is still dropping observations where DV is negative, so I'm still looking for an approach that keeps all observations and gives the actual value of $\beta$ $\endgroup$ – Ian Nov 30 '18 at 20:48
  • 1
    $\begingroup$ By the way: The log-link shouldn't drop negative values. I was able to construct several examples where DV was negative and got reasonable estimates with a log link. So I don't know why your glm is dropping observations. $\endgroup$ – COOLSerdash Nov 30 '18 at 22:18
1
$\begingroup$
library(tidyverse)
library(broom)
options(scipen = 9999999)

df3 <- 
  # Create DV
  data_frame(DV = rnorm(n = 1000000,mean = 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*DV*IV)


glm(DV~IV, family=gaussian(link="log"), data=df3,start = c(0,0) ) %>% 
  broom::tidy()
#> # A tibble: 2 x 5
#>   term        estimate std.error statistic  p.value
#>   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
#> 1 (Intercept)  2.30     0.000426    5403.  0.      
#> 2 IVTRUE       0.00994  0.000600      16.6 1.21e-61

Created on 2018-12-01 by the reprex package (v0.2.1)

$\endgroup$
1
$\begingroup$

I'm taking the logarithm because I'm interested in estimating the effect of the independent variable on growth of the dependent variable.

Before you get to the issue with modelling and coding of the problem, I think you need to step back and think more about the coherence of the underlying measurement you are asking for. The reason you are getting problems here is that measuring growth with a real number breaks down when you have negative values. To see this, note that we generally measure growth either by a growth rate:

$$R_t = \frac{X_{t} - X_{t-1}}{X_{t-1}},$$

or the corresponding "force" of growth:

$$\delta_t = \ln(X_{t}) - \ln(X_{t-1}),$$

where the underlying series of values $\{ X_t | t \in \mathbb{Z} \}$ is non-negative. (These measures of growth are related by $1+R_t = \exp(\delta_t)$ so both give the same information.) You can see from these results that when $X_t > X_{t-1}$ you have positive growth and when $X_t<X_{t-1}$ you have negative growth. The case of negative growth is already covered by a positive quantity getting smaller in magnitude.

If you want to extend this analysis to allow for negative values in the underlying series, you need to think about how you want this represented. Usually this is done with complex numbers (i.e., by extending the logarithm function over the domain of all real numbers, which gives complex outputs for negative numbers). I think you need to ask yourself what you actually want to measure here, and whether what you are asking to measure is actually coherent.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.