Skip to content

Commit

Permalink
Fixed issue#2 and some warnings from CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
sgaure committed Aug 22, 2018
1 parent da7c059 commit 183bde2
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 55 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: lfe
Version: 2.8-1
Date: 2018-08-20
Date: 2018-08-22
Title: Linear Group Fixed Effects
Authors@R: person("Simen", "Gaure", email="[email protected]", role=c("aut","cre"))
Copyright: 2011-2018, Simen Gaure
Expand All @@ -19,4 +19,5 @@ Classification/JEL: C13, C23, C60
Classification/MSC: 62J05, 65F10, 65F50
URL: https://github.com/sgaure/lfe
BugReports: https://github.com/sgaure/lfe/issues
Encoding: UTF-8
RoxygenNote: 6.1.0
10 changes: 5 additions & 5 deletions R/nlexpect.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#' one already. It will also be passed an argument \code{.z} which contains
#' the actual coefficients in normalized coordinates, i.e. if \code{ch} is the
#' Cholesky decomposition of the covariance matrix, and \code{pt} are the point
#' estimates, the coefficients will be \code{pt + ch \%*\% .s}. The first argument
#' estimates, the coefficients will be \code{pt + ch \%*\% .z}. The first argument
#' is a vector with names corresponding to the coefficients.
#'
#' If you specify \code{vectorized=TRUE}, your function will be passed a list with vectors
Expand All @@ -57,8 +57,8 @@
#' The \code{...} can be used for passing other arguments to the integration
#' routine.
#'
#' @param est object of class \code{"felm"}, a result of a call to
#' \code{\link{felm}}.
#' @param est object of class \code{"felm"} or \code{"lm"}, a result of a call to
#' \code{\link{felm}} or \code{lm}.
#' @param fun function of coefficients to be integrated. Can also be a
#' \code{quote}d expression.
#' @param coefs character. Names of coefficients to test. Only needed if
Expand Down Expand Up @@ -111,13 +111,13 @@
#' 2*nlexpect(est, x1*sign(pt1) < 0)
#'
#' # Here's a multivalued, vectorized example
#' nlexpect(est, rbind(a=x1*x2 < pt1, b=x1*x2 > 0), vectorized=TRUE)
#' nlexpect(est, rbind(a=x1*x2 < pt1, b=x1*x2 > 0), vectorize=TRUE)
#' \donttest{
#'
#' # Non-linear test:
#'
#' # A simple one, what's the probability that product x1*x2 is between 0 and |E(x1)|?
#' nlexpect(est, x1*x2 > 0 & x1*x2 < abs(pt1), vectorized=TRUE)
#' nlexpect(est, x1*x2 > 0 & x1*x2 < abs(pt1), vectorize=TRUE)
#' # Then a more complicated one with the expected value of a polynomal in the coefficients
#' f <- function(x) c(poly=x[['x1']]*(6*x[['x1']]-x[['x2']]^2))
#' # This is the linearized test:
Expand Down
2 changes: 1 addition & 1 deletion cleanup
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
rm -f src/Makevars acaux config.log
rm -rf src/Makevars src/config.h acaux config.* aclocal.m4 autom4te.cache


