fit_p1: Fitting function for p1 models

Description Usage Arguments Details Value Author(s) Examples

View source: R/p2.R

Description

Estimates a p1 model via (exact) maximum likelihood.

Usage

1
2
fit_p1(y, XnS, XnR, XvD, XvC, trace = FALSE, init = NULL,
  opt = nlminb, ...)

Arguments

y

An adjacency matrix of size g x g.

XnS

Matrix of sender effects of size g x ks.

XnR

Matrix of receiver effects of size g x kr.

XvD

Density effects, a 3-dim array of size g x g x kd.

XvC

Reciprocity effects, a 3-dim array of size g x g x kc.

trace

TRUE for tracing information during the estimation. Default is FALSE.

init

Optional starting value for model parameters. Default is NULL.

opt

Name of the optimising function. Default is nlminb.

...

Optional arguments passed to the optimiser.

Details

The function is included for compatibility with fit_p2, and it might also be useful to obtain starting values.

Value

The returned value is an object of class "p1", a list containing the following components:

theta

the vector of model estimates.

loglik

the log likelihood function at the estimate.

AIC, BIC

model selection criteria at the estimate.

XnS.null, XnR.null

logical, flagging whether there are no sender or receiver effects, respectively.

seed

the random seed used for estimation (when M>0).

theta.cov

Variance matrix of estimates.

theta.se

Standard errors of estimates.

opt

Optimiser employed for estimation.

opt.details

Object returned by the optimiser.

ADobj

Object returned by TMB:MakeADFun, containing the log likelihood function and its gradient (among its components).

model.data

List containing all the model data, fed to TMB:MakeADFun.

sdrep

Summary object returned by TMB::sdreport. This is an object with many slots, useful for TMB users.

Author(s)

Ruggero Bellio

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Analysis of the  kracknets data from the NetData package
library(NetData)
data(kracknets)
# data preparation
g <- 21
Y <- matrix(0, g, g)
ind <-1
for(i in 1:nrow(friendship_data_frame)){
   sele <- friendship_data_frame[i, ]
   Y[sele$ego, sele$alter] <- sele$friendship_tie
   }
Xn <- model.matrix(~ AGE + TENURE, attributes)[, -1]
XvD <- array(1, dim=c(g, g, 4))
for(i in 1:g)
 for(j in 1:g){
    XvD[i, j, 2] <- as.numeric(attributes$DEPT[i]==attributes$DEPT[j])
    XvD[i, j, 3] <- as.numeric(attributes$LEVEL[i]==attributes$LEVEL[j])
    XvD[i, j, 4] <- abs(attributes$AGE[i] - attributes$AGE[j])
  }
XvC <- array(1, dim=c(g, g, 1))
# Now we are ready to fit the model
mod <- fit_p1(Y, Xn, Xn, XvD, XvC)
summary(mod)

rugbel/p2model documentation built on March 8, 2021, 8:16 p.m.