Comments (2)
This is not relevant any more, since weights
is considered a parameters, with respect to which we are computing the gradient.
from galamm.
This is solved now.
library(galamm)
library(Matrix)
library(lme4)
library(dplyr, quietly = TRUE, warn.conflicts = FALSE)
library(tidyr, quietly = TRUE, warn.conflicts = FALSE)
library(memoise)
set.seed(11)
n <- 2000
dat <- tibble(
id = 1:n,
b = rnorm(n)
) %>%
uncount(3, .id = "tp") %>%
uncount(2, .id = "item") %>%
mutate(
x = runif(nrow(.)),
winv = if_else(item == 1, 1, 2),
y = x + b + rnorm(nrow(.), sd = sqrt(winv))
)
theta_inds <- 1
beta_inds <- 2:3
lambda_inds <- integer()
bounds <- c(0, -Inf, -Inf)
lmod <- lFormula(y ~ x + (1 | id), data = dat, REML = FALSE)
mlwrapper <- function(par, hessian = FALSE){
marginal_likelihood(
y = dat$y,
trials = rep(1, length(dat$y)),
X = lmod$X,
Zt = lmod$reTrms$Zt,
Lambdat = lmod$reTrms$Lambdat,
beta = par[beta_inds],
theta = par[theta_inds],
theta_mapping = lmod$reTrms$Lind - 1L,
lambda = par[lambda_inds],
lambda_mapping_X = integer(),
lambda_mapping_Zt = integer(),
weights = 2,
weights_mapping = rep(0L, nrow(dat)),
family = "gaussian",
maxit_conditional_modes = 1,
hessian = hessian
)
}
mlmem <- memoise(mlwrapper)
fn <- function(par){
mlmem(par)$logLik
}
gr <- function(par){
mlmem(par)$gradient[1:3]
}
par_init <- c(1, 0, 0)
opt <- optim(par_init, fn = fn, gr = gr,
method = "L-BFGS-B", lower = bounds,
control = list(fnscale = -1))
opt
#> $par
#> [1] 0.574685217 0.003681805 0.989699240
#>
#> $value
#> [1] -21058.72
#>
#> $counts
#> function gradient
#> 17 17
#>
#> $convergence
#> [1] 0
#>
#> $message
#> [1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"
Created on 2022-10-14 with reprex v2.0.2
from galamm.
Related Issues (20)
- Summary method does not always return formula HOT 3
- anova method should return likelihood ratio tests HOT 1
- Automatic setup of models with smooth terms HOT 1
- Create documentation for S3 object HOT 1
- Create examples HOT 1
- Covariates interacting with factor loadings
- Summary for smooth terms HOT 1
- Add plot function for smooth terms HOT 1
- Mixed response models don't work with multiple trials
- Cannot handle more than one factor when there are factors in fixed effects
- Add new GLM families
- Memory issues on CRAN HOT 6
- Failure on old R release HOT 1
- Hello! HOT 2
- Product of factor loadings HOT 2
- Binomial model with multiple trials HOT 1
- Heteroscedastic model or model with weights HOT 1
- Implement predict.galamm function HOT 1
- Implement plot.galamm function HOT 1
- Create optimControl parameter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from galamm.