kkholst / lava Goto Github PK
View Code? Open in Web Editor NEWLatent Variable Models in R https://kkholst.github.io/lava/
Latent Variable Models in R https://kkholst.github.io/lava/
Hi Klaus,
Melanie would like to use the plotConf function for mixed models (e.g. lmer object).
But she gets the following error:
"Error in if (fixed.only) { : argument is of length zero"
example:
library(lme4)
library(lava)
n <- 100
x0 <- rnorm(n)
x1 <- seq(-3,3, length.out=n)
x2 <- factor(rep(c(1,2),each=n/2), labels=c("A","B"))
y <- 5 + 2*x0 + 0.5*x1 + -1*(x2=="B")*x1 + 0.5*(x2=="B") + rnorm(n, sd=0.25)
dd <- data.frame(y=y, x1=x1, x2=x2)
dd$Id <- rbinom(n, size = 3, prob = 0.3)
lmer0 <- lmer(y ~ x0 + x1*x2 + (1|Id), dd)
plotConf(lmer0, var1="x1", `var2="x2")
I think this is because lme4:::model.frame.merMod has an additional argument fixed.only compare to the standard stats:::model.frame.lm
I have tried to fixed, as well as another error due to the fact that when extracting the covariance matrix in lmer we get an object and not a matrix (so I have applied as.matrix to it).
In the following file you will find the change that I suggest:
plotConf.txt
(it should be an .R file but I could not load it so I converted it to a .txt file)
Thanks
Hi Klaus,
I wanted to add a multinomial variable to the model:
m <- lvm()
distribution(m, ~y) <- multinomial.lvm(m, prob=c(0.2, 0.2, 0.6)
But I got the error <could not find function "multinomial.lvm"> (which is however listed in the reference manual)
Thanks!
Hi Klaus,
The function modelsearch in lava (v 1.4.7) appears to return each additional model path 3 times. Adjusted p-values appear sensitive to this redundancy.
m <- lvm(c(v1, v2, v3, v4) ~ u)
latent(m) <- ~u
dtempo <- sim(m, 1e2)
e <- estimate(m, dtempo)
esearch <- modelsearch(e)
esearch
Thanks,
Patrick
Hi,
Thanks for using data.table. For the next release, in revdep testing I get the following error from R CMD check. It happens with data.table 1.13.2, too, as released on CRAN, so I don't think it is due to the data.table update. CRAN checks seem all OK for lava
so it seems to be problem just local for me. Any ideas please? It would be nice to pass OK locally to clear this up.
I see that Suggested packages gof
and lava.tobit
have been removed from CRAN, but that doesn't seem to cause CRAN checks any problem. I'm running with R_CHECK_FORCE_SUGGESTS=false to get past that, which I assume CRAN checks do too.
Thanks, Matt
There is a call loadNamespace(mets)
in examples - https://github.com/kkholst/lava/blob/master/man/closed.testing.Rd#L39
As mets is suggested dependency, it should not be required to run examples according to R-exts. This can be conditionally escaped with requireNamespace.
It is possible there are other cases of that issue in other examples, this one was to first that fails.
* checking examples ... ERROR
Running examples in ‘lava-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: closed.testing
> ### Title: Closed testing procedure
> ### Aliases: closed.testing p.correct
>
> ### ** Examples
>
> m <- lvm()
> regression(m, c(y1,y2,y3,y4,y5,y6,y7)~x) <- c(0,0.25,0,0.25,0.25,0,0)
> regression(m, to=endogenous(m), from="u") <- 1
> variance(m,endogenous(m)) <- 1
> set.seed(2)
> d <- sim(m,200)
> l1 <- lm(y1~x,d)
> l2 <- lm(y2~x,d)
> l3 <- lm(y3~x,d)
> l4 <- lm(y4~x,d)
> l5 <- lm(y5~x,d)
> l6 <- lm(y6~x,d)
> l7 <- lm(y7~x,d)
>
> (a <- merge(l1,l2,l3,l4,l5,l6,l7,subset=2))
Estimate Std.Err 2.5% 97.5% P-value
x -0.0220 0.0993 -0.21668 0.173 8.25e-01
x.1 0.3723 0.1157 0.14564 0.599 1.29e-03
x.2 0.1198 0.1110 -0.09780 0.337 2.81e-01
x.3 0.4223 0.0926 0.24076 0.604 5.14e-06
x.4 0.2934 0.1214 0.05558 0.531 1.56e-02
x.5 0.2057 0.1062 -0.00246 0.414 5.28e-02
x.6 0.0524 0.1182 -0.17922 0.284 6.57e-01
> p.correct(a)
Error in loadNamespace(name) : there is no package called ‘mets’
Calls: p.correct ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Hi Klaus,
Hope you are doing well. I am trying to change the confidence region interval for a spaghetti plot I am making using the trend.delta specification in the 'spaghetti' function. When I alter the value for trend.delta, the shaded region does not change. This seems to be the case using my data as well as in the generated data in the example provided online:
These two
if (interactive() & requireNamespace("mets")) {
K <- 5
y <- "y"%++%seq(K)
m <- lvm()
regression(m,y=y,x=~u) <- 1
regression(m,y=y,x=~s) <- seq(K)-1
regression(m,y=y,x=~x) <- "b"
d <- sim(m,500)
dd <- mets::fast.reshape(d);
dd$num <- dd$num+rnorm(nrow(dd),sd=0.5) ## Unbalance
spaghetti(y~num,dd,id="id",lty=1,col=Col(1,.4),trend=TRUE,trend.col="darkblue")
The resulting plot when I specify trend.delta=0.05 and trend.delta=0.5 for dd is the same
Sorry if this is an error on my part -- I am not especially strong in R. Any advice you have on how to fix this would be greatly appreciated. If you need any additional information from me or if I can help to resolve this please let me know.
Thanks
Hi there! It looks like you recently made a release of lava that has a new R >= 3.5 requirement. According to this commit, it seems you want to enforce that readRDS()
has support for the version 3 format that came with R 3.5. Is this required by your package? 28dd87b#diff-35ba4a2677442e210c23a00a5601aba3
In tidymodels, we implicitly rely on your package through recipes -> ipred -> prodlim -> lava. We try to maintain support for 5 versions of R where possible, which means that we support back through R 3.3 at the moment. Do you think it might be possible for lava to continue to support R versions back this far?
Hi Klaus,
I get an error when I remove the last external parameter from an lvm model (lava version 1.4.4.13):
lv1 <- lvm(Y ~ X1 + X2)
parameter(lv1) <- "YX3"X4"
parameter(lv1) <- "Y
coef(lv1)
parameter(lv1, remove = TRUE) <- "YX3"X4"
coef(lv1)
parameter(lv1, remove = TRUE) <- "Y
I tried to look at what was going on, the error appears
in "parameter<-.lvm" line "index(x) <- reindex(x)"
Then in the reindex function the line:
"eparname <- unlist(unique(x$exfix[enamed]))"
is problematic as enamed is an empty list.
A possible solution (for my small example) is to replace this line by:
if(length(enamed)>0){
eparname <- unlist(unique(x$exfix[enamed]))
}else{
eparname <- NULL
}
Thanks!
The function modelsearch appears to return each additional possible model path evaluated 3 times. Adjusted p-values appear sensitive to this redundancy.
m <- lvm(c(v1, v2, v3, v4) ~ u) latent(m) <- ~u dtempo <- sim(m, 1e2) e <- estimate(m, dtempo) esearch <- modelsearch(e)
Hi,
seems for the last only lava_1.7.2.tar.gz made it to the CRAN mirrors. See http://cran.r-project.org/src/contrib/Archive/lava/ missing lava_1.7.2.1.tar.gz .
The bug #12 is hence still unfixed.
$ for f in lava_1.7.*.tar.gz; do echo $f; R CMD INSTALL $f; done
lava_1.7.1.tar.gz
* installing to library ‘/home/bionic/R/x86_64-pc-linux-gnu-library/3.5’
* installing *source* package ‘lava’ ...
** package ‘lava’ successfully unpacked and MD5 sums checked
** R
** data
** demo
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (lava)
lava_1.7.2.tar.gz
* installing to library ‘/home/bionic/R/x86_64-pc-linux-gnu-library/3.5’
* installing *source* package ‘lava’ ...
** package ‘lava’ successfully unpacked and MD5 sums checked
** R
Error in parse(outFile) :
/tmp/Rtmpdt3HA8/R.INSTALL1ebd4eadab44/lava/R/contr.R:47:53: unexpected input
46: pairwise.diff <- function(n) {
47: pdiff <- function(n) lava::contr(lapply(seq(n-1), \
^
ERROR: unable to collate and parse R files for package ‘lava’
* removing ‘/home/bionic/R/x86_64-pc-linux-gnu-library/3.5/lava’
* restoring previous ‘/home/bionic/R/x86_64-pc-linux-gnu-library/3.5/lava’
$ ls
Hi Klaus,
Someone made me notice that the argument rate in coxExponential.lvm should actually be called scale
to be consistent with the rexp function in R.
A small example:
p.rate <- 5; m <- lvm(Y~1); distribution(m,"Y") <- coxExponential.lvm(rate = p.rate) set.seed(10); round(quantile(lava::sim(m, 1e4)[,1]),3)
gives something much closer to
set.seed(10); round(quantile(rexp(1e4, rate = 1/p.rate)),3)
than
set.seed(10); round(quantile(rexp(1e4, rate = p.rate)),3)
Hi,
I intend to upgrade the Debian package if lava. Unfortunately the testsuite has some failure in our setup. You can see the full test log which contains:
== Failed tests ================================================================
-- Error ('test-model.R:97:5'): Graph attributes -------------------------------
Error in `testthat::expect_match(col, graph::nodeRenderInfo(g2)$fill[v])`: is.character(regexp) is not TRUE
Backtrace:
x
1. \-testthat::expect_match(col, graph::nodeRenderInfo(g2)$fill[v]) at test-model.R:97:4
2. \-base::stopifnot(is.character(regexp), length(regexp) == 1)
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 254 ]
Any idea what might be wrong here?
Kind regards, Andreas.
The latest package version uses the \(x)
anonymous function notation in the pairwise.diff
function. This syntax is not supported in R versions prior to 4.1, causing package installation to fail.
46: pairwise.diff <- function(n) {
47: pdiff <- function(n) lava::contr(lapply(seq(n-1), \
^
ERROR: unable to collate and parse R files for package lava```
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.