Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mcglm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leg
mcglm
Commits
d7bb8d4a
Commit
d7bb8d4a
authored
9 years ago
by
Walmes Marques Zeviani
Browse files
Options
Downloads
Patches
Plain Diff
Add tags and tidy code/text.
parent
0372b503
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/mc_dexpm.R
+27
-21
27 additions, 21 deletions
R/mc_dexpm.R
R/mc_getInformation.R
+15
-8
15 additions, 8 deletions
R/mc_getInformation.R
with
42 additions
and
29 deletions
R/mc_dexpm.R
+
27
−
21
View file @
d7bb8d4a
#' Exponential-matrix covariance link function
#' @title Exponential-matrix covariance link function
#' @author Wagner Hugo Bonat
#'
#' @description Given a matrix \code{U} the function \code{mc_expm}
#'returns the exponential-matrix \eqn{expm(U)} and some auxiliares
matrices to compute
#'its derivatives. This function is based on
the eigen-value decomposition it means that it is
#'very slow.
#'
returns the exponential-matrix \eqn{expm(U)} and some auxiliares
#'
matrices to compute
its derivatives. This function is based on
#'
the eigen-value decomposition it means that it is
very slow.
#'
#' @param U A matrix.
#'@param n A number specifing the dimension of the matrix U. Default \code{n = dim(U)[1]}.
#'@param sparse Logical defining the class of the output matrix. If \code{sparse = TRUE} the output
#'class will be 'dgCMatrix' if \code{sparse = FALSE} the class will be 'dgMatrix'.
#'@param inverse Logical defining if the inverse will be computed or not.
#'@return A list with \eqn{\Omega = expm(U)} its inverse (if \code{inverse = TRUE}) and
#' auxiliares matrices to compute the derivatives.
#' @param n A number specifing the dimension of the matrix U. Default
#' \code{n = dim(U)[1]}.
#' @param sparse Logical defining the class of the output matrix. If
#' \code{sparse = TRUE} the output class will be 'dgCMatrix' if
#' \code{sparse = FALSE} the class will be 'dgMatrix'.
#' @param inverse Logical defining if the inverse will be computed or
#' not.
#' @return A list with \eqn{\Omega = expm(U)} its inverse (if
#' \code{inverse = TRUE}) and auxiliares matrices to compute the
#' derivatives.
#'
#' @seealso \code{\link[Matrix]{expm}}, \code{\link[base]{eigen}},
#' \code{link[mcglm]{mc_dexp_gold}}.
mc_expm
<-
function
(
U
,
n
=
dim
(
U
)[
1
],
sparse
=
FALSE
,
inverse
=
FALSE
)
{
tt
=
eigen
(
U
,
symmetric
=
TRUE
)
UU
=
tt
$
vectors
Q
=
tt
$
values
eQr
=
Diagonal
(
n
,
exp
(
tt
$
values
))
tt
<-
eigen
(
U
,
symmetric
=
TRUE
)
UU
<-
tt
$
vectors
Q
<-
tt
$
values
eQr
<-
Diagonal
(
n
,
exp
(
tt
$
values
))
inv_UU
<-
t
(
UU
)
Omega
=
Matrix
(
UU
%*%
eQr
%*%
inv_UU
,
sparse
=
sparse
)
Omega
<-
Matrix
(
UU
%*%
eQr
%*%
inv_UU
,
sparse
=
sparse
)
if
(
inverse
==
TRUE
)
{
eQr_INV
=
Diagonal
(
n
,
exp
(
-
tt
$
values
))
eQr_INV
<-
Diagonal
(
n
,
exp
(
-
tt
$
values
))
inv_Omega
<-
Matrix
(
UU
%*%
eQr_INV
%*%
inv_UU
,
sparse
=
sparse
)
saida
<-
list
(
Omega
=
Omega
,
inv_Omega
=
inv_Omega
,
UU
=
UU
,
Q
=
Q
,
inv_UU
=
inv_UU
)
saida
<-
list
(
Omega
=
Omega
,
inv_Omega
=
inv_Omega
,
UU
=
UU
,
Q
=
Q
,
inv_UU
=
inv_UU
)
}
if
(
inverse
==
FALSE
)
{
saida
<-
list
(
Omega
=
Omega
,
UU
=
UU
,
Q
=
Q
,
inv_UU
=
inv_UU
)
...
...
This diff is collapsed.
Click to expand it.
R/mc_getInformation.R
+
15
−
8
View file @
d7bb8d4a
#' Getting information about model parameters
#' @title Getting information about model parameters
#' @author Wagner Hugo Bonat
#'
#' @description This computes all information required about the number of model parameters.
#' @description This computes all information required about the number
#' of model parameters.
#'
#' @param list_initial A list of initial values.
#' @param list_power_fixed A list of logical specyfing if the power parameters should be estimated or not.
#' @param list_power_fixed A list of logical specyfing if the power
#' parameters should be estimated or not.
#' @param n_resp A number specyfing the nmber of response variables.
#' @return The number of \eqn{\beta}'s, \eqn{\tau}'s, power and correlation parameters.
#' @return The number of \eqn{\beta}'s, \eqn{\tau}'s, power and
#' correlation parameters.
mc_getInformation
<-
function
(
list_initial
,
list_power_fixed
,
n_resp
)
{
mc_getInformation
<-
function
(
list_initial
,
list_power_fixed
,
n_resp
)
{
n_betas
<-
lapply
(
list_initial
$
regression
,
length
)
n_taus
<-
lapply
(
list_initial
$
tau
,
length
)
n_power
<-
lapply
(
list_initial
$
power
,
length
)
for
(
i
in
1
:
n_resp
)
{
if
(
list_power_fixed
[[
i
]]
==
TRUE
)
{
n_power
[
i
]
=
0
n_power
[
i
]
<-
0
}
}
if
(
n_resp
==
1
)
{
...
...
@@ -22,7 +27,9 @@ mc_getInformation <- function(list_initial, list_power_fixed, n_resp) {
if
(
n_resp
!=
1
)
{
n_rho
<-
length
(
list_initial
$
rho
)
}
n_cov
<-
sum
(
do.call
(
c
,
n_power
))
+
n_rho
+
sum
(
do.call
(
c
,
n_taus
))
saida
<-
list
(
n_betas
=
n_betas
,
n_taus
=
n_taus
,
n_power
=
n_power
,
n_rho
=
n_rho
,
n_cov
=
n_cov
)
n_cov
<-
sum
(
do.call
(
c
,
n_power
))
+
n_rho
+
sum
(
do.call
(
c
,
n_taus
))
saida
<-
list
(
n_betas
=
n_betas
,
n_taus
=
n_taus
,
n_power
=
n_power
,
n_rho
=
n_rho
,
n_cov
=
n_cov
)
return
(
saida
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment