[R] fBasics
hello ! I'm trying to follow some examples in fBasics ... the routine needs a 'fields' function but doesn't find it : here's the code : library(fBasics) library(fSeries) symbol=AOLA ymd2cymd - function(x) { # Transfor Date: output - is.character(x) x - as.integer(as.character(x)) x - (19+cumsum(1-sign(c(1,diff(x/2)*100 + x if(output) x - as.character(x) # Return result: x } file=paste(symbol,.csv,sep=) query=paste(s=,symbol,d=7e=22f=2004g=da=7b=8c=2000,sep=) STOCK = yahooImport(save=TRUE,file=file,source=http://ichart.yahoo.com/ table.csv?,query=query) FULLTABLE - matrix (data=scan(file=file,what=,skip=1,sep=,),byrow=T,ncol=7) PRIJZEN - c(as.real(FULLTABLE[,2])) namesFULLTABLE - fields(scan(file=file,n=1,what=,sep=\n)) ^ - here happens the error ! FULLTABLE[,1] - ymd2cymd(rev(dates(FULLTABLE[,1],format=d-mon- y,out.format=ymd,century=2000))) FULLTABLE - data.frame(FULLTABLE) names(FULLTABLE) - namesFULLTABLE for( i in 2:length(namesFULLTABLE) ) FULLTABLE[,i] - rev(FULLTABLE[,i]) write.table(FULLTABLE,file=file, dinnames.write=colnames) can someone help ? thanks in advance __ [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] Variable Importance in pls: R or B? (and in glpls?)
Dear R-users, dear Ron I use pls from the pls.pcr package for classification. Since I need to know which variables are most influential onto the classification performance, what criteria shall I look at: a) B, the array of regression coefficients for a certain model (means a certain number of latent variables) (and: squared or absolute values?) OR b) the weight matrix RR (or R in the De Jong publication; in Ding Gentleman this is the P Matrix and called 'loadings')? (and again: squared or absolute values?) and what about glpls (glpls1a) ? shall I look at the 'coefficients' (regression coefficients)? Thanks for clarification Christoph __ [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
Re: [R] boxplot() from list
On Sun, 2004-09-12 at 10:10, Laura Quinn wrote: I have a list containing 48 objects (each with 30 rows and 4 columns, all numeric), and wish to produce 4 boxplot series (with 48 plots in each) , one for each column of each object. Basically I want a boxplot from boxplot(mylist[[]][,i]) for i in 1:4. It seems that I can create a boxplot of length 48 from the entire list, but I don't seem able to subscript to return 4 boxplots from the list - I have also tried to create 4 new lists (one for each column of each object) by using variations on the following, but none seems to work: newlist-oldlist[,1] newlist-oldlist[[]][,1] newlist-oldlist[[]][,$colone] can anyone please offer some insight?? Thanks in advance, For each individual boxplot, you could do something like: boxplot(data.frame(sapply(mylist, function(x) x[, 1]))) adjusting the index (1) for each of the four columns in your list matrices. You can then adjust the additional arguments to boxplot() as you require. See ?sapply for more information on accessing list member elements and returning a vector or matrix. HTH, Marc Schwartz __ [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
RE: [R] boxplot() from list
Dear Laura, You don't say what kind of objects are in the list, but suppose that they are matrices; here's a scaled-down example using 3 list elements: M1 - matrix(rnorm(30*4), 48, 4) M2 - matrix(rnorm(30*4), 48, 4) M3 - matrix(rnorm(30*4), 48, 4) L - list(M1=M1, M2=M2, M3=M3) par(mfrow=c(3, 4)) lapply(L, function(x) apply(x, 2, boxplot)) I hope that this helps, John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Laura Quinn Sent: Sunday, September 12, 2004 10:10 AM To: [EMAIL PROTECTED] Subject: [R] boxplot() from list I have a list containing 48 objects (each with 30 rows and 4 columns, all numeric), and wish to produce 4 boxplot series (with 48 plots in each) , one for each column of each object. Basically I want a boxplot from boxplot(mylist[[]][,i]) for i in 1:4. It seems that I can create a boxplot of length 48 from the entire list, but I don't seem able to subscript to return 4 boxplots from the list - I have also tried to create 4 new lists (one for each column of each object) by using variations on the following, but none seems to work: newlist-oldlist[,1] newlist-oldlist[[]][,1] newlist-oldlist[[]][,$colone] can anyone please offer some insight?? Thanks in advance, Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT __ [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
Re: [R] boxplot() from list
On Sun, 12 Sep 2004, Marc Schwartz wrote: On Sun, 2004-09-12 at 10:10, Laura Quinn wrote: I have a list containing 48 objects (each with 30 rows and 4 columns, all numeric), and wish to produce 4 boxplot series (with 48 plots in each) , one for each column of each object. Basically I want a boxplot from boxplot(mylist[[]][,i]) for i in 1:4. It seems that I can create a boxplot of length 48 from the entire list, but I don't seem able to subscript to return 4 boxplots from the list - I have also tried to create 4 new lists (one for each column of each object) by using variations on the following, but none seems to work: newlist-oldlist[,1] newlist-oldlist[[]][,1] newlist-oldlist[[]][,$colone] can anyone please offer some insight?? Thanks in advance, For each individual boxplot, you could do something like: boxplot(data.frame(sapply(mylist, function(x) x[, 1]))) adjusting the index (1) for each of the four columns in your list matrices. You can then adjust the additional arguments to boxplot() as you require. See ?sapply for more information on accessing list member elements and returning a vector or matrix. I think that is overly complex, as boxplot accepts a list. I had tested (but decided not to send) mylist - vector(list, 48) for(i in 1:48) mylist[[i]] - matrix(rnorm(30*4), 30) for (J in 1:4) boxplot(lapply(mylist, function(x, j) x[, j], j = J)) -- 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 __ [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
Re: [R] boxplot() from list
On Sun, 2004-09-12 at 11:42, Prof Brian Ripley wrote: On Sun, 12 Sep 2004, Marc Schwartz wrote: On Sun, 2004-09-12 at 10:10, Laura Quinn wrote: I have a list containing 48 objects (each with 30 rows and 4 columns, all numeric), and wish to produce 4 boxplot series (with 48 plots in each) , one for each column of each object. Basically I want a boxplot from boxplot(mylist[[]][,i]) for i in 1:4. It seems that I can create a boxplot of length 48 from the entire list, but I don't seem able to subscript to return 4 boxplots from the list - I have also tried to create 4 new lists (one for each column of each object) by using variations on the following, but none seems to work: newlist-oldlist[,1] newlist-oldlist[[]][,1] newlist-oldlist[[]][,$colone] can anyone please offer some insight?? Thanks in advance, For each individual boxplot, you could do something like: boxplot(data.frame(sapply(mylist, function(x) x[, 1]))) adjusting the index (1) for each of the four columns in your list matrices. You can then adjust the additional arguments to boxplot() as you require. See ?sapply for more information on accessing list member elements and returning a vector or matrix. I think that is overly complex, as boxplot accepts a list. I had tested (but decided not to send) mylist - vector(list, 48) for(i in 1:48) mylist[[i]] - matrix(rnorm(30*4), 30) for (J in 1:4) boxplot(lapply(mylist, function(x, j) x[, j], j = J)) Fair enough. I did not want to presume that the remaining arguments to boxplot might be the same for each plot. Though one could also put those into an appropriate structure and still do the loop. Also, if using the display, one would probably want to set par(ask = TRUE), lest the four plots flash by in rapid sequence. Marc __ [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] can't get the quartz window to the background
Dear List, I have switched from Linux to OS X, and I find the R interface there really nice. I am using Emacs+ESS, and the quartz device. My only problem is that 1. I can't move the quartz window, whenever I go above it I see a spinning rainbow circle (AFAIK that means I am busy or can't touch me in OS X) 2. Once something gets in front of it, I cannot raise it any more. 3. I don't see it when I cycle the windows with Alt-Tab I am sure that I am missing something, read the manual and searched the archives, but found no solution to this. That might be because I am really new to OS X. Thanks, Tamas __ [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
Re: [R] can't get the quartz window to the foreground (was: background)
On Sun, Sep 12, 2004 at 01:50:21PM -0400, Tamas K Papp wrote: 1. I can't move the quartz window, whenever I go above it I see a spinning rainbow circle (AFAIK that means I am busy or can't touch me in OS X) 2. Once something gets in front of it, I cannot raise it any more. 3. I don't see it when I cycle the windows with Alt-Tab Sorry, misleading subject. My problem is that I can't get it to the _foreground_. Tamas __ [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
Re: [R] Cancor
Irena Komprej irena.komprej at telemach.net writes: I am strugling with cancor procedure in R. I cannot figure out the meaning of xcoef and of yxcoef. Are these: 1. standardized coefficients 2. structural coefficients 3. something else? Look at the examples at the bottom of ?cancor from which its evident xcoef is such that x %*% cxy$xcoef are the canonical variables. (More at the end of this post.) I have tried to simulate canonical correlation analysis by checking the eigenstructure of the expression: Sigma_xx %*% Sigma_xy %*% Sigma_yy %*% t(Sigma_xy). The resulting eigenvalues were the same as the squared values of cancor$cor. I have normalized the resulting eigenvectors, the a's with sqrt(a'%*%Sigma_xx%*%t(a)), and similarly the b's with sqrt(b'%*%Sigma_yy%*%t(b)). The results differed considerably from xcoef and ycoef of the cancor. Run the example in the help page to get some data and some output: set.seed(1) example(cancor) # Also, define isqrt as the inverse square root of a postive def matrix isqrt - function(x) { e - eigen(x) stopifnot( all(e$values 0) ) e$vectors %*% diag(1/sqrt(e$values)) %*% solve(e$vectors) } # we can reconstruct the canonical correlations and xcoef # in the way you presumably intended like this: z - svd(cov(x,y) %*% solve(var(y), cov(y,x)) %*% solve(var(x))) sqrt(z$d) # canonical correlations isqrt((nrow(x)-1)*var(x)) %*% z$u# xcoef Another thing you can do is to type cancor at the R prompt to view its source and see how it works using the QR decomposition. __ [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] calculating error
Could anybody explain this results? sin(2*pi) -2.449213e-16 #should be zero (10^16)*sin(log2(4)*pi) -2.449213 #should be zero too and explain what to do to correct this events? Thanks!!! Branimir K. Hackenberger __ [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
Re: [R] calculating error
On Sunday 12 September 2004 13:28, Branimir K. Hackenberger wrote: Could anybody explain this results? sin(2*pi) -2.449213e-16 #should be zero It is, in the sense that all.equal(sin(2*pi), 0) [1] TRUE (10^16)*sin(log2(4)*pi) -2.449213 #should be zero too and explain what to do to correct this events? For starters, you need to invent and then use an infinite precision computer where the variable 'pi' is really the ratio between the circumference and radius of a circle, and not just a finite precision approximation of it. Good luck trying :-) Deepayan __ [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
Re: [R] calculating error
Branimir K. Hackenberger hack at ffos.hr writes: : : Could anybody explain this results? : : sin(2*pi) : -2.449213e-16 #should be zero : : : (10^16)*sin(log2(4)*pi) : -2.449213 #should be zero too : : : and explain what to do to correct this events? Someone else has already explained why this is. In terms of what you can do, in general, you have to keep finite precision in mind when performing computer calculations using floating point representations. Sometimes there are tricks. If you know that the result or an intermediate result will be integer then if the error is sufficiently small you can round it at that point: R round(sin(2*pi)) [1] 0 R (10^16)*round(sin(log2(4)*pi)) [1] 0 If exact arithmetic is required you may need to use a symbolic mathematics package capable of exact arithmetic. There are both free, e.g. yacas, and commercial ones, e.g. mathematica, maple. For example, in yacas: In Sin(2*Pi); Out 0; In (10^16)*Sin(IntLog(4,2)*Pi) Out 0; __ [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
Re: [R] SAS to R migration questions
I copied your data into Excel and saved it as *.txt. From within R, the following commands produced for me the result cited in your email below: salesData - read.table(R-qn.txt, header=TRUE, sep=\t, as.is=TRUE) sapply(salesData, class)# check class of columns of salesData reversal - regexpr(\\(, salesData$salepx) rev - which(reversal0) salesData[-c(rev, rev-1),] If R-qn.txt contained gigabytes, R might die in read.table. For that, you will need to process the data base in smaller pieces. The R Data Import/Export manual [available, e.g., via help.start() from within R] discusses various ways of interacting direction with relational databases, etc. hope this helps. spencer graves Matthew Wilson wrote: Hi, I'd like to get away from SAS, but I don't really know R well enough at this point to know if it would be good for this project. I tried to describe the essence of the project below without getting bogged down in details. It starts when I receive a data flat file. There's lots of columns, but the relevant ones are: custid (customer ID number) saledt (date of sale) salepx (sale price) Step 1: I read in this data into a SAS dataset. Some of these flat files hold several gigabytes of data. SAS allows indexes to be created on columns which really speeds up queries. I read the R import/export doc and it suggested using databases for really big datasets. I figured I'd probably use perl or python to read the file and convert it to either an R .tab file or to load the data into a SQL database for the big files (Postgres or MySQL, since I'm trying to go 100% open source with this). Step 2: In the data, I'll usually find one row per sale, but occasionally, a sale will be entered incorrectly at first, then later reversed, then a third line will show the correct sale data: custid saledt salepx 111 8/1/2004$75 111 9/1/2004$50 112 10/1/2004 $30 112 10/1/2004 ($30) 112 10/1/2004 $20 The fourth line reverses the third line by showing a negative charge for the same customer ID and sale date, and the last line is the correct line. I want to compress all those adjustments and reversals lines out of the data, so the outgoing data would look like this: custid saledt salepx 111 8/1/2004$75 111 9/1/2004$50 112 10/1/2004 $20 In SAS, I use a proc summary step in SAS to accomplish this: proc summary data=d1; class custid saledt; var salepx; output out=d2 sum=; run; This is where I need help: how to do this step in R? Step 3: I print a list of number of sales per customer ID, ranking the customer IDs from most to least. I use a SAS proc freq step for this: proc freq data=d2 order=freq; tables custid; run; and the output would look like this: custid freq 111 2 112 1 Again, I have no idea how to do step 3 in R. Thanks in advance! All help is welcome. Is this kind of work what R is good at? -- Spencer Graves, PhD, Senior Development Engineer O: (408)938-4420; mobile: (408)655-4567 __ [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] mahalanobis distance
Is there a function that calculate the mahalanobis distance in R . The dist function calculates euclidean', 'maximum', 'manhattan', 'canberra', 'binary' or 'minkowski'. Thanks ../Murli __ [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
RE: [R] mahalanobis distance
See (surprising enough) ?mahalanobis... Andy From: Murli Nair Is there a function that calculate the mahalanobis distance in R . The dist function calculates euclidean', 'maximum', 'manhattan', 'canberra', 'binary' or 'minkowski'. Thanks ../Murli __ [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 __ [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
RE: [R] mahalanobis distance
Dear Murli, Try ?mahalanobis, which, by the way, is turned up by help.search(mahalanobis). I hope this helps, John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Murli Nair Sent: Sunday, September 12, 2004 3:17 PM To: [EMAIL PROTECTED] Subject: [R] mahalanobis distance Is there a function that calculate the mahalanobis distance in R . The dist function calculates euclidean', 'maximum', 'manhattan', 'canberra', 'binary' or 'minkowski'. Thanks ../Murli __ [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
Re: [R] SAS to R migration questions
Matthew Wilson writes: (...) Step 3: I print a list of number of sales per customer ID, ranking the customer IDs from most to least. I use a SAS proc freq step for this: proc freq data=d2 order=freq; tables custid; run; and the output would look like this: custid freq 111 2 112 1 Again, I have no idea how to do step 3 in R. Provided that you are going to work with this data stored in a SQL database, it'll probably be more efficient to do this sort of manipulation directly in SQL. Anyways, the following lines of code in R will do what you described: cust - c(111,111,112) cc - data.frame(t(sapply(unique(cust),function(level,vec) { c(custid=level,freq=sum(vec==level)) },cust))) cc[order(cc$freq,decreasing=T),] Cheers, -- Fernando Henrique Ferraz P. da Rosa http://www.ime.usp.br/~feferraz __ [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
Re: [R] SAS to R migration questions
Fernando Henrique Ferraz P. da Rosa writes: cust - c(111,111,112) cc - data.frame(t(sapply(unique(cust),function(level,vec) { c(custid=level,freq=sum(vec==level)) },cust))) cc[order(cc$freq,decreasing=T),] An even simpler solution: cc - data.frame(table(cust)) cc[order(cc$Freq,decreasing=T),] -- Fernando Henrique Ferraz P. da Rosa http://www.ime.usp.br/~feferraz __ [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] How to personalize principal components analysis
Hallo! Does anybody know if it is possible to choose the function to be maximazed in the principal components analysis?Thanks Simone Vantini __ [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] Controling a tcl/tk slider
Hi, Is there any command in R that drags a tcl/tk slider to a particular position (value)? thanks in advance, Johan Van Horebeek __ [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] pairwise deletion of missing cases in lm
Does anybody know if there is some sort of pairwise option for handling missing cases in lm and computing the relevant statistics? I would be much obliged if anyone could help... Regards Alan Simpson Roberts Research Group __ [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