[R] what is best for scripting?
I am using R in Windows. I see that I will have to use batch processes with R. I will have to read and write text files, and run some R code; probably some external code too. I have never done scripting. Is there any document that explains simple steps with examples? I also have heard that Python is a good scripting language. Is it worth the effort? (I do not have too much free time, so if I could do without, much better ...). Has anybody strong opinions on that? Past experiences? Thank you! Jordi The information contained herein is confidential and is inte...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] using predict and recalibrating repeatedly?
Let us say I have a time series I want to forecast. I have decided I am going to use ppr, nnet and svm. I calibrate my model with these 3 algorithms (let us assume I use all the data for the calibration; I do not distinguish here between training and testing: all data are used for training, just for simplification of the exposition). Now, I get a new data point for the time series. I use the predict method with the 3 calibrations. This is fast. I get a new data point. I use the predict method. And so on. But at some point in time, I want to recalibrate my 3 algorithms. This takes time. What I would like is the following: Let us assume I have 1000 data points. I calibrate my algorithms to this data set. Let us assume that I get a new data point every minute, and let us assume it takes half an hour for the calibration of one of the algorithms. What I want is that for the first 30 data points, I am using the old predict. Then, after this point, I start a calibration with 1030 data points. But this will take a long time (until I have acquired 1060 points). What I want is to use the old predict (the calibration when there were 1000 data points). When the calibration with the 1060 points is over and I get the data point No. 1061, I would like that automatically, when I call the predict method, the new predict is called, not the old one. Is there an easy way to do this? Of course, the ideal would be to have the calibration in one computer and the predict in another, but I guess that this adds too much complexity to the mix ... Thank you. The information contained herein is confidential and is inte...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to open a text file in my screen (not in the R session)?
In the middle of my code, I have the following: write.table(PredictionTest, file = predictions.txt) what I would like is that inmediately after this line is executed, the file predictions.txt is opened in the middle of my screen (not in my R session, where I continue running my code). Is there an easy way to do that? Thank you The information contained herein is confidential and is inte...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to open a text file in my screen (not in the R sessio n)?
Thank you for all the answers. I have used system(notepad predictions.txt,wait=FALSE) and it works. Just a final question: is there a way to force the file to open on top of all the other applications in my desktop? -Original Message- From: Massimiliano Tripoli [mailto:[EMAIL PROTECTED] Sent: 23 November 2005 19:39 To: Molins, Jordi; 'r-help@stat.math.ethz.ch' Cc: Jordi Molins Subject: Re: [R] How to open a text file in my screen (not in the R session)? You could use the following istruction: system(notepad predictions.txt,wait=FALSE) I hope this will be helpful. Regards, Massimiliano At 01:00 AM 11/23/2005, Molins, Jordi wrote: In the middle of my code, I have the following: write.table(PredictionTest, file = predictions.txt) what I would like is that inmediately after this line is executed, the file predictions.txt is opened in the middle of my screen (not in my R session, where I continue running my code). Is there an easy way to do that? Thank you The information contained herein is confidential and is inte...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] books about MCMC to use MCMC R packages?
Dear list users, I need to learn about MCMC methods, and since there are several packages in R that deal with this subject, I want to use them. I want to buy a book (or more than one, if necessary) that satisfies the following requirements: - it teaches well MCMC methods; - it is easy to implement numerically the ideas of the book, and notation and concepts are similar to the corresponding R packages that deal with MCMC methods. I have done a search and 2 books seem to satisfy my requirements: - Markov Chain Monte Carlo In Practice, by W.R. Gilks and others. - Monte Carlo Statistical methods, Robert and Casella. What do people think about these books? Is there a suggestion of some other book that could satisfy better my requirements? Thank you very much in advance. The information contained herein is confidential and is inte...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] mars of degree 3?
Dear list, when I execute library(mda) x1 - rnorm(10,mean=1,sd=.12) x2 - rnorm(10,mean=.6,sd=.12) y - pp(x1,1)+pp(x1,1)*pp(x2,.6)+.12*rnorm(length(x1)) mymars - mars(cbind(x1,x2),y,degree=2) mymars$cuts mymars$factor I get what I expected. Instead, when I execute x1 - rnorm(10,mean=1,sd=.12) x2 - rnorm(10,mean=.6,sd=.12) x3 - rnorm(10,mean=.2,sd=.12) y - pp(x1,1)+pp(x2,.6)+pp(x3,.2)+pp(x1,1)*pp(x2,.6)+pp(x1,1)*pp(x3,.2)+pp(x2,.6) *pp(x3,.2)+pp(x1,1)*pp(x2,.6)*pp(x3,.2)+.12*rnorm(length(x1)) mymars - mars(cbind(x1,x2,x3),y,degree=3,prune=FALSE) mymars$cuts mymars$factor or x1 - rnorm(10,mean=1,sd=.12) x2 - rnorm(10,mean=.6,sd=.12) x3 - rnorm(10,mean=.2,sd=.12) y - pp(x1,1)*pp(x2,.6)*pp(x3,.2)+.12*rnorm(length(x1)) mymars - mars(cbind(x1,x2,x3),y,degree=3,prune=FALSE) mymars$cuts mymars$factor I do not get the term of interaction degree 3. What am I thinking wrong? Thank you Jordi The information contained herein is confidential and is inte...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] mars of degree 3?
I have forgotten to list the definition of pp. Here it is: pp - function(x,a) {ifelse(xa, x-a, 0)} __ Dear list, when I execute library(mda) x1 - rnorm(10,mean=1,sd=.12) x2 - rnorm(10,mean=.6,sd=.12) y - pp(x1,1)+pp(x1,1)*pp(x2,.6)+.12*rnorm(length(x1)) mymars - mars(cbind(x1,x2),y,degree=2) mymars$cuts mymars$factor I get what I expected. Instead, when I execute x1 - rnorm(10,mean=1,sd=.12) x2 - rnorm(10,mean=.6,sd=.12) x3 - rnorm(10,mean=.2,sd=.12) y - pp(x1,1)+pp(x2,.6)+pp(x3,.2)+pp(x1,1)*pp(x2,.6)+pp(x1,1)*pp(x3,.2)+pp(x2,.6) *pp(x3,.2)+pp(x1,1)*pp(x2,.6)*pp(x3,.2)+.12*rnorm(length(x1)) mymars - mars(cbind(x1,x2,x3),y,degree=3,prune=FALSE) mymars$cuts mymars$factor or x1 - rnorm(10,mean=1,sd=.12) x2 - rnorm(10,mean=.6,sd=.12) x3 - rnorm(10,mean=.2,sd=.12) y - pp(x1,1)*pp(x2,.6)*pp(x3,.2)+.12*rnorm(length(x1)) mymars - mars(cbind(x1,x2,x3),y,degree=3,prune=FALSE) mymars$cuts mymars$factor I do not get the term of interaction degree 3. What am I thinking wrong? Thank you Jordi The information contained herein is confidential and is inte...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] again, a question between R and C++
Dear R Users, I want to make a call from R into C++. My inputs are List1, List2, List3, IntegerID. The amount of elements of the lists and their type depend on IntegerID. Typical elements of a given list can be vectors, doubles, and even other lists. I want to return also a list (whose nature will depend also, possibly, on IntegerID). What I want to do is to call these 4 inputs from C++ and then use a factory pattern (depending on IntegerID) that will perform different calculations on the lists depending on the IntegerID (of course, I could also do this with a simple switch statement). I have been reading the documentation, especially the one regarding .Call and .External, and it seems that my algorithm could be implemented, but the examples I have seen up to now are such that what occupies the place of my lists are just vectors (like in convolve4 example). Is there an example where I could see how instead of a vector, a set of lists (with an unkown number of arguments, as well as unkown types) are used as inputs? I guess that the ideal would be that in the equivalent of the convolve4 function, my args would be variant type of lists, and then, after the factory pattern is called, and the correct class is registered (via IntegerID), this variant type is really decomposed into the individual types that compose the list (ie, vectors, doubles, ...). Of course, in the factory there should be as many decomposing algorithms as IntegerIDs, each creating a particular decomposition. Also, how returning a list (whose nature will depend also, possibly, on IntegerID) should be handled? Thank you in advance Jordi The information contained herein is confidential and is inte...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] memory error message using MASS and GLMMGibbs
Hello, I was just testing the MASS code examples for chapter 10 (Random and Mixed Effects) and I have pasted the following code in an R session (2.1.0 in windows 2000 professional; I have also Xemacs + ESS installed, but I was not using them at that time; my machine has quite a lot of RAM): library(MASS) library(lattice) library(nlme) library(GLMMGibbs) # declare a random intercept for each subject epil$subject - Ra(data = factor(epil$subject)) glmm(y ~ lbase*trt + lage + V4 + subject, family = poisson, data = epil, keep = 10, thin = 100) and then an Application Error appears: The instruction at 0x1001edc9 referenced memory at 0x0008. The memory could not be written. It does not take long for this message to appear (less than 1s after I type Enter). Any help is welcome Jordi The information contained herein is confidential and is inte...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] cross-correlations
Hello, I have been looking around in past helps about cross-correlations for a set of n time series. Although you can do it by yourself calculating the out-of-the-diagonal terms in the cross correlation matrix by using pairwise combinations of ccf and the diagonal terms by using acf, this does not seem a very practical way of doing things. Does anybody know a function that gives directly the cross-correlation matrix? thanks Jordi The information contained herein is confidential and is inte...{{dropped}} __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] not positive definite D matrix in quadprog
Hello to everybody, I have a quadratic programming problem that I am trying to solve by various methods. One of them is to use the quadprog package in R. When I check positive definiteness of the D matrix, I get that one of the eigenvalues is negative of order 10^(-8). All the others are positive. When I set this particular eigenvalue to 0.0 and I recheck the eigenvalues in R, the last eigenvalue is positive of order 10^(-12). I try to use solve.QP, but I get an error message that matrix D in quadratic function is not positive definite. For reference, a fully R session is listed below. Is 10^(-12) too close to 0? i.e., does R consider that with an eigenvalue of order +10^(-12) the matrix is not positive definite but positive semidefinite? In general, has somebody know a way (in R or outside R, maybe in c++) to solve quadratic programming with positive semidefinite matrices? In particular, my problem is not so hard: given y an n x 1 matrix, and beta an n x m matrix, I want to find an m x 1 matrix x s. t. sum(y - beta * x)^2 is minimum. The particularity is that I want to impose restrictions on x: all x components should be between 0 and 1, and there are also constraints of the type A x = b, where A and b have the necessary dimensions to ensure consistency. I have tried with some other packages, and they do not give a correct solution when the system increases in size (e.g., 24 variables and 9 constraint equations) ... some idea? thanks! Jordi _ The problem: library(MASS) library(quadprog) D - matrix(c(439.5883658,438.8445615,438.1007572,2430.285506,2426.162884,2422.04 0262,44.21800696,44.14261394, 438.8445615,438.1020157,437.3594699,2426.173348,2422.057702,2417.942056,44.1 43188,44.06792255, 438.1007572,437.3594699,449.6727418,2445.212326,2542.83573,2643.780669,50.19 455336,52.04059805, 2430.285506,2426.173348,2445.212326,13491.19467,13614.55046,13737.90625,253. 4897678,255.745654, 2426.162884,2422.057702,2542.83573,13614.55046,14687.86142,15923.99043,313.8 180838,336.4239658, 2422.040262,2417.942056,2643.780669,13737.90625,15923.99043,19107.7405,410.9 729841,472.5104919, 44.21800696,44.143188,50.19455336,253.4897678,313.8180838,410.9729841,9.5462 51262,11.57677661, 44.14261394,44.06792255,52.04059805,255.745654,336.4239658,472.5104919,11.57 677661,14.51245153),8,8) D.vectors - eigen(D,only.values=F)$vectors D.values - eigen(D,only.values=F)$values #the last value is negative D.values [1] 4.609489e+04 2.458166e+03 8.232288e+01 1.961199e+00 5.976441e-01 [6] 2.810968e-01 1.253157e-09 -2.685763e-08 D.quad - matrix(0,8,8) diag(D.quad) - D.values #checking that the eigenvalue decomposition works fine D.vectors%*%D.quad%*%ginv(D.vectors) D.quad[8,8] [1] -2.685763e-08 D.quad[8,8] - 0.0 #checking; nothing changes too much D.vectors%*%D.quad%*%ginv(D.vectors) #now all eigenvalues are positive: D.values.new - eigen(D.vectors%*%D.quad%*%ginv(D.vectors),only.values=F)$values D.values.new [1] 4.609489e+04 2.458166e+03 8.232288e+01 1.961199e+00 5.976441e-01 [6] 2.810968e-01 1.253140e-09 1.428534e-12 Dmat - D.vectors%*%D.quad%*%ginv(D.vectors) dvec - -c(-2910.533769,-2905.609008,-3012.223863,-16274.97455,-17222.46423,-18380.6 391,-357.8878464,-379.6371849) #this ensures that coefficients are positive: Amat - matrix(0,8,8) diag(Amat) - 1 bvec - rep(0,8) #it says D is not positive definite ... solve.QP(Dmat,dvec,Amat,bvec=bvec) Error in solve.QP(Dmat, dvec, Amat, bvec = bvec) : matrix D in quadratic function is not positive definite! The information contained herein is confidential and is inte...{{dropped}} __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] a question about identify and locator
Hello, I use R 1.9.1 on Windows 2000. I have a chart that I am looking. I use identify() and locator() to find out the (x,y) values of interesting points in the chart, but these functions are not always helpful (e.g., sometimes identify() prints on top of the chart, making the number illegible). What I would be interested in is in a functionality that identifies the (x,y) point using something like a text box superimposed on the chart that disappears when the cursor is away from the chart (for example, similar to Excel) or even better, small text boxes located both in the x and y axis near to the points (0,y) and (x,0), resp., that are constantly updated (like charts in Bloomberg) . Is there something like this in R? Thank you Jordi The information contained herein is confidential and is inte...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] SVD with positivity constraints
Hello, I have a matrix equation, Ax=b, that I need to solve for x. x should be a vector of positive numbers (between 0 and 1). A is not a square matrix in general. This lead me to using the SVD. However, using the SVD gives me positive and negative numbers, as well. I have some constraints included in the A matrix itself (i.e., that the sum of some xi should be equal to 1) but I do not know how to include the constraint that each xi should be non-negative. Is there in R (or somewhere else) an SVD that includes this kind of constraint? or some other optimizer that can cope with solving non-square matrix equations, including the positivity constraint? I know that this is not really an R question, sorry for that. Jordi Jordi Molins Short Term Products / Treasury Capital Markets Dresdner Kleinwort Wasserstein phone +49 69 713 15329 fax +49 69 713 19804 mobile +49 171 171 64 61 mailto:[EMAIL PROTECTED] The information contained herein is confidential and is inte...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] SVD with positivity constraints
Thank you to Prof Brian Ripley and to Ken Knoblauch for your replies. I should explain a little bit more about the problem at hand: in principle, the matrix can have more rows than columns or the other way around. However, I always could include in an artificial way more equations, such that there are more equations than unknowns. So, in practical terms, the first question from Prof Brian Ripley is: more equations than unkowns. I have Additionally, I have seen in several places that is suggested to use La.svd instead of the standard svd. -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: 27 July 2004 10:13 To: Molins, Jordi Cc: '[EMAIL PROTECTED]' Subject: Re: [R] SVD with positivity constraints If A is not square, which dimension is larger? There will most likely be either no solution or an infinity of solutions. If the latter, I think you are using the Moore-Penrose inverse (depends exactly how you use the SVD), that is the shortest solution, but the SVD will give you the whole space of solutions and you could compute if that intersects the positive orthant. On Tue, 27 Jul 2004, Molins, Jordi wrote: I have a matrix equation, Ax=b, that I need to solve for x. x should be a vector of positive numbers (between 0 and 1). A is not a square matrix in general. This lead me to using the SVD. However, using the SVD gives me positive and negative numbers, as well. I have some constraints included in the A matrix itself (i.e., that the sum of some xi should be equal to 1) but I do not know how to include the constraint that each xi should be non-negative. Is there in R (or somewhere else) an SVD that includes this kind of constraint? or some other optimizer that can cope with solving non-square matrix equations, including the positivity constraint? optim(method=L-BFGS-B) can cope with [0, 1] constraints. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 The information contained herein is confidential and is inte...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Recall: [R] SVD with positivity constraints
The sender would like to recall the message, [R] SVD with positivity constraints. The information contained herein is confidential and is inte...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] SVD with positivity constraints
Thank you to Prof Brian Ripley and to Ken Knoblauch for your fast replies. I should explain a little bit more about the problem at hand: in principle, the matrix can have more rows than columns or the other way around. However, I always could include in an artificial way more equations, such that there are more equations than unknowns. So, in practical terms, the answer to the first question from Prof Brian Ripley is: more equations than unkowns. I have checked in the Modern Applied Statistics with S 4th edition, and in page 62 it is shown the use of svd. It is written that svd gives, as result, u, v and d. If there is a space of solutions (as opposed to a unique solution) how is the solution given? how can I retrieve the whole space of solutions? Additionally, I have seen in several places that is suggested to use La.svd instead of the standard svd. Would the La.svd generate also the whole space of solutions? I have looked the documentation (http://cran.r-project.org/doc/packages/RScaLAPACK.pdf) but it is not explicitly written how to retrieve non-unique solutions. An additional question: in the Numerical Recipes for C++ it is written that the small numbers in the diagonal of d should be set manually to 0. Is this done (maybe as an option) in svd or in La.svd? could this resetting have a material effect in the solutions found? thank you J -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: 27 July 2004 10:13 To: Molins, Jordi Cc: '[EMAIL PROTECTED]' Subject: Re: [R] SVD with positivity constraints If A is not square, which dimension is larger? There will most likely be either no solution or an infinity of solutions. If the latter, I think you are using the Moore-Penrose inverse (depends exactly how you use the SVD), that is the shortest solution, but the SVD will give you the whole space of solutions and you could compute if that intersects the positive orthant. On Tue, 27 Jul 2004, Molins, Jordi wrote: I have a matrix equation, Ax=b, that I need to solve for x. x should be a vector of positive numbers (between 0 and 1). A is not a square matrix in general. This lead me to using the SVD. However, using the SVD gives me positive and negative numbers, as well. I have some constraints included in the A matrix itself (i.e., that the sum of some xi should be equal to 1) but I do not know how to include the constraint that each xi should be non-negative. Is there in R (or somewhere else) an SVD that includes this kind of constraint? or some other optimizer that can cope with solving non-square matrix equations, including the positivity constraint? optim(method=L-BFGS-B) can cope with [0, 1] constraints. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 The information contained herein is confidential and is inte...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] SVD with positivity constraints
Hello, what I wrote below is nonsense: if the matrix has more equations than unknowns, it makes no sense considering the general space of solutions. Sorry for that. Another consideration: could somebody give me an opinion about the following procedure? the simplex algorithm maximizes z=a00x0 + a01x1+...+a0(N-1)x(N-1) subject to x0=0, ... x(N-1)=0 and under M=m1+m2+m3 constraints: m1 equations for = inequalities(with x on the left), m2 equations for = inequalities, and m3 equations for equalities (=). Consider a00=a01=...=a0(N-1)=0 (degenerate in some sense), and let me choose also m1=m2=0, and then m3 being the number of equations I have. Using the simplex method for linear programing would give me my solution, or would this method give me a degenerate solution? thank you, and please bear with me my desesperation ;- Jordi -Original Message- From: Molins, Jordi Sent: 27 July 2004 11:33 To: '[EMAIL PROTECTED]' Cc: 'Prof Brian Ripley'; 'Ken Knoblauch' Subject: RE: [R] SVD with positivity constraints Thank you to Prof Brian Ripley and to Ken Knoblauch for your fast replies. I should explain a little bit more about the problem at hand: in principle, the matrix can have more rows than columns or the other way around. However, I always could include in an artificial way more equations, such that there are more equations than unknowns. So, in practical terms, the answer to the first question from Prof Brian Ripley is: more equations than unkowns. I have checked in the Modern Applied Statistics with S 4th edition, and in page 62 it is shown the use of svd. It is written that svd gives, as result, u, v and d. If there is a space of solutions (as opposed to a unique solution) how is the solution given? how can I retrieve the whole space of solutions? Additionally, I have seen in several places that is suggested to use La.svd instead of the standard svd. Would the La.svd generate also the whole space of solutions? I have looked the documentation (http://cran.r-project.org/doc/packages/RScaLAPACK.pdf) but it is not explicitly written how to retrieve non-unique solutions. An additional question: in the Numerical Recipes for C++ it is written that the small numbers in the diagonal of d should be set manually to 0. Is this done (maybe as an option) in svd or in La.svd? could this resetting have a material effect in the solutions found? thank you J -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: 27 July 2004 10:13 To: Molins, Jordi Cc: '[EMAIL PROTECTED]' Subject: Re: [R] SVD with positivity constraints If A is not square, which dimension is larger? There will most likely be either no solution or an infinity of solutions. If the latter, I think you are using the Moore-Penrose inverse (depends exactly how you use the SVD), that is the shortest solution, but the SVD will give you the whole space of solutions and you could compute if that intersects the positive orthant. On Tue, 27 Jul 2004, Molins, Jordi wrote: I have a matrix equation, Ax=b, that I need to solve for x. x should be a vector of positive numbers (between 0 and 1). A is not a square matrix in general. This lead me to using the SVD. However, using the SVD gives me positive and negative numbers, as well. I have some constraints included in the A matrix itself (i.e., that the sum of some xi should be equal to 1) but I do not know how to include the constraint that each xi should be non-negative. Is there in R (or somewhere else) an SVD that includes this kind of constraint? or some other optimizer that can cope with solving non-square matrix equations, including the positivity constraint? optim(method=L-BFGS-B) can cope with [0, 1] constraints. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 The information contained herein is confidential and is inte...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html