Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73db82d

Browse files
author
Christoph Kiefer
committed
update tests and summary
1 parent 6a97c44 commit 73db82d

40 files changed

+518
-503
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: lavacreg
22
Type: Package
33
Title: Latent Variable Count Regression Models
4-
Version: 0.1-0
5-
Date: 2021-01-20
4+
Version: 0.1-1
5+
Date: 2021-03-01
66
Authors@R: c(person("Christoph", "Kiefer",
77
email = "[email protected]",
88
role = c("cre", "aut"),

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ importFrom(stats,as.formula)
1313
importFrom(stats,dpois)
1414
importFrom(stats,na.omit)
1515
importFrom(stats,nlminb)
16+
importFrom(stats,pnorm)
1617
importFrom(stats,terms.formula)
1718
importFrom(utils,combn)
1819
useDynLib(lavacreg)

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# lavacreg 0.1-1
2+
3+
* skipping two tests failing on MacOS (i.e. applications in which only one latent covariate is considered)
4+
* lowered numerical precision for test on Poisson regression with three manifest covariates (for Solaris)
5+
* added a more detailed summary-function
6+
17
# lavacreg 0.1-0
28

39
* Added a `NEWS.md` file to track changes to the package.

R/00documentation.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#' A first example to illustrate
1+
#' A first example dataset to illustrate the use of lavacreg
22
#'
3-
#' A dataset containing ... .
3+
#' A dataset containing 9 variables: a dependent variable dv, a group variable treat
4+
#' and 7 indicators for 3 latent covariates.
45
#'
56
#' @format A data frame with 871 rows and 9 variables:
67
#' \describe{

R/00methods.R

+74-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,83 @@
77
#' @param object lavacreg object
88
#' @return Function prints the parameter table of an estimated model, which
99
#' includes the parameter estimates and standard errors.
10+
#' @importFrom stats pnorm
1011
setMethod("summary", signature(object="lavacreg"),
1112
function(object) {
13+
input <- object@input
14+
dataobj <- object@dataobj
1215
pt <- object@fit$pt
13-
pt$SE <- NULL
14-
SE <- sqrt(diag(object@fit$vcov_fit))
16+
pt$pval <- pt$zval <- pt$SE <- NA
17+
vcov_fit <- object@fit$vcov_fit
18+
19+
if (object@input@se & !is.null(vcov_fit)){
20+
SE <- sqrt(diag(object@fit$vcov_fit))
21+
22+
pt$SE[as.logical(pt$par_free)] <- SE
23+
pt$zval <- pt$par/pt$SE
24+
pt$pval <- 2*(1-pnorm(abs(pt$zval)))
25+
}
26+
27+
for (g in 1:dataobj@no_groups){
28+
pt_g <- pt[pt$group == g,]
29+
cat(paste0("\n\n--------------------- Group ",g," --------------------- \n\n"))
30+
31+
# Print regression coefficients
32+
cat("Regression:\n")
33+
res <- subset(pt_g, pt_g$dest == "regcoef", select = c("rhs", "par", "SE", "zval", "pval"))
34+
rownames(res) <- res$rhs
35+
res <- res[,-1]
36+
names(res) <- c("Estimate", "SE", "Est./SE", "p-value")
37+
print(res, digits=3, print.gap=3)
38+
39+
if (input@family != "poisson"){
40+
# Print overdispersion parameter if it exists
41+
res <- subset(pt_g, pt_g$type == "size", select = c("par", "SE", "zval", "pval"))
42+
rownames(res) <- "Dispersion"
43+
names(res) <- c("Estimate", "SE", "Est./SE", "p-value")
44+
print(res, digits=3, print.gap=3)
45+
}
46+
47+
if (dataobj@no_z | dataobj@no_lv){
48+
# Print means and variances of the covariates
49+
cat("\nMeans:\n")
50+
res <- subset(pt_g, pt_g$type == "mean", select = c("lhs", "par", "SE", "zval", "pval"))
51+
rownames(res) <- res$lhs
52+
res <- res[,-1]
53+
names(res) <- c("Estimate", "SE", "Est./SE", "p-value")
54+
print(res, digits=3, print.gap=3)
55+
56+
cat("\nVariances:\n")
57+
res <- subset(pt_g, pt_g$type == "var", select = c("lhs", "par", "SE", "zval", "pval"))
58+
rownames(res) <- res$lhs
59+
res <- res[,-1]
60+
names(res) <- c("Estimate", "SE", "Est./SE", "p-value")
61+
print(res, digits=3, print.gap=3)
62+
}
63+
64+
if (dataobj@no_z + dataobj@no_lv >= 2){
65+
# Print covariances of covariates
66+
cat("\nCovariances:\n")
67+
res <- subset(pt_g, pt_g$type == "cov" | pt_g$type == "cov_z_lv",
68+
select = c("lhs", "op", "rhs", "par", "SE", "zval", "pval"))
69+
rownames(res) <- paste(res$lhs, res$op, res$rhs)
70+
res <- res[,-c(1:3)]
71+
names(res) <- c("Estimate", "SE", "Est./SE", "p-value")
72+
print(res, digits=3, print.gap=3)
73+
}
74+
75+
if (dataobj@no_lv){
76+
# Print measurement model
77+
cat("\nMeasurement Model:\n")
78+
res <- subset(pt_g, (pt_g$dest == "mm" | pt_g$type == "veps") & pt_g$par_free > 0,
79+
select = c("lhs", "op", "rhs", "par", "SE", "zval", "pval"))
80+
rownames(res) <- paste(res$lhs, res$op, res$rhs)
81+
res <- res[,-c(1:3)]
82+
names(res) <- c("Estimate", "SE", "Est./SE", "p-value")
83+
print(res, digits=3, print.gap=3)
84+
}
85+
86+
}
1587

16-
pt$SE[as.logical(pt$par_free)] <- SE
17-
print(pt)
1888
}
1989
)

R/RcppExports.R

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ compute_groupcond_logl <- function(x, muy, sigmayw, muwz, sigmaz, ghweight, detv
55
.Call('_lavacreg_compute_groupcond_logl', PACKAGE = 'lavacreg', x, muy, sigmayw, muwz, sigmaz, ghweight, detvarz, dims)
66
}
77

8+
creg_group_logl_cpp <- function(datalist, modellist) {
9+
.Call('_lavacreg_creg_group_logl_cpp', PACKAGE = 'lavacreg', datalist, modellist)
10+
}
11+

R/creg_loglikelihood.R

+10-8
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,40 @@
99
#' @keywords internal
1010
#' @noRd
1111
creg_loglikelihood_function <- function(datalist, modellist) {
12+
# browser()
1213
kappas <- modellist$groupw
1314
n_cell <- modellist$n_cell
1415
no_groups <- length(kappas)
1516
family <- modellist$family
1617

1718
obj.group <- sum(dpois(n_cell, exp(kappas), log = TRUE))
1819

20+
# obj.ingroups <- creg_group_logl_cpp(datalist, modellist$modellist_g)
21+
1922
obj.ingroups <- mapply(function(data, modellist_g) {
20-
#data <- datalist[[g]]
21-
#modellist_g <- modellist$modellist_g[[g]]
2223
muy <- modellist_g$muy
2324
sigmayw <- modellist_g$sigmayw
2425
muwz <- modellist_g$muwz
2526
sigmaz <- modellist_g$sigmaz
2627
ghweight <- modellist_g$ghweight
2728
detvarz <- modellist_g$detvarz
2829
dims <- modellist_g$dims
29-
30+
3031
if (any(!is.na(sigmaz))){
3132
if (any(diag(solve(sigmaz)) <= 0)) return(-Inf)
32-
}
33+
}
3334
if (any(sigmayw[-1] <= 0)) return(-Inf)
3435
if (family == "nbinom" & sigmayw[1] <= 0) return(-Inf)
35-
36-
obj.i <- compute_groupcond_logl(x = data, muy = muy, sigmayw = sigmayw, muwz = muwz,
37-
sigmaz = sigmaz, ghweight = ghweight, detvarz = detvarz, dims = dims)
36+
37+
obj.i <- compute_groupcond_logl(x = data, muy = muy, sigmayw = sigmayw, muwz = muwz,
38+
sigmaz = sigmaz, ghweight = ghweight, detvarz = detvarz,
39+
dims = dims)
3840
if(is.na(obj.i)) return(-Inf)
3941
return(obj.i)
4042
}, data = datalist, modellist_g = modellist$modellist_g, SIMPLIFY = TRUE)
4143

4244
obj <- -(obj.group + sum(obj.ingroups))/sum(n_cell)
43-
if (is.na(obj)) browser()
45+
if (is.na(obj)) return(+Inf)
4446
return(obj)
4547

4648
}

docs/404.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/index.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)