8 changes: 8 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
\name{NEWS}
\title{lfe news}
\section{Changes in version 2.8-1}{
\itemize{
\item Fixed a bug in Crowsum which prevented computation of clustered standard
errors in large datasets (rows x covariates exceeds 2
billion). Thanks to mcmalone for the report.
\item Minor updates to documentation and some cosmetic code changes.
}
}
\section{Changes in version 2.8}{
\itemize{
\item Added functionality for closed form standard errors on the fixed
Expand Down
10 changes: 5 additions & 5 deletions man/nlexpect.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/demean.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static void *demeanlist_thr(void *varg) {
#ifdef HAVE_THREADNAME
#ifndef USEOMP
char thrname[16];
snprintf(thrname,16, "Ct %d/%d",vecnum+1, arg->K);
snprintf(thrname,16, "Ct %5d/%5d",vecnum+1, arg->K);
STNAME(thrname);
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/kaczmarz.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static void *kaczmarz_thr(void *varg) {
if(vecnum >= arg->numvec) break;
#ifdef HAVE_THREADNAME
char thrname[16];
snprintf(thrname, 16, "Kz %d/%d",vecnum+1, arg->numvec);
snprintf(thrname, 16, "Kz %5d/%5d",vecnum+1, arg->numvec);
STNAME(thrname);
#endif

Expand Down
82 changes: 41 additions & 41 deletions tests/Examples/lfe-Ex.Rout.save
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

R Under development (unstable) (2018-06-19 r74917) -- "Unsuffered Consequences"
R Under development (unstable) (2018-08-19 r75170) -- "Unsuffered Consequences"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

Expand Down Expand Up @@ -59,9 +59,9 @@ Loading required package: Matrix
> # find bias corrections
> bccorr(est)
corr v1 v2 cov d1 d2
-0.032262721 0.952892562 1.376031164 -0.036943420 0.088877778 0.082733214
-0.030728526 0.950001416 1.370274827 -0.035059660 0.091768924 0.088489551
d12
-0.004461406
-0.006345166
>
>
>
Expand Down Expand Up @@ -434,8 +434,8 @@ function (v, addnames)
}
v
}
<bytecode: 0x556e19773ee0>
<environment: 0x556e1772d320>
<bytecode: 0x55f222b93e30>
<environment: 0x55f2216d9148>
> is.estimable(ef,fl)
Warning in is.estimable(ef, fl) :
non-estimable function, largest error 0.006 in coordinate 4013 ("id.4013")
Expand All @@ -457,8 +457,8 @@ function (v, addnames)
}
v
}
<bytecode: 0x556e18fe2758>
<environment: 0x556e19253d08>
<bytecode: 0x55f2224504f8>
<environment: 0x55f22266dc28>
attr(,"verified")
[1] TRUE
> is.estimable(ef,fl)
Expand Down Expand Up @@ -625,21 +625,21 @@ attr(,"df1")
> # find bias corrections, there's little bias in this example
> print(yv <- fevcov(est, lhs='y'))
id firm foo
id 0.92015755 -0.011173022 -0.019789538
firm -0.01117302 0.963808718 -0.009781304
foo -0.01978954 -0.009781304 1.035240984
id 0.92025530 -0.011069589 -0.019794399
firm -0.01106959 0.964082331 -0.009815829
foo -0.01979440 -0.009815829 1.035318331
attr(,"bias")
id firm foo
id 0.0319481064 -2.052376e-04 -1.023073e-04
firm -0.0002052376 2.187053e-02 -4.728025e-05
foo -0.0001023073 -4.728025e-05 1.560268e-02
id 3.185035e-02 -3.086703e-04 -9.744607e-05
firm -3.086703e-04 2.159692e-02 -1.275526e-05
foo -9.744607e-05 -1.275526e-05 1.552533e-02
> ## Here's how to compute the unbiased correlation matrix:
> cm <- cov2cor(yv)
> structure(cm,bias=NULL)
id firm foo
id 1.00000000 -0.011864355 -0.020276072
firm -0.01186435 1.000000000 -0.009792208
foo -0.02027607 -0.009792208 1.000000000
id 1.00000000 -0.011752230 -0.020279218
firm -0.01175223 1.000000000 -0.009825009
foo -0.02027922 -0.009825009 1.000000000
>
>
>
Expand All @@ -664,11 +664,11 @@ foo -0.02027607 -0.009792208 1.000000000
> #both bootstrap and computed se:
> cbind(getfe(est,ef=efactory(est,'ref'),se=TRUE), fse=fixedse(est))
effect obs comp fe idx se fse
f.1 0.9354485 212 1 f 1 0.06876413 0.07239479
f.2 1.9504291 208 1 f 2 0.07263999 0.07311460
f.3 3.0979605 206 1 f 3 0.07552078 0.07351750
f.4 3.9299698 180 1 f 4 0.07603677 0.07872855
f.5 5.0332818 194 1 f 5 0.07149293 0.07567327
f.1 0.9354485 212 1 f 1 0.06752416 0.07239479
f.2 1.9504291 208 1 f 2 0.06982697 0.07311460
f.3 3.0979605 206 1 f 3 0.07683635 0.07351750
f.4 3.9299698 180 1 f 4 0.08075644 0.07872855
f.5 5.0332818 194 1 f 5 0.07520879 0.07567327
> #compare with lm:
> summary(lm(y ~x+f-1))

Expand Down Expand Up @@ -1060,24 +1060,24 @@ Levels: 1 2 3
[1] 0.6807816+0i
> # mctrace is not really useful for small problems.
> mctrace(fun,ncol(A),tol=0.05)
[1] 0.6560292
[1] 0.6539472
attr(,"sd")
[1] 0.03258954
[1] 0.03255193
attr(,"iterations")
[1] 10868
[1] 10892
> # try a larger problem (3000x3000):
> f1 <- factor(sample(1500,3000,replace=TRUE))
> f2 <- factor(sample(1500,3000,replace=TRUE))
> fl <- list(f1,f2)
> mctrace(fl,tol=-5)
[1] 512.4893
[1] 512.6789
attr(,"sd")
[1] 4.026014
[1] 4.309791
attr(,"iterations")
[1] 44
[1] 42
> # exact:
> length(f1) - nlevels(f1) - nlevels(f2) + nlevels(compfactor(fl))
[1] 507
[1] 509
>
>
>
Expand Down Expand Up @@ -1151,16 +1151,16 @@ x2 -0.12240804 1.224730
0.2779329
>
> # Here's a multivalued, vectorized example
> nlexpect(est, rbind(a=x1*x2 < pt1, b=x1*x2 > 0), vectorized=TRUE)
> nlexpect(est, rbind(a=x1*x2 < pt1, b=x1*x2 > 0), vectorize=TRUE)
x1
a 0.8653844
b 0.5324968
a 0.2514457
b 0.0883645
> ## No test:
>
> # Non-linear test:
>
> # A simple one, what's the probability that product x1*x2 is between 0 and |E(x1)|?
> nlexpect(est, x1*x2 > 0 & x1*x2 < abs(pt1), vectorized=TRUE)
> nlexpect(est, x1*x2 > 0 & x1*x2 < abs(pt1), vectorize=TRUE)
x1
0.3977857
> # Then a more complicated one with the expected value of a polynomal in the coefficients
Expand Down Expand Up @@ -1230,14 +1230,14 @@ b 0.5324968
> # estimate the covariance matrix of the fixed effects
> fevcov(est, alpha)
id firm foo
id 0.95289256 -0.04488015 0.03963543
firm -0.04488015 5.53609420 -0.01160888
foo 0.03963543 -0.01160888 9.15619224
id 0.95000141 -0.04658861 0.03880143
firm -0.04658861 5.53028926 -0.01080117
foo 0.03880143 -0.01080117 9.15858839
attr(,"bias")
id firm foo
id 0.088877778 -0.005940383 -0.004116515
firm -0.005940383 0.082297201 -0.001586703
foo -0.004116515 -0.001586703 0.051505257
id 0.091768924 -0.004231931 -0.003282517
firm -0.004231931 0.088102140 -0.002394416
foo -0.003282517 -0.002394416 0.049109103
> # estimate variances of the diagonal
> varvars(est, alpha)
[1] 0.01018015 0.05503299 0.09774750
Expand Down Expand Up @@ -1289,15 +1289,15 @@ F-statistic: 5219 on 2 and 9997 DF, p-value: < 2.2e-16
0.9019639 0.5757362 3.0000000 0.9019611 0.1919121 9997.0000000
attr(,"formula")
~x - 1 | x2 + 0.2 | `(Intercept)`
<environment: 0x556e19d899e8>
<environment: 0x55f2215c27d0>
> # The Delta-method coincides when the function is linear:
> waldtest(est, function(x) x - c(0, 1, -0.2))
p chi2 df1 p.F F df2
0.9019639 0.5757362 3.0000000 0.9019611 0.1919121 9997.0000000
attr(,"formula")
function (x)
x - c(0, 1, -0.2)
<bytecode: 0x556e18a54880>
<bytecode: 0x55f2221a8b78>
>
>
>
Expand All @@ -1307,7 +1307,7 @@ x - c(0, 1, -0.2)
> cleanEx()
> options(digits = 7L)
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
Time elapsed: 27.778 3.532 26.254 0 0
Time elapsed: 28.359 0.921 15.406 0 0
> grDevices::dev.off()
null device
1
Expand Down

0 comments on commit 183bde2

Please sign in to comment.