jpolo at mail.usf.edu
2008-Apr-10 16:22 UTC
[R] QP.solve, QPmat, constraint matrix, and positive definite
hello all, i'm trying to use QPmat, from the popbio package. it appears to be based on solve.QP and is intended for making a population projection matrix. QPmat asks for: nout, A time series of population vectors and C, C constraint matrix, (with two more vectors, b and nonzero). i believe the relevant code from QPmat is: function (nout, C, b, nonzero) { if (!"quadprog" %in% (.packages())) { library(quadprog) } n <- dim(nout) z <- nout[, 2:n[2]] z <- matrix(z, n[1] * (n[2] - 1), 1) M <- c() for (i in 1:(n[2] - 1)) { N <- kronecker(t(nout[, i]), diag(n[1])) m <- N[, nonzero] M <- rbind(M, m) } G <- t(M) %*% M f <- t(M) %*% z res <- solve.QP(G, f, -t(C), -b) i'm receiving the error "Error in solve.QP(G, f, -t(C), -b) : matrix D in quadratic function is not positive definite!" solve.QP documentation says that Dmat goes into the place that is referred to in the code as G. i've two matrices. nout is 31x3 and all elements are 0 or positive. my C matrix is 31 x 31 and has a -1 running diagonal from the upper left to the lower right, with everything else 0. i'm somewhat confused by what matrix or element is being multiplied as it leads up to G and all i can guess is that i didn't construct the C matrix correctly. how would i do that? sorry if i have too much info or am missing something. thanks for your time. john
jpolo at mail.usf.edu
2008-Apr-10 16:22 UTC
[R] QP.solve, QPmat, constraint matrix, and positive definite
hello all, i'm trying to use QPmat, from the popbio package. it appears to be based on solve.QP and is intended for making a population projection matrix. QPmat asks for: nout, A time series of population vectors and C, C constraint matrix, (with two more vectors, b and nonzero). i believe the relevant code from QPmat is: function (nout, C, b, nonzero) { if (!"quadprog" %in% (.packages())) { library(quadprog) } n <- dim(nout) z <- nout[, 2:n[2]] z <- matrix(z, n[1] * (n[2] - 1), 1) M <- c() for (i in 1:(n[2] - 1)) { N <- kronecker(t(nout[, i]), diag(n[1])) m <- N[, nonzero] M <- rbind(M, m) } G <- t(M) %*% M f <- t(M) %*% z res <- solve.QP(G, f, -t(C), -b) i'm receiving the error "Error in solve.QP(G, f, -t(C), -b) : matrix D in quadratic function is not positive definite!" solve.QP documentation says that Dmat goes into the place that is referred to in the code as G. i've two matrices. nout is 31x3 and all elements are 0 or positive. my C matrix is 31 x 31 and has a -1 running diagonal from the upper left to the lower right, with everything else 0. i'm somewhat confused by what matrix or element is being multiplied as it leads up to G and all i can guess is that i didn't construct the C matrix correctly. how would i do that? sorry if i have too much info or am missing something. thanks for your time. john
jpolo at mail.usf.edu
2008-Apr-12 01:53 UTC
[R] QP.solve, QPmat, constraint matrix, and positive definite
i found the posdefify, nearcor, and nearPD functions, but can't get things to work. when i tried nearPd, it gave me an dpoMatrix, but i don't know if it would have worked because it said: "31 x 31 Matrix of class "dpoMatrix" " right between $mat and the actual matrix and i don't know how to cut that out. i'm not sure i'm even putting the right variables in the right places, relative to the functions' respective requirements. sorry about double-posting as well. the web interface for school's email uses some lousy jsp that times out in the middle of emails and whatnot. john