Re: [R] Checking if a matrix exists/is defined
Steven Yen sye...@gmail.com [Sun, Oct 19, 2014 at 06:17:48AM CEST]: Hello Can someone help me with the following, specifically in judging whether a matrix exists. exists(my.matrix) I have trouble with the first line below. In this case, matrix obj$hessian exists and is 74 x 74. I receive the error message: Warning message: Looks like a warning message to me. In all(w$hessian) : coercing argument of type 'double' to logical all expects a logical vector, instead it finds a double vector. Trying to make sense of it, it converts the double vector to logical using as.logical(). Looking up ?as.logical I fail, however, to see which rules it uses to convert double to logical. Possibly 0 - FALSE and everything else - TRUE. -- Johannes Hüsing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johan...@huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, Life on the Mississippi) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Checking if a matrix exists/is defined
Thank you Rich. It works like a charm! Earlier I worked around by judging its determinant: dd-NULL if (invH) dd-det(obj$hessian) if (invH exists(dd)){ ... } Now I do if (!is.null(obj$hessian) invH){ ... } which is more direct. Thanks again. Steven At 01:50 AM 10/19/2014, Richard M. Heiberger wrote: all() takes a logical argument, not numeric. See ?all I think you are looking for is.null(obj$hessian) If this isn't what you are looking for, please send a reproducible example to the entire list. Rich On Sun, Oct 19, 2014 at 12:17 AM, Steven Yen sye...@gmail.com wrote: Hello Can someone help me with the following, specifically in judging whether a matrix exists. I have trouble with the first line below. In this case, matrix obj$hessian exists and is 74 x 74. I receive the error message: Warning message: In all(w$hessian) : coercing argument of type 'double' to logical Thank you all. --- if (!all(obj$hessian)|OPG){ vb-obj$gradientObs; vb-solve(t(vb)%*%vb) vb.method-; v(b)=inv(G'G) } else { vb- solve(-obj$hessian) vb.method-; v(b)=inv(-H) } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Checking if a matrix exists/is defined
Hello Can someone help me with the following, specifically in judging whether a matrix exists. I have trouble with the first line below. In this case, matrix obj$hessian exists and is 74 x 74. I receive the error message: Warning message: In all(w$hessian) : coercing argument of type 'double' to logical Thank you all. --- if (!all(obj$hessian)|OPG){ vb-obj$gradientObs; vb-solve(t(vb)%*%vb) vb.method-; v(b)=inv(G'G) } else { vb- solve(-obj$hessian) vb.method-; v(b)=inv(-H) } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Checking if a matrix exists/is defined
all() takes a logical argument, not numeric. See ?all I think you are looking for is.null(obj$hessian) If this isn't what you are looking for, please send a reproducible example to the entire list. Rich On Sun, Oct 19, 2014 at 12:17 AM, Steven Yen sye...@gmail.com wrote: Hello Can someone help me with the following, specifically in judging whether a matrix exists. I have trouble with the first line below. In this case, matrix obj$hessian exists and is 74 x 74. I receive the error message: Warning message: In all(w$hessian) : coercing argument of type 'double' to logical Thank you all. --- if (!all(obj$hessian)|OPG){ vb-obj$gradientObs; vb-solve(t(vb)%*%vb) vb.method-; v(b)=inv(G'G) } else { vb- solve(-obj$hessian) vb.method-; v(b)=inv(-H) } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.