I am trying to run the R Script below, I have actually simplified it to just this part that is causing issues. When I run this script I continue to get an error that says "cannot rescale a constant/zero column to a unit variance". I cannot figure out what is going on here. I have stripped down my data file so it is more manageable so I can try to figure this out. The data.txt file that is being read looks like this: I have made this file very basic on purpose to see if I could get this to work, but it is not working. Of course once I get this to actually work I will expand the data file to match the data I am actually using. If I change the attribute in the prcomp function to scale=FALSE of course I can run my script. But if it is scaling...which is causing the issues, it errors. Any help would be GREATLY appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Cannot-rescale-a-constant-zero-column-error-tp4647996.html Sent from the R help mailing list archive at Nabble.com.
On Oct 31, 2012, at 5:47 AM, fillay89 wrote:> I am trying to run the R Script below,There is no script (or data description) appearing in this posting to the Rhelp Mailing List. Nabble is not Rhelp, despite Nabble's effort to get you to think it is an archive. Please review the Posting Guide that I know you were offered when you posted from Nabble. Yes, we could view this in Nabble, but most of us choose not to do so. This is a technical mailing list, not a website or chat-room. -- David.> I have actually simplified it to just > this part that is causing issues. When I run this script I continue to get > an error that says "cannot rescale a constant/zero column to a unit > variance". I cannot figure out what is going on here. I have stripped down > my data file so it is more manageable so I can try to figure this out. > > The data.txt file that is being read looks like this: > > > I have made this file very basic on purpose to see if I could get this to > work, but it is not working. Of course once I get this to actually work I > will expand the data file to match the data I am actually using. > > > > If I change the attribute in the prcomp function to scale=FALSE of course I > can run my script. But if it is scaling...which is causing the issues, it > errors. > > Any help would be GREATLY appreciated. > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Cannot-rescale-a-constant-zero-column-error-tp4647996.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.David Winsemius, MD Alameda, CA, USA
Sounds like one of your data columns is constant. The variance of a constant is 0, and scaling would then divide by 0, which is impossible. Kevin Wright On Wed, Oct 31, 2012 at 7:47 AM, fillay89 <jasonfill@gmail.com> wrote:> I am trying to run the R Script below, I have actually simplified it to > just > this part that is causing issues. When I run this script I continue to get > an error that says "cannot rescale a constant/zero column to a unit > variance". I cannot figure out what is going on here. I have stripped > down > my data file so it is more manageable so I can try to figure this out. > > The data.txt file that is being read looks like this: > > > I have made this file very basic on purpose to see if I could get this to > work, but it is not working. Of course once I get this to actually work I > will expand the data file to match the data I am actually using. > > > > If I change the attribute in the prcomp function to scale=FALSE of course I > can run my script. But if it is scaling...which is causing the issues, it > errors. > > Any help would be GREATLY appreciated. > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Cannot-rescale-a-constant-zero-column-error-tp4647996.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Kevin Wright [[alternative HTML version deleted]]
On 10/31/2012 11:47 PM, fillay89 wrote:> I am trying to run the R Script below, I have actually simplified it to just > this part that is causing issues. When I run this script I continue to get > an error that says "cannot rescale a constant/zero column to a unit > variance". I cannot figure out what is going on here. I have stripped down > my data file so it is more manageable so I can try to figure this out. > > The data.txt file that is being read looks like this: > > > I have made this file very basic on purpose to see if I could get this to > work, but it is not working. Of course once I get this to actually work I > will expand the data file to match the data I am actually using. > > > > If I change the attribute in the prcomp function to scale=FALSE of course I > can run my script. But if it is scaling...which is causing the issues, it > errors. > > Any help would be GREATLY appreciated. >Hi fillay89, You seem to be trying to run a principal component analysis on two numbers, which won't produce anything useful. If I make up some data that is more realistic: pcmatrix<-data.frame(Q1=sample(1:5,10,TRUE),Q2=sample(1:5,10,TRUE)) pcmatrix[,1] <- pcmatrix[,1] + 96 pcmatrix[,2] <- pcmatrix[,2] + 96 x.pca <- prcomp(pcmatrix,retx=TRUE,center=TRUE,scale=TRUE,cor=TRUE) x.pca Standard deviations: [1] 1.263267 0.635733 Rotation: PC1 PC2 Q1 0.7071068 -0.7071068 Q2 0.7071068 0.7071068 it runs and I get a slightly more useful result. Running your code does bomb in exactly the way you describe, as does: x.pca <- prcomp(data.frame(Q1=99,Q2=98), retx=TRUE, center=TRUE, scale=TRUE, cor=TRUE) Error in prcomp.default(data.frame(Q1 = 99, Q2 = 98), retx = TRUE, center = TRUE, : cannot rescale a constant/zero column to unit variance Your problem is that you have a data frame with only one value (i.e. a constant) in each column. Jim