Fixed effects maximum likelihood models.

Description

This function estimates maximum likelihood models (e.g., Poisson or Logit) and is efficient to handle fixed effects (i.e. cluster variables). It further allows for nonlinear right hand sides.

Usage

1
2
3
4
femlm(linear.fml, data, dummy, linear.start = 0,
      useHessian = TRUE, opt_method = c("nlminb", "optim"),
      debug = FALSE, family = c("poisson", "negbin", "logit"),
      opt.control=list(),optim.method="BFGS",...)

Arguments

linear.fml

A formula. The linear formula to be estimated.

family

Character scalar. It should provide the family. Currently family="poisson", family="negbin" and family="logit" are implemented. Note that the log link is used by default.

data

A data.frame containing the necessary variables to run the model. The variables of the non-linear right hand side of the formula are identified with this data.frame names. Note that no NA is allowed.

start

A list. Starting values for the non-linear parameters. ALL the parameters are to be named and given a staring value. Example: start=list(a=1,b=5,c=0). Though, there is an exception: if all parameters are to be given the same starting value, use start.init. Yet this is not recommended.

dummy

Character vector. The name/s of a/some variable/s within the dataset. These variables should contain the identifier of each observation (e.g., think of it as a panel identifier).

linear.start

Numeric named vector. The starting values of the linear part. If it is just a numeric scalar, all coefficients are set to linear.start.

useHessian

Logical. (Only if omptimization method is optim). Should the Hessian be computed in the optimization stage? Default is TRUE.

opt_method

Character scalar. Which optimization method should be used. Either nlminb or optim. Default is nlminb.

opt.control

List of elements to be passed to the optimization method (nlminb or optim).

optim.method

Character scalar. If opt_method="optim", it is the algorithm to be used by optim (default is "BFGS"). See optim help pages for detail.

debug

Logical. If TRUE then the log-likelihood as well as all parameters are printed at each iteration. Default is FALSE.

...

Not currently used.

Value

An feNmlm object.

coef

The coefficients.

coeftable

The table of the coefficients with their standard errors, z-values and p-values.

loglik

The loglikelihood.

iterations

Number of iterations of the algorithm.

n

The number of observations.

k

The number of parameters of the model.

call

The call.

nonlinear.fml

The nonlinear formula of the call. It also contains the dependent variable.

linear.formula

The linear formula of the call.

ll_null

Log-likelyhood of the null model

pseudo_r2

The adjusted pseudo R2.

naive.r2

The R2 as if the expected predictor was the linear predictor in OLS.

message

The convergence message from the optimization procedures.

sq.cor

Squared correlation between the dependent variable and its expected value as given by the optimization.

expected.predictor

The expected predictor is the expected value of the dependent variable.

cov.unscaled

The variance covariance matrix of the parameters.

sd

The standard error of the parameters.

Author(s)

Laurent Berge

See Also

See also feNmlm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#The data
n = 100
x = rnorm(n,1,5)**2
y = rnorm(n,-1,5)**2
z = rpois(n,x*y)
base = data.frame(x,y,z)

# Results of the Poisson..
est_poisson = femlm(z~log(x)+log(y),base,family="poisson")
# .. and of the Negative Binomial
est_negbin = femlm(z~log(x)+log(y),base,family="negbin")

# Displaying the results
est_poisson
est_negbin

# Changing the way the standard errors are computed:
summary(est_poisson,sd="white")
summary(est_negbin,sd="white")

#
# Now with dummies
#

# Bilateral network
nb = 20
n = nb**2
k = nb
id1 = factor(rep(1:k,each=n/k))
id2 = factor(rep(1:(n/k),times=k))
x = rnorm(n,1,5)**2
y = rnorm(n,-1,5)**2
z = rpois(n,x*y+rnorm(n,sd = 3)**2)
base = data.frame(x,y,z,id1,id2)

# We want to use the ID's of each observation as a variable: we use the option dummy
est_poisson = femlm(z~log(x)+log(y),base,family="poisson",dummy=c("id1","id2"))
# Displaying the results with twoway clustered santard-errors
print(est_poisson,"t")