MatthieuStigler / Misconometrics

A bunch of small R scripts useful in econometrics
GNU General Public License v3.0
6 stars 4 forks source link

Bug when running lm() #2

Closed Lisaksimon closed 3 years ago

Lisaksimon commented 3 years ago

Hi Matthieu,

as per email, here is the error I get when I try the decomposition with lm():


library(devtools)
#> Loading required package: usethis
source_url("https://raw.githubusercontent.com/MatthieuStigler/Misconometrics/master/Gelbach_decompo/dec_covar.R")
#> SHA-1 hash of file is ed716e821f7d61a45b36cedc16d1ed1be3abb046
library(tidyverse)
library(reprex)

model_full_1 <- lm(Fertility ~ ., data=swiss)
dec <- dec_covar(object = model_full_1, var_main = "Education")
#> Error in data.frame(term = names(co), estimate = unname(co), stringsAsFactors = FALSE): arguments imply differing number of rows: 0, 2

I get the same error when I do dec_covar on my linear model. While when I convert the data into panel data and use plm(), it works fine!

Thanks so much for looking into this. Created on 2020-10-11 by the reprex package (v0.3.0)

MatthieuStigler commented 3 years ago

Ok, so I cannot reproduce the error you face!

This could be a good news, meaning it's just about updating packages. I suspect in particular you are using an old version of broom? Can you please run packageVersion("broom") first, then update it (install.packages("broom") or all with update.packages(ask=FALSE)) and then re-run the reprex below? Note there will be new warnings (I need to update the code) but the code should run at least!?

devtools::source_url("https://raw.githubusercontent.com/MatthieuStigler/Misconometrics/master/Gelbach_decompo/dec_covar.R")
#> SHA-1 hash of file is ed716e821f7d61a45b36cedc16d1ed1be3abb046
#> Error in bindingIsLocked(x, ns): no binding for "process_lm"
library(tidyverse)

model_full_1 <- lm(Fertility ~ ., data=swiss)
dec <- dec_covar(object = model_full_1, var_main = "Education")
#> Warning: `funs()` is deprecated as of dplyr 0.8.0.
#> Please use a list of either functions or lambdas: 
#> 
#>   # Simple named list: 
#>   list(mean = mean, median = median)
#> 
#>   # Auto named with `tibble::lst()`: 
#>   tibble::lst(mean, median)
#> 
#>   # Using lambdas
#>   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.

packageVersion("broom")
#> [1] '0.7.0'
packageVersion("dplyr")
#> [1] '1.0.2'

Created on 2020-10-11 by the reprex package (v0.3.0)

Lisaksimon commented 3 years ago

So just updated all my packages - bad new is that now neither plm nor lm works anymore. I do get the exact same error message as you now replicating the above - but the code does not run, it stops at the errors..


devtools::source_url("https://raw.githubusercontent.com/MatthieuStigler/Misconometrics/master/Gelbach_decompo/dec_covar.R")
#> SHA-1 hash of file is ed716e821f7d61a45b36cedc16d1ed1be3abb046
#> Error in bindingIsLocked(x, ns): no binding for "process_lm"
library(tidyverse)
library(reprex)

model_full_1 <- lm(Fertility ~ ., data=swiss)
dec <- dec_covar(object = model_full_1, var_main = "Education")
#> Warning: `funs()` is deprecated as of dplyr 0.8.0.
#> Please use a list of either functions or lambdas: 
#> 
#>   # Simple named list: 
#>   list(mean = mean, median = median)
#> 
#>   # Auto named with `tibble::lst()`: 
#>   tibble::lst(mean, median)
#> 
#>   # Using lambdas
#>   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.

packageVersion("broom")
#> [1] '0.7.1'
packageVersion("dplyr")
#> [1] '1.0.2'

Created on 2020-10-11 by the reprex package (v0.3.0)

Any ideas?

Lisaksimon commented 3 years ago

Oh I actually just updated my data.table package (which for some reason did not update, and now I get the same message, but the code runs, and plm() decomposition is back to running!

MatthieuStigler commented 3 years ago

great! I'll have to clean those warnings at some point, but the important is it is working now!

MatthieuStigler commented 3 years ago

Ok, I've cleaned and updated the code for the latest version of dplyr, it should now run without issues. I'll close the issue, but feel free to re-open if there are still issues

Lisaksimon commented 3 years ago

Great. Thanks again for your quick help, it was a life saver last week!

From: Matthieu notifications@github.com Reply to: MatthieuStigler/Misconometrics reply@reply.github.com Date: Saturday, 17. October 2020 at 15:03 To: MatthieuStigler/Misconometrics Misconometrics@noreply.github.com Cc: Lisa Simon lisaksimon@gmail.com, Author author@noreply.github.com Subject: Re: [MatthieuStigler/Misconometrics] Bug when running lm() (#2)

Closed #2https://github.com/MatthieuStigler/Misconometrics/issues/2.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/MatthieuStigler/Misconometrics/issues/2#event-3889701739, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACR2FDUHDJBD7T7CYOIA7QDSLIIEFANCNFSM4SL5TU6Q.