[R] Use "append" in the function write.xlsx2 or write.xlsx (openxlsx package)
Hi, I am trying to print several dataset in several different sheets of the same xlsx file. I sometimes run the codes more than once, and I need to erase all things in the target file, and I do not use "append" in the first function call. However I want to write it in a loop. Is there a way to initiate a blank xlsx file so that I can use "append = TRUE" whenever I call the function write.xlsx2? output_file2<-"data_xx.xlsx" write.xlsx2(x= df_all2[["a"]], file = output_file2, sheetName = "a") write.xlsx2(x= df_all2[["b"]], file = output_file2, sheetName = "b", append=TRUE) write.xlsx2(x= df_all2[["c"]], file = output_file2, sheetName = "c", append= TRUE) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Extracting rows of a data.frame by "identical"
Is it possible? I am expecting the result to be the second row of the data frame ... d<-data.frame(a=1:3, b=3:5,c=9:11) > d a b c 1 1 3 9 2 2 4 10 3 3 5 11 > d[identical(d[c("b","c")],c(4,10)),] [1] a b c <0 rows> (or 0-length row.names) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Can't rename a data frame column
Hi, Could someone suggest a way to rename a data frame column? For example, I want to rename the column beta, but I can't do it this way > d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9) > mm<-"beta" > rename(d, c(mm="two", "gamma"="three")) The following `from` values were not present in `x`: mm alpha beta three 1 14 7 2 25 8 3 36 9 Of course this would work > rename(d, c("beta"="two", "gamma"="three")) alpha two three 1 1 4 7 2 2 5 8 3 3 6 9 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] How to print the frequency table (produced by the command "table" to Excel
Thanks. Could we print the row/column names, "alpha1" and "alpha2" to the csv file? 2016-04-30 17:06 GMT-07:00 Jim Lemon <drjimle...@gmail.com>: > Hi jpm miao, > I think you can get what you want like this: > > alpha1<-sample(LETTERS[1:3],50,TRUE) > alpha2<-sample(LETTERS[1:2],50,TRUE) > alphas<-data.frame(alpha1,alpha2) > library(prettyR) > alphatab<-xtab(alpha1~alpha2,alphas) > sink("temp_table3.csv",append=TRUE) > delim.xtab(alphatab,pct=NA,delim=",") > sink() > > Jim > > On Sun, May 1, 2016 at 4:47 AM, jpm miao <miao...@gmail.com> wrote: > > Jim, > > > >Thanks for creating such a fantastic package "prettyR". > >I want to print the pretty frequency table (with row total and column > > total) to an excel (or csv ) file. Is it possible? > >>alphatab > > > > A B Total > > A 8 10 18 > > B 7 5 12 > > C 9 11 20 > > Total 24 26 50 > > > >Two issues I encountered (See the attached csv file). > > 1. When I tried to print the above table to csv file, all elements on the > > same row are printed in one cell. > > 2. If I write "delim.table(alpha tab)", the table is distorted (see > > attached). Of course, I can adjust it manually but sometimes the number > of > > files is big. > > > > Thanks! > > > > Miao > > > >> alpha1<-sample(LETTERS[1:3],50,TRUE) > >> alpha2<-sample(LETTERS[1:2],50,TRUE) > >> > >> alphas<-data.frame(alpha1,alpha2) > >> alphatab<-xtab(alpha1~alpha2,alphas) > > Crosstabulation of alpha1 by alpha2 > > alpha2 > > alpha1 A B > > A 8 10 18 > >44.44 55.56 - > >33.33 38.46 36.00 > > > > B 7 5 12 > >58.33 41.67 - > >29.17 19.23 24.00 > > > > C 9 11 20 > > 45 55 - > >37.50 42.31 40.00 > > > > 24 26 50 > > 48 52100 > >> delim.xtab(alphatab,pct=NA,interdigitate=TRUE) > > alphatab > > > > A B Total > > A 8 10 18 > > B 7 5 12 > > C 9 11 20 > > Total 24 26 50 > > > >> sink("temp_table3.csv") > >> delim.xtab(alphatab,pct=NA,interdigitate=TRUE) > >> sink() > >> sink("temp_table3.csv", append=TRUE) > >> delim.table(alphatab) > >> sink() > >> sink("temp_table3.csv", append=TRUE) > >> delim.table(alphatab) > >> sink() > >> ?delim.xtab > > > > > > 2016-04-26 16:14 GMT-07:00 Jim Lemon <drjimle...@gmail.com>: > >> > >> Hi jpm miao, > >> You can get CSV files that can be imported into Excel like this: > >> > >> library(prettyR) > >> sink("excel_table1.csv") > >> delim.table(table(df[,c("y","z")])) > >> sink() > >> sink("excel_table2.csv") > >> delim.table(as.data.frame(table(df[,c("y","z")])),label="") > >> sink() > >> sink("excel_table3.csv") > >> delim.table(as.matrix(table(df[,c("y","z")])),label="") > >> sink() > >> > >> Jim > >> > >> On Wed, Apr 27, 2016 at 8:35 AM, jpm miao <miao...@gmail.com> wrote: > >> > Hi, > >> > > >> >How could we print the frequency table (produced by "table") to an > >> > Excel > >> > file? > >> >Is there an easy way to do so? Thanks, > >> > > >> > Miao > >> > > >> >> df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3]) > >> > > >> >> table(df[,c("y","z")]) > >> >z > >> > y a b c > >> > 1 0 0 1 > >> > 2 0 1 0 > >> > 3 1 0 0 > >> >> test<-table(df[,c("y","z")]) > >> >> as.data.frame(test) > >> > y z Freq > >> > 1 1 a0 > >> > 2 2 a0 > >> > 3 3 a1 > >> > 4 1 b0 > >> > 5 2 b1 > >> > 6 3 b0 > >> > 7 1 c1 > >> > 8 2 c0 > >> > 9 3 c0 > >> >> as.matrix(test) > >> >z > >> > y a b c > >> > 1 0 0 1 > >> > 2 0 1 0 > >> > 3 1 0 0 > >> >> testm<-as.matrix(test) > >> >> testm > >> >z > >> > y a b c > >> > 1 0 0 1 > >> > 2 0 1 0 > >> > 3 1 0 0 > >> >> typeof(testm) > >> > [1] "integer" > >> > > >> > [[alternative HTML version deleted]] > >> > > >> > __ > >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> > 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. > > > > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] How to print the frequency table (produced by the command "table" to Excel
Jim, Thanks for creating such a fantastic package "prettyR". I want to print the pretty frequency table (with row total and column total) to an excel (or csv ) file. Is it possible? >alphatab A B Total A 8 10 18 B 7 5 12 C 9 11 20 Total 24 26 50 Two issues I encountered (See the attached csv file). 1. When I tried to print the above table to csv file, all elements on the same row are printed in one cell. 2. If I write "delim.table(alpha tab)", the table is distorted (see attached). Of course, I can adjust it manually but sometimes the number of files is big. Thanks! Miao > alpha1<-sample(LETTERS[1:3],50,TRUE) > alpha2<-sample(LETTERS[1:2],50,TRUE) > > alphas<-data.frame(alpha1,alpha2) > alphatab<-xtab(alpha1~alpha2,alphas) Crosstabulation of alpha1 by alpha2 alpha2 alpha1 A B A 8 10 18 44.44 55.56 - 33.33 38.46 36.00 B 7 5 12 58.33 41.67 - 29.17 19.23 24.00 C 9 11 20 45 55 - 37.50 42.31 40.00 24 26 50 48 52100 > delim.xtab(alphatab,pct=NA,interdigitate=TRUE) alphatab A B Total A 8 10 18 B 7 5 12 C 9 11 20 Total 24 26 50 > sink("temp_table3.csv") > delim.xtab(alphatab,pct=NA,interdigitate=TRUE) > sink() > sink("temp_table3.csv", append=TRUE) > delim.table(alphatab) > sink() > sink("temp_table3.csv", append=TRUE) > delim.table(alphatab) > sink() > ?delim.xtab 2016-04-26 16:14 GMT-07:00 Jim Lemon <drjimle...@gmail.com>: > Hi jpm miao, > You can get CSV files that can be imported into Excel like this: > > library(prettyR) > sink("excel_table1.csv") > delim.table(table(df[,c("y","z")])) > sink() > sink("excel_table2.csv") > delim.table(as.data.frame(table(df[,c("y","z")])),label="") > sink() > sink("excel_table3.csv") > delim.table(as.matrix(table(df[,c("y","z")])),label="") > sink() > > Jim > > On Wed, Apr 27, 2016 at 8:35 AM, jpm miao <miao...@gmail.com> wrote: > > Hi, > > > >How could we print the frequency table (produced by "table") to an > Excel > > file? > >Is there an easy way to do so? Thanks, > > > > Miao > > > >> df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3]) > > > >> table(df[,c("y","z")]) > >z > > y a b c > > 1 0 0 1 > > 2 0 1 0 > > 3 1 0 0 > >> test<-table(df[,c("y","z")]) > >> as.data.frame(test) > > y z Freq > > 1 1 a0 > > 2 2 a0 > > 3 3 a1 > > 4 1 b0 > > 5 2 b1 > > 6 3 b0 > > 7 1 c1 > > 8 2 c0 > > 9 3 c0 > >> as.matrix(test) > >z > > y a b c > > 1 0 0 1 > > 2 0 1 0 > > 3 1 0 0 > >> testm<-as.matrix(test) > >> testm > >z > > y a b c > > 1 0 0 1 > > 2 0 1 0 > > 3 1 0 0 > >> typeof(testm) > > [1] "integer" > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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 -- To UNSUBSCRIBE and more, see 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] How to print the frequency table (produced by the command "table" to Excel
Hi, How could we print the frequency table (produced by "table") to an Excel file? Is there an easy way to do so? Thanks, Miao > df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3]) > table(df[,c("y","z")]) z y a b c 1 0 0 1 2 0 1 0 3 1 0 0 > test<-table(df[,c("y","z")]) > as.data.frame(test) y z Freq 1 1 a0 2 2 a0 3 3 a1 4 1 b0 5 2 b1 6 3 b0 7 1 c1 8 2 c0 9 3 c0 > as.matrix(test) z y a b c 1 0 0 1 2 0 1 0 3 1 0 0 > testm<-as.matrix(test) > testm z y a b c 1 0 0 1 2 0 1 0 3 1 0 0 > typeof(testm) [1] "integer" [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] table , exclude - count the frequency in a data frame but exclude one value
Hi, I have a data frame with two variables x, y, both of which take values in the set {1,2,3}. I'd like to count the frequency by the command "table", but exclude the value "1" in variable x, but keep "1" in variable y. Is it possible? When I use "exclude", value 1 in both x and y are excluded. Thanks, > df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3]) > table(df[,c("y","x")]) x y 1 2 3 1 0 0 1 2 0 1 0 3 1 0 0 > table(df[,c("y","x")], exclude = 1) x y 2 3 2 1 0 3 0 0 > table(df[,c("y","x")], exclude = c(NULL, 1)) x y 2 3 2 1 0 3 0 0 > table(df[,c("y","x")], exclude = c(1, NULL)) x y 2 3 2 1 0 3 0 0 > table(df[,c("y","x")], exclude = c(1, 0)) x y 2 3 2 1 0 3 0 0 > table(df[,c("y","x")], exclude = list(1 , NULL)) Error in as.vector(exclude, typeof(x)) : (list) object cannot be coerced to type 'integer' [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Java memory error when reading a small xlsx file
Hi, I tried to read a (small) xlsx file by "readWorksheetFromFile" function of "XLConnect" package and "read.xlsx" function in "xlsx" package, but I got this error message: Error: OutOfMemoryError (Java): Java heap space I tried to follow the solution on the web http://stackoverflow.com/questions/21937640/handling-java-lang-outofmemoryerror-when-writing-to-excel-from-r and I did add a line to my program ### options(java.parameters = "-Xmx8000m") #or options(java.parameters = "-Xmx1000m") ### but it did not work. I wonder if I need to detach the packages before adding that line detach("package:XLConnect", unload=TRUE) detach("package:xlsx", unload=TRUE) detach("package:xlsxjars", unload=TRUE) detach("package:XLConnectJars", unload=TRUE) detach("package:rJava", unload=TRUE) options(java.parameters = "-Xmx8000m") library(XLConnect) library(xlsx) ### but it did not work. I am on a Mac, with very new OS and very new R version. R version 3.2.4 (2016-03-10) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.11.3 (El Capitan) Could someone guide me how to solve the problem? Thanks! Miao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Add a vertical arrow to a time series graph using ggplot and xts
Hi, I am trying to add a vertical arrow (from top to bottom or from bottom to up) to a time series plot using ggplot2 and xts. It seems that the vertical line command "geom_vline" does not work for this purpose (Correct me if I am wrong). I try the command "geom_segment" as follows, but I got an error message at the last line "Error: Invalid input: date_trans works with objects of class Date only". Sometimes the error message occurs when I run the program, sometimes it does not occur until I call the plot "p1". How could I add a vertical line to the plot? Thanks! Miao ## library(xts) # primary #library(tseries) # Unit root tests library(ggplot2) library(vars) library(grid) dt_xts<-xts(x = 1:10, order.by = seq(as.Date("2016-01-01"), as.Date("2016-01-10"), by = "1 day")) colnames(dt_xts)<-"gdp" xmin<-min(index(dt_xts)) xmax<-max(index(dt_xts)) df1<-data.frame(x = index(dt_xts), coredata(dt_xts)) p<-ggplot(data = df1, mapping= aes(x=x, y=gdp))+geom_line() rg<-ggplot_build(p)$panel$ranges[[1]]$y.range y1<-rg[1] y2<-rg[2] df2<-data.frame(x = "2016-01-05", y1=y1, y2=y2 ) p1<-p+geom_segment(mapping=aes(x=x, y=y1, xend=x, yend=y2), data=df2, arrow=arrow()) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] How to print the graphs in landscape/portrait orientation (revised)
Hi, I made a few graphs by ggplot. The following codes produce a pdf file with graphs, sometimes in landscape orientation, sometimes in portrait orientation. I am using both Mac and Windows PC. Question: how can I control the orientation of the pdf file? I try to add a line pdf(paper = “USr”) (or pdf(paper="letter")) in the following code, but it does not work. Thanks!! # library(ggplot2) library(grid) library(gridExtra)# Output graphs to files n<-100 p2<-array(list(NA),dim=n) # pdf(paper = "Usr") # pdf(paper = "letter") for(i in 1:n) { p2[i][[1]]<-ggplot(data.frame(x=1:(i+1), y=seq(2,2*(i+1),2)), aes(x=x, y=y))+ geom_line(color="blue") } m2 <- marrangeGrob(p2, nrow=3, ncol=2) ggsave("test_160409xyz.pdf", m2) ## [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] How to print the graphs in landscape/portrait orientation
Hi, I made a few graphs by ggplot. The following codes produce a pdf file with graphs in landscape orientation on my Windows PC, while they produce a pdf file with the same graphs, but in portrait orientation: *p2 <- lapply(1:(2*n), function(.x) xyz_outl[.x][[1]]) #a sequence of graphs made by ggplot* *m2 <- marrangeGrob(p2, nrow=3, ncol=2) * *ggsave("xyz.pdf", m2)* Question: how can I let the graphs printed in landscape orientation on my Mac? I try to add the following line before the above code, but it does not work. *pdf(paper = "Usr")* Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] readWorksheetFromFile error message: invalid 'envir' argument
Hi, I try to read a large xlsx file from by the function "readWorksheetFromFile" in "XLConnect" package. Sometimes it works, but sometimes it gives an error message. When it does not work and I try to run the program line by line (in RStudio), then it would sometimes work, but sometimes it does not. When it does not run, restarting RStudio sometimes works. How can I fix the problem? Thanks, > date_col<-readWorksheetFromFile("dt-160FXO_many_xyz_data.xlsx", sheet=2, region="A1:A3137") Error in ls(envir = envir, all.names = private) : invalid 'envir' argument Miao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] How can we let "multiplot.R" return a plot?
Hi, The function "ggplot" does plot and return a plot. For example, we can write: y = ggplot(.. .) Then y is a plot. How can we modify the multiplot function so that it can also return a plot? Multiplot.R is here: http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/, and the code is as below. Any advice on returning a multi-ggplot would help! Thanks, Miao # Multiple plot function # # ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects) # - cols: Number of columns in layout # - layout: A matrix specifying the layout. If present, 'cols' is ignored. # # If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), # then plot 1 will go in the upper left, 2 will go in the upper right, and # 3 will go all the way across the bottom. # multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) { library(grid) # Make a list from the ... arguments and plotlist plots <- c(list(...), plotlist) numPlots = length(plots) # If layout is NULL, then use 'cols' to determine layout if (is.null(layout)) { # Make the panel # ncol: Number of columns of plots # nrow: Number of rows needed, calculated from # of cols layout <- matrix(seq(1, cols * ceiling(numPlots/cols)), ncol = cols, nrow = ceiling(numPlots/cols)) } if (numPlots==1) { print(plots[[1]]) } else { # Set up the page grid.newpage() pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout # Make each plot, in the correct location for (i in 1:numPlots) { # Get the i,j matrix positions of the regions that contain this subplot matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE)) print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row, layout.pos.col = matchidx$col)) } } } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Could the function "addPlot.RTF {rtf}" add multiplots to Word?
Hi, I am outputting a large number of graphs (made by ggplot2) to a Word file. The function "addPlot" in the package "rtf" does help output the graphs sequentially in one column; can it be modified so that it outputs graphs in more than one columns? (I try R2wd package, but it does not work well on my computer) Could we let the ggplot2-related graph function return more than one graph (e.g., cowplot package or "multiplot.R" function http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/ and then use addPlot? Any suggested alternative would help! Thanks!! Miao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Is there any concise way to write a one-to-one mapping?
My code is: if(type=="none") type2<-"nc" if(type=="drift") type2<-"c" if(type=="trend") type2<-"ct" I am wondering if there's a concise way to write a mapping from type to type2, especially when the number of categories is high. Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Make a Excel chart by R code
Hi, I understand that there're many great graphic packages in R (e.g., ggplot2) . Nevertheless, my office uses Excel extensively. Is there any package in R that produces Excel graphs by R codes? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Which is better: Modifying an existing package or creating a new one?
Hi, Given that I frequently use A, B, C, D, E packages. In each of the 5 packages, I intend to modify one of the functions. Two ways: 1st: Modify A, B, C, D, E to A', B', C', D', E' Then I will use library(A') . library(E') instead of A, B, C, D, E. or Just keep the names A, B, C, D, E but modify the content 2nd: create a package F and add the five functions to the F package. For each of the 5 functions, a line library(A)... or library(E) is required. Then I will need library(F) when I create a new program. Which is a better way in terms of time consumption and code portability? If I move the codes to a new computer, which way will be easier? Any suggestion? Thanks, Miao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] r2wd (Write R to Word) in Chinese
Hi, The package r2wd is good at writing MS Word document from R. Can Chinese be written into MS Word by this package or any other method from R? Are Chinese fonts (e.g., Kai 楷書) available in r2wd? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] An easy question on package building/installation
Hi, I try to build a package myself on RStudio. The command package.skeleton is successfully run, but the command build is not. In my case, the username and the package name are both abcd. Error message: R CMD build abcd Error: unexpected symbol in R CMD Could someone help me to write a correct build command? Thanks! Full log: setwd(D:/0B/R/pkg-abcd) setwd(D:/0B/R/pkg-abcd) package.skeleton(name=abcd) Creating directories ... Creating DESCRIPTION ... Creating NAMESPACE ... Creating Read-and-delete-me ... Saving functions and data ... Making help files ... Done. Further steps are described in './abcd/Read-and-delete-me'. setwd(D:/0B/R/pkg-abcd/abcd) dir() [1] data DESCRIPTIONman [4] NAMESPACE R Read-and-delete-me .libPaths() [1] C:/Users/abcd/Documents/R/win-library/3.0 [2] C:/Program Files/R/R-3.0.1/library R CMD build abcd Error: unexpected symbol in R CMD R CMD build C:\Users\abcd\Documents\R\win-library\3.0 Error: unexpected symbol in R CMD R CMD INSTALL -1 C:/Users/abcd/Documents/R/win-library/3.0 abcd Error: unexpected symbol in R CMD [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Segmented (piecewise linear) regression/cointegration
Hi, If the relation between y and x is piecewise linear, the package segmented can be used to model it. It works pretty well. My situation is a little different: y and x are both I(1). Is there an R-package dealing with this situation? If not, is there an econometrics paper on this issue? Some papers deal with the case in which the relation between x and y changes at a certain time point, but my case is different- the relation between x and y changes when x exceeds some break point. Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Extracting slots from an object (e.g.: object produced by unit root test function urdfTest)
Hi, I run a statistical test function in the package fUnitRoots that returns a S4 object but I am wondering how to extract the p-value, one of the output elements. The document of the function urdfTest: . All tests return an object of class fHTEST with the following slots: @call . @test a list object which holds the output of the underlying test function. @title . The entries of the @test slot include the following components: $statistic .. $p.value the p-value of the test. . (end) I store the result of the test test in an element of a list (adf1[r3m][[1]]), and I want to extract the p-value. I was expecting the p-value via adf1[r3m][[1]]@test$p.value but it gives only an error message. Could someone tell me how to extract the p-value? Thanks!!! adf1[r3m][[1]]-urdfTest(dat[,i], lags = 1, type = ct) adf1[r3m][[1]] [1] [2] Test regression trend [3] [4] Call: [5] lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag) [6] [7] Residuals: [8] Min 1Q Median 3Q Max [9] -3.0785 -0.0485 0.0072 0.0627 3.5672 [10] [11] Coefficients: [12] Estimate Std. Error t value Pr(|t|) [13] (Intercept) -1.733e-02 9.529e-03 -1.818 0.06910 . [14] z.lag.1 -7.060e-03 2.343e-03 -3.013 0.00261 ** [15] tt 5.299e-06 4.927e-06 1.076 0.28221 [16] z.diff.lag -1.035e-01 1.859e-02 -5.569 2.81e-08 *** [17] --- [18] Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 [19] [20] Residual standard error: 0.2107 on 2864 degrees of freedom [21] Multiple R-squared: 0.01461,\tAdjusted R-squared: 0.01358 [22] F-statistic: 14.15 on 3 and 2864 DF, p-value: 3.716e-09 [23] [24] [25] Value of test-statistic is: -3.0134 3.0697 4.5828 [26] [27] Critical values for test statistics: [28] 1pct 5pct 10pct [29] tau3 -3.96 -3.41 -3.12 [30] phi2 6.09 4.68 4.03 [31] phi3 8.27 6.25 5.34 adf1[r3m][[1]]@test Error: trying to get slot test from an object of a basic class (character) with no slots adf1[r3m][[1]]@test$p-value Error: trying to get slot test from an object of a basic class (character) with no slots [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Extracting slots from an object (e.g.: object produced by unit root test function urdfTest)
Thank you very much. Could we extract the p-value in the output of the ur.df function? Does there exist any unit root test function where the p-value can be extracted? Thanks! An example for ur.df function: data(Raotbl3) attach(Raotbl3) lc.df - ur.df(y=lc, lags=3, type='trend') summary(lc.df) 2015-03-13 1:23 GMT+08:00 David Winsemius dwinsem...@comcast.net: On Mar 12, 2015, at 1:04 AM, jpm miao wrote: Hi, I run a statistical test function in the package fUnitRoots that returns a S4 object but I am wondering how to extract the p-value, one of the output elements. The document of the function urdfTest: . All tests return an object of class fHTEST with the following slots: @call . @test a list object which holds the output of the underlying test function. @title . The entries of the @test slot include the following components: $statistic .. $p.value the p-value of the test. . (end) I store the result of the test test in an element of a list (adf1[r3m][[1]]), and I want to extract the p-value. I was expecting the p-value via adf1[r3m][[1]]@test$p.value but it gives only an error message. Could someone tell me how to extract the p-value? Thanks!!! If you look at the code by typing: fUnitRoots::urdfTest, you should quickly see why you are seeing text output: That function is doing the equivalent of a console screenscrape: ... output = capture.output(summary(urca))[-(1:4)] ... # and then assigns a trimmed version of that result to the `test`- slot. So the documentation is misleading in suggesting that a list object is being returned in the `test` slot. It's just a character vestor. -- adf1[r3m][[1]]-urdfTest(dat[,i], lags = 1, type = ct) adf1[r3m][[1]] [1] [2] Test regression trend [3] [4] Call: [5] lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag) [6] [7] Residuals: [8] Min 1Q Median 3Q Max [9] -3.0785 -0.0485 0.0072 0.0627 3.5672 [10] [11] Coefficients: [12] Estimate Std. Error t value Pr(|t|) [13] (Intercept) -1.733e-02 9.529e-03 -1.818 0.06910 . [14] z.lag.1 -7.060e-03 2.343e-03 -3.013 0.00261 ** [15] tt 5.299e-06 4.927e-06 1.076 0.28221 [16] z.diff.lag -1.035e-01 1.859e-02 -5.569 2.81e-08 *** [17] --- [18] Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 [19] [20] Residual standard error: 0.2107 on 2864 degrees of freedom [21] Multiple R-squared: 0.01461,\tAdjusted R-squared: 0.01358 [22] F-statistic: 14.15 on 3 and 2864 DF, p-value: 3.716e-09 [23] [24] [25] Value of test-statistic is: -3.0134 3.0697 4.5828 [26] [27] Critical values for test statistics: [28] 1pct 5pct 10pct [29] tau3 -3.96 -3.41 -3.12 [30] phi2 6.09 4.68 4.03 [31] phi3 8.27 6.25 5.34 That is being displayed as a multi-element text object. You instead need to show the code that actually created that object. adf1[r3m][[1]]@test Error: trying to get slot test from an object of a basic class (character) with no slots adf1[r3m][[1]]@test$p-value Error: trying to get slot test from an object of a basic class (character) with no slots [[alternative HTML version deleted]] Please learn to post in palin text. -- David Winsemius Alameda, CA, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Extracting slots from an object (e.g.: object produced by unit root test function urdfTest)
Sorry. Let me modify the question: Does there exist any unit root test function (with trend or intercept) where the p-value can be extracted? The function adf.test in tseries package does return the p-value, but there's no choice of trend or intercept. Thanks. 2015-03-13 10:49 GMT+08:00 jpm miao miao...@gmail.com: Thank you very much. Could we extract the p-value in the output of the ur.df function? Does there exist any unit root test function where the p-value can be extracted? Thanks! An example for ur.df function: data(Raotbl3) attach(Raotbl3) lc.df - ur.df(y=lc, lags=3, type='trend') summary(lc.df) 2015-03-13 1:23 GMT+08:00 David Winsemius dwinsem...@comcast.net: On Mar 12, 2015, at 1:04 AM, jpm miao wrote: Hi, I run a statistical test function in the package fUnitRoots that returns a S4 object but I am wondering how to extract the p-value, one of the output elements. The document of the function urdfTest: . All tests return an object of class fHTEST with the following slots: @call . @test a list object which holds the output of the underlying test function. @title . The entries of the @test slot include the following components: $statistic .. $p.value the p-value of the test. . (end) I store the result of the test test in an element of a list (adf1[r3m][[1]]), and I want to extract the p-value. I was expecting the p-value via adf1[r3m][[1]]@test$p.value but it gives only an error message. Could someone tell me how to extract the p-value? Thanks!!! If you look at the code by typing: fUnitRoots::urdfTest, you should quickly see why you are seeing text output: That function is doing the equivalent of a console screenscrape: ... output = capture.output(summary(urca))[-(1:4)] ... # and then assigns a trimmed version of that result to the `test`- slot. So the documentation is misleading in suggesting that a list object is being returned in the `test` slot. It's just a character vestor. -- adf1[r3m][[1]]-urdfTest(dat[,i], lags = 1, type = ct) adf1[r3m][[1]] [1] [2] Test regression trend [3] [4] Call: [5] lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag) [6] [7] Residuals: [8] Min 1Q Median 3Q Max [9] -3.0785 -0.0485 0.0072 0.0627 3.5672 [10] [11] Coefficients: [12] Estimate Std. Error t value Pr(|t|) [13] (Intercept) -1.733e-02 9.529e-03 -1.818 0.06910 . [14] z.lag.1 -7.060e-03 2.343e-03 -3.013 0.00261 ** [15] tt 5.299e-06 4.927e-06 1.076 0.28221 [16] z.diff.lag -1.035e-01 1.859e-02 -5.569 2.81e-08 *** [17] --- [18] Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 [19] [20] Residual standard error: 0.2107 on 2864 degrees of freedom [21] Multiple R-squared: 0.01461,\tAdjusted R-squared: 0.01358 [22] F-statistic: 14.15 on 3 and 2864 DF, p-value: 3.716e-09 [23] [24] [25] Value of test-statistic is: -3.0134 3.0697 4.5828 [26] [27] Critical values for test statistics: [28] 1pct 5pct 10pct [29] tau3 -3.96 -3.41 -3.12 [30] phi2 6.09 4.68 4.03 [31] phi3 8.27 6.25 5.34 That is being displayed as a multi-element text object. You instead need to show the code that actually created that object. adf1[r3m][[1]]@test Error: trying to get slot test from an object of a basic class (character) with no slots adf1[r3m][[1]]@test$p-value Error: trying to get slot test from an object of a basic class (character) with no slots [[alternative HTML version deleted]] Please learn to post in palin text. -- David Winsemius Alameda, CA, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Add an NA column to a zoo object
Hi , I have a zoo object with several rows fx, r3m, etc. I would like to create in the zoo object the lag of one column. One thing I can think of is to create the lag first and then merge it into the original zoo object, which is tedious. Can I add an NA column to the zoo object first and then put the lag into the NA column? Thanks! datz-zoo(dat, dat[,date1]) fxlag3m-lag(datz[,fx], -65, na.pad=TRUE) datz-merge(datz, fxlag3m) head(datz) date fx r3m r6m r1y date1 fxlag3m 2009-01-01 2009-01-01 90.90 -7.3500 -7.8500 -8.3000 2009-01-01 NA 2009-01-02 2009-01-02 91.16 -7.3458 -8.0487 -8.4645 2009-01-02 NA 2009-01-05 2009-01-05 93.19 -6.9000 -7.6000 -8.2500 2009-01-05 NA 2009-01-06 2009-01-06 93.97 -6.7000 -7.3500 -8.0500 2009-01-06 NA 2009-01-07 2009-01-07 93.23 -6.3500 -7.1000 -7.7000 2009-01-07 NA 2009-01-08 2009-01-08 91.63 -6.6500 -7.3500 -7.8000 2009-01-08 NA [[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] Dealing with NAs in lm or gmm
Hi, My question is about NAs in the function gmm, but I believe that the same issues occur in the case of lm. I try to estimate a model by gmm function (GMM, generalized method of moments). Each of the variables has 94 rows, but the resulting fitted model has only 89 rows. Then the function removes the rows with NAs. I want to add a 94*1 vector, ONI, to the resulting fitted values; I want to find the fitted value with NAs kept. How can I do it? na.action? Code: gmm8-gmm(y~RDR1+xx, xiv) Warning message: In getDat(object$g, object$x) : There are missing values. Associated observations have been removed ONI.gmm8-fitted(gmm8)+0.85*ONI Error in NextMethod(.Generic) : dims [product 89] do not match the length of object [94] In addition: Warning message: In `+.default`(fitted(gmm8), 0.85 * ONI) : longer object length is not a multiple of shorter object length Help on na.action: na.action a function which indicates what should happen when the data contain NAs. The default is set by the na.action setting of options, and is na.fail if that is unset. The ‘factory-fresh’ default is na.omit. Another possible value is NULL, no action. Value na.exclude can be useful. Thanks! Miao [[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] Dealing with NAs in lm or gmm
I tries na.action = na.exclude but it returns a fitted vector with NAs removed. Is there any way to return the fitted vector with NAs (In my case, 94*1 matrix)? gmm8-gmm(y~RDR1+xx, xiv, na.action = na.exclude) Warning message: In getDat(object$g, object$x) : There are missing values. Associated observations have been removed nrow(fitted(gmm8)) [1] 89 nrow(xx) NULL nrow(as.matrix(xx)) [1] 94 nrow(RDR1) [1] 94 nrow(y) [1] 94 2014-10-21 17:27 GMT+08:00 ONKELINX, Thierry thierry.onkel...@inbo.be: You want na.action = na.exclude. Or remove rows with NA values from your dataset. Which is IMHO the safest way to build a model. ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens jpm miao Verzonden: dinsdag 21 oktober 2014 10:29 Aan: r-help Onderwerp: [R] Dealing with NAs in lm or gmm Hi, My question is about NAs in the function gmm, but I believe that the same issues occur in the case of lm. I try to estimate a model by gmm function (GMM, generalized method of moments). Each of the variables has 94 rows, but the resulting fitted model has only 89 rows. Then the function removes the rows with NAs. I want to add a 94*1 vector, ONI, to the resulting fitted values; I want to find the fitted value with NAs kept. How can I do it? na.action? Code: gmm8-gmm(y~RDR1+xx, xiv) Warning message: In getDat(object$g, object$x) : There are missing values. Associated observations have been removed ONI.gmm8-fitted(gmm8)+0.85*ONI Error in NextMethod(.Generic) : dims [product 89] do not match the length of object [94] In addition: Warning message: In `+.default`(fitted(gmm8), 0.85 * ONI) : longer object length is not a multiple of shorter object length Help on na.action: na.action a function which indicates what should happen when the data contain NAs. The default is set by the na.action setting of options, and is na.fail if that is unset. The ‘factory-fresh’ default is na.omit. Another possible value is NULL, no action. Value na.exclude can be useful. Thanks! Miao [[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. * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. [[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] lag operator on a zoo object - code sharing
Hi, I could not find a nice lag operator on zoo object. Perhaps there is, but I just couldn't find it. Basically I want the operator to return the lagged zoo object (with one or more variables ) with the original date. For example, if I write lag(x, -3), then I got the lagged series, but the first three observations are deleted. My code could work, but is not polished. Someone helps or comments? lagzoo-function(x, lag_n) { if(is.zoo(x)==FALSE) { stop(zoo objects for lagzoo, please) } if(ncol(x)==1) { y-x t-time(x) n-length(t) y[(lag_n+1):n]-x[1:(n-lag_n)] y[1:lag_n]-NA return(y) } else { y-x n-nrow(x) y[(lag_n+1):n,]-x[1:(n-lag_n),] y[1:lag_n,]-NA return(y) } } [[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] ggplot scale_x_date : to plot quarterly scale?
Hi, I am plotting time series by ggplot2, but I believe that my question applies to other plotting tool as well. I want to make my x-axis the quarterly scale, e.g: 2000Q1 2000Q2. However, scale_x_date and date_format(%m/%d) support all time formats BUT QUARTERs library(scales) # to access breaks/formatting functions dt + scale_x_date() dt + scale_x_date(labels = date_format(%m/%d)) Is there any solution? Thanks! [[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] Time series Regression with lags
Hi, I am working on zoo (time series) objects. Is there any way to do a time series regression with a lag period? E.g., Y(t) = b1*X1(t)+b2*X(t-1)+b3*X2(t) Is dynlm the default one to use? Anything else Thanks! [[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] Find growth rate of a zoo (time series) object
Hi, Is there any way to find the growth rate of a quarterly/monthly time series? For example, I have a quarterly CPI level series, and I wonder how to find the CPI growth rate (inflation rate). Is there easier way to convert to another class and convert back? Thanks! dput(dtz[1:16,CPI]) structure(c(58.79667, 59.57333, 60.73667, 60.78, 60.90333, 61.39, 62.60667, 62.07333, 62.58, 63.10333, 62.60333, 62.06333, 61.8, 62.75667, 63.0, 62.65333 ), index = structure(c(1981, 1981.25, 1981.5, 1981.75, 1982, 1982.25, 1982.5, 1982.75, 1983, 1983.25, 1983.5, 1983.75, 1984, 1984.25, 1984.5, 1984.75), class = yearqtr), class = zoo) [[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] aggregating a zoo object (monthly data to quarterly data)
I tried to convert a monthly dataset to quarterly by averaging dt_mz-zoo(dt_m, dt_m$date_m) dt_mz2q-aggregate(dt_mz, as.yearqtr, FUN=mean) However, the resulting zoo object are just NAs How can I get a quarterly average dataset? Thanks! dput(dt_mz) structure(c(Jan 1981, Feb 1981, Mar 1981, Apr 1981, May 1981, Jun 1981, Jul 1981, Aug 1981, Sep 1981, Oct 1981, Nov 1981, Dec 1981, Jan 1982, Feb 1982, Mar 1982, Apr 1982, May 1982, Jun 1982, Jul 1982, Aug 1982, Sep 1982, Oct 1982, Nov 1982, Dec 1982, Jan 1983, Feb 1983, Mar 1983, Apr 1983, May 1983, Jun 1983, Jul 1983, Aug 1983, Sep 1983, Oct 1983, Nov 1983, Dec 1983, Jan 1984, Feb 1984, Mar 1984, Apr 1984, May 1984, Jun 1984, Jul 1984, Aug 1984, Sep 1984, Oct 1984, Nov 1984, Dec 1984, Jan 1985, Feb 1985, Mar 1985, Apr 1985, May 1985, Jun 1985, Jul 1985, Aug 1985, Sep 1985, Oct 1985, Nov 1985, Dec 1985, Jan 1986, Feb 1986, Mar 1986, Apr 1986, May 1986, Jun 1986, Jul 1986, Aug 1986, Sep 1986, Oct 1986, Nov 1986, Dec 1986, Jan 1987, Feb 1987, Mar 1987, Apr 1987, May 1987, Jun 1987, Jul 1987, Aug 1987, Sep 1987, Oct 1987, Nov 1987, Dec 1987, Jan 1988, Feb 1988, Mar 1988, Apr 1988, May 1988, Jun 1988, Jul 1988, Aug 1988, Sep 1988, Oct 1988, Nov 1988, Dec 1988, Jan 1989, Feb 1989, Mar 1989, Apr 1989, May 1989, Jun 1989, Jul 1989, Aug 1989, Sep 1989, Oct 1989, Nov 1989, Dec 1989, Jan 1990, Feb 1990, Mar 1990, Apr 1990, May 1990, Jun 1990, Jul 1990, Aug 1990, Sep 1990, Oct 1990, Nov 1990, Dec 1990, Jan 1991, Feb 1991, Mar 1991, Apr 1991, May 1991, Jun 1991, Jul 1991, Aug 1991, Sep 1991, Oct 1991, Nov 1991, Dec 1991, Jan 1992, Feb 1992, Mar 1992, Apr 1992, May 1992, Jun 1992, Jul 1992, Aug 1992, Sep 1992, Oct 1992, Nov 1992, Dec 1992, Jan 1993, Feb 1993, Mar 1993, Apr 1993, May 1993, Jun 1993, Jul 1993, Aug 1993, Sep 1993, Oct 1993, Nov 1993, Dec 1993, Jan 1994, Feb 1994, Mar 1994, Apr 1994, May 1994, Jun 1994, Jul 1994, Aug 1994, Sep 1994, Oct 1994, Nov 1994, Dec 1994, Jan 1995, Feb 1995, Mar 1995, Apr 1995, May 1995, Jun 1995, Jul 1995, Aug 1995, Sep 1995, Oct 1995, Nov 1995, Dec 1995, Jan 1996, Feb 1996, Mar 1996, Apr 1996, May 1996, Jun 1996, Jul 1996, Aug 1996, Sep 1996, Oct 1996, Nov 1996, Dec 1996, Jan 1997, Feb 1997, Mar 1997, Apr 1997, May 1997, Jun 1997, Jul 1997, Aug 1997, Sep 1997, Oct 1997, Nov 1997, Dec 1997, Jan 1998, Feb 1998, Mar 1998, Apr 1998, May 1998, Jun 1998, Jul 1998, Aug 1998, Sep 1998, Oct 1998, Nov 1998, Dec 1998, Jan 1999, Feb 1999, Mar 1999, Apr 1999, May 1999, Jun 1999, Jul 1999, Aug 1999, Sep 1999, Oct 1999, Nov 1999, Dec 1999, Jan 2000, Feb 2000, Mar 2000, Apr 2000, May 2000, Jun 2000, Jul 2000, Aug 2000, Sep 2000, Oct 2000, Nov 2000, Dec 2000, Jan 2001, Feb 2001, Mar 2001, Apr 2001, May 2001, Jun 2001, Jul 2001, Aug 2001, Sep 2001, Oct 2001, Nov 2001, Dec 2001, Jan 2002, Feb 2002, Mar 2002, Apr 2002, May 2002, Jun 2002, Jul 2002, Aug 2002, Sep 2002, Oct 2002, Nov 2002, Dec 2002, Jan 2003, Feb 2003, Mar 2003, Apr 2003, May 2003, Jun 2003, Jul 2003, Aug 2003, Sep 2003, Oct 2003, Nov 2003, Dec 2003, Jan 2004, Feb 2004, Mar 2004, Apr 2004, May 2004, Jun 2004, Jul 2004, Aug 2004, Sep 2004, Oct 2004, Nov 2004, Dec 2004, Jan 2005, Feb 2005, Mar 2005, Apr 2005, May 2005, Jun 2005, Jul 2005, Aug 2005, Sep 2005, Oct 2005, Nov 2005, Dec 2005, Jan 2006, Feb 2006, Mar 2006, Apr 2006, May 2006, Jun 2006, Jul 2006, Aug 2006, Sep 2006, Oct 2006, Nov 2006, Dec 2006, Jan 2007, Feb 2007, Mar 2007, Apr 2007, May 2007, Jun 2007, Jul 2007, Aug 2007, Sep 2007, Oct 2007, Nov 2007, Dec 2007, Jan 2008, Feb 2008, Mar 2008, Apr 2008, May 2008, Jun 2008, Jul 2008, Aug 2008, Sep 2008, Oct 2008, Nov 2008, Dec 2008, Jan 2009, Feb 2009, Mar 2009, Apr 2009, May 2009, Jun 2009, Jul 2009, Aug 2009, Sep 2009, Oct 2009, Nov 2009, Dec 2009, Jan 2010, Feb 2010, Mar 2010, Apr 2010, May 2010, Jun 2010, Jul 2010, Aug 2010, Sep 2010, Oct 2010, Nov 2010, Dec 2010, Jan 2011, Feb 2011, Mar 2011, Apr 2011, May 2011, Jun 2011, Jul 2011, Aug 2011, Sep 2011, Oct 2011, Nov 2011, Dec 2011, Jan 2012, Feb 2012, Mar 2012, Apr 2012, May 2012, Jun 2012, Jul 2012, Aug 2012, Sep 2012, Oct 2012, Nov 2012, Dec 2012, Jan 2013, Feb 2013, Mar 2013, Apr 2013, May 2013, Jun 2013, Jul 2013, Aug 2013, Sep 2013, Oct 2013, Nov 2013, Dec 2013, Jan 2014, Feb 2014, Mar 2014, Apr 2014, May 2014, Jun 2014, Jul 2014, Aug 2014, 58.05, 59.04, 59.30, 59.54, 59.31, 59.87, 60.10, 60.69, 61.42, 61.08, 60.67, 60.59, 60.98, 60.79, 60.94, 61.10, 61.47, 61.60, 61.56, 63.42, 62.84, 62.33, 61.83, 62.06, 62.08, 62.70, 62.96, 63.24, 62.80, 63.27, 62.56, 62.53, 62.72, 62.70, 62.17, 61.32, 61.37, 61.98, 62.15, 62.27, 63.03, 62.97, 62.81, 63.04, 63.25, 62.99, 62.64, 62.33, 62.36, 62.86, 62.89, 62.58, 62.38, 62.29, 62.35, 62.08, 63.11, 63.05, 62.16, 61.52, 62.10, 62.27, 62.26, 62.42, 62.50, 62.66, 62.50, 62.85, 64.44, 64.31, 63.41, 63.13, 62.96, 62.84, 62.34, 62.56, 62.57, 62.62, 63.34, 63.86, 64.09, 63.51, 63.69, 64.35, 63.31, 63.06,
[R] Could someone recommend a package for time series?
Hi, I've not used R for about one year and don't know well about the updates on the time series-related package. My primary job is to do economic/financial time series data analysis - annual, monthly, daily, etc. I usually read data by the package XLConnect, which can read xls or xlsx files directly. It's excellent. However I can't find a package to manipulate time series data. For example, I just want to do an easy manipulation , e.g, to label the dates of the data from , say, 1991M10 to 2014M07, and then extract part of the data, say, 2005M01 to 2010M12 and do analysis. Is there any package work well for my purpose? I sometimes need to aggregate monthly data to quarterly data and I find aggregate function helpful. In the past I used packages xts, zoo and don't find it really user friendly. Maybe I haven't mastered it; maybe there're some updates (which I don't know) now. Could someone recommend a package or provide an example (or just the document, I can read it) for my purpose? Attached is an exemplary data set I talked about. Thanks, Miao __ 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] timeDate package: Read dates from xls or txt
Hi, timeDate package create a date vector like this: Dates - c(1989-09-28,2001-01-15,2004-08-30,1990-02-09) I have a date whose size is large. Could this package read the dates from xls or txt files? Could we convert the read vector (e.g., I usually use XLConnect to read xls files) to the date? Thanks, Miao [[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] Could someone recommend a package for time series?
Thanks Pascal! It certainly helps! 2014-09-29 17:10 GMT+08:00 Pascal Oettli kri...@ymail.com: Hi Miao, You certainly will find useful answers here : http://cran.r-project.org/web/views/TimeSeries.html Regards, Pascal Oettli On Mon, Sep 29, 2014 at 6:05 PM, jpm miao miao...@gmail.com wrote: Hi, I've not used R for about one year and don't know well about the updates on the time series-related package. My primary job is to do economic/financial time series data analysis - annual, monthly, daily, etc. I usually read data by the package XLConnect, which can read xls or xlsx files directly. It's excellent. However I can't find a package to manipulate time series data. For example, I just want to do an easy manipulation , e.g, to label the dates of the data from , say, 1991M10 to 2014M07, and then extract part of the data, say, 2005M01 to 2010M12 and do analysis. Is there any package work well for my purpose? I sometimes need to aggregate monthly data to quarterly data and I find aggregate function helpful. In the past I used packages xts, zoo and don't find it really user friendly. Maybe I haven't mastered it; maybe there're some updates (which I don't know) now. Could someone recommend a package or provide an example (or just the document, I can read it) for my purpose? Attached is an exemplary data set I talked about. Thanks, Miao __ 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. -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan [[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] timeDate package: Read dates from xls or txt
Thanks. Could timeDate object be transformed to/from zoo or xts? 2014-09-30 9:01 GMT+08:00 Jeff Newmiller jdnew...@dcn.davis.ca.us: If you read the documentation for that package you will find that the answer is no, for the simple reason that it doesn't do input or output. It does help you with conversions between POSIXt types, and can help figure out which days are holidays or weekends, but you need the date in character format to start. For reading in CSV data I use as.is=TRUE or stringsAsFactors=FALSE in my call to read.csv. For reading xls files I have had difficulties, which is why I prefer to export Excel data to CSV before reading it into R. One XLConnect bug workaround I have used is to convert the timestamp column into character using as.character with specified format and then back using as.POSIXct and a specified timezone, but it was borne of desperation and may not always be necessary or even sufficient. Please post using plain text rather than HTML format on this list. Only you can prevent your postings from being garbled. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On September 29, 2014 2:47:01 AM PDT, jpm miao miao...@gmail.com wrote: Hi, timeDate package create a date vector like this: Dates - c(1989-09-28,2001-01-15,2004-08-30,1990-02-09) I have a date whose size is large. Could this package read the dates from xls or txt files? Could we convert the read vector (e.g., I usually use XLConnect to read xls files) to the date? Thanks, Miao [[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. [[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] NAG (NAGFWrapper) or any optimization package recommended?
Hi, Is there any optimization package in R recommended for general purposes (constrained, unconstrained, etc)? Has anyone used the function in NAGFWrapper package http://www.nag.co.uk/numeric/R/r-package Are the optimization functions therein available for free? Thanks, Miao [[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] Find the prediction or the fitted values for an lm model
Hi, I would like to fit my data with a 4th order polynomial. Now I have only 5 data point, I should have a polynomial that exactly pass the five point Then I would like to compute the fitted or predict value with a relatively large x dataset. How can I do it? BTW, I thought the model prodfn should pass by (0,0), but I just wonder why the const is unequal to zero x1-c(0,3,4,5,8) y1-c(0,1,4,7,8) prodfn-lm(y1 ~ poly(x1, 4)) x-seq(0,8,0.01) temp-predict(prodfn,data.frame(x=x)) # This line does not work.. prodfn Call: lm(formula = y1 ~ poly(x1, 4)) Coefficients: (Intercept) poly(x1, 4)1 poly(x1, 4)2 poly(x1, 4)3 poly(x1, 4)4 4.000e+00 6.517e+00-4.918e-16-2.744e+00-8.882e-16 [[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] Find the cutoff correlation value for Pearson correlation test
Hi, I find a few Pearson correlation test functions like fBasics::correlationTest or stats::cor.test which give the p-value of the test result. Is there a function that calculate the cutoff correlation value for a specific p-value , e.g., p = 0.05? I have a plot for the cross correlations between two time series, and I would like to add a horizontal line that marks the significance of the correlations. Thanks, Miao [[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] Test for exogeneity
Hi, I am building a bivariate SVAR model y_1t=c_1+Ã_1 (1,1) y_(1,t-1)+Ã_1 (1,2) y_(2,t-1)+Ã_2 (1,1) y_(1,t-2)+Ã_2 (1,2) y_(2,t-2)+å_1t b y_1t+ y_2t=c_2+Ã_1 (2,1) y_(1,t-1)+Ã_1 (2,2) y_(2,t-1)+Ã_2 (2,1) y_(1,t-2)+Ã_2 (1,2) y_(2,t-2)+å_2t Now y1 is relatively exogenous in that y1 impacts y2 contemporaneously but not the other way around. Given a bivariate dataset, is there any statistical test (in any R package or elsewhere) that helps to justify/test the exogeneity of y1 in the present context? Is there any reference available? Thanks, Miao [[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] Lag selection in Unit Root Test
Hi, I attempt to conduct the unit root test with the two functions unitrootTest(x, lags = 1, type = c(nc, c, ct), title = NULL, description = NULL) adfTest(x, lags = 1, type = c(nc, c, ct), title = NULL, description = NULL) According to the document, lagsis the maximum number of lags used for error term correction. However, it seems that lags is the number of lags used, NOT the MAXIMUM number of lags used. For example, if I write lags =12, I expect a lag between 1 and 12, but it always gives lags =12. Could the function choose the lags from a range (say, 1-12) based on information criteria (AIC or BIC)? Thanks, Miao __ 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] Compiling a C++ file in RStudio?
Hi, I am wondering if C++ programs could be compiled in RStudio. I search on the web, and I find many yes's and no's. It looks like Rcpp can do it (or partially?). I just wonder if it can replace the C++ IDE, e.g., Eclipse or Visual Studio since RStudio is much easier to use. One says yes: http://learndataanalysis.com/you-can-now-source-c-file-rstudio Thanks, Miao [[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] Problem when running an SVAR-AB model in vars package
Is B a reserve word in vars package? I tried to run an SVAR-AB model by SVAR function and find the IRF in vars package. The problem is that when B matrix is named by B, an error message occurs. However, if the same matrix is named by Bm, then things run smoothly. What's wrong? Is B a reserve word in vars package? Amatexo [,1] [,2] [1,]10 [2,] NA1 Bm [,1] [,2] [1,] NA0 [2,]0 NA B-Bm B [,1] [,2] [1,] NA0 [2,]0 NA svar.Aexo-SVAR(var_dl, estmethod =direct, Amat=Amatexo, Bmat=Bm,hessian=TRUE) Warning message: In SVAR(var_dl, estmethod = direct, Amat = Amatexo, Bmat = Bm, : The AB-model is just identified. No test possible. irf.svaraexo-irf(svar.Aexo, boot=TRUE, n.ahead=12) There were 50 or more warnings (use warnings() to see the first 50) svar.Aexo-SVAR(var_dl, estmethod =direct, Amat=Amatexo, Bmat=B,hessian=TRUE) Warning message: In SVAR(var_dl, estmethod = direct, Amat = Amatexo, Bmat = B, : The AB-model is just identified. No test possible. irf.svaraexo-irf(svar.Aexo, boot=TRUE, n.ahead=12) Error in determinant.matrix(x, logarithm = TRUE, ...) : 'x' must be a square matrix In addition: Warning message: In optim(start, logLc, ...) : one-dimensional optimization by Nelder-Mead is unreliable: use Brent or optimize() directly [[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] Reserve word in could not be used it as a dimname?
Hi, I have a matrix whose columns are named as in and out. Then I coerce it to be a data.frame. However the system seems to forbid me from using the name in, but I am not aware of it until I call it by the dollar sign $. Is there something R should remind me but it does not? Is there any remedy to work on it? head(dat1$in) Error: unexpected 'in' in head(dat1$in View(dat1) head(dat1[in]) in 1 3.28 2 9.6 3 7.24 4 4.45 5 2.33 6 2.83 head(dat1[out]) out 10 20 3 0.04 4 0.03 5 0.04 6 0.01 head(dat1$out) [1] 000.04 0.03 0.04 0.01 [[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] Reserve word in could not be used it as a dimname?
Just wonder why R does not remind me so when I use it as a dimname... 2013/7/11 Pascal Oettli kri...@ymail.com Hello, in is a reserved word. ?Reserved Hope this clarifies, Pascal 2013/7/11 jpm miao miao...@gmail.com Hi, I have a matrix whose columns are named as in and out. Then I coerce it to be a data.frame. However the system seems to forbid me from using the name in, but I am not aware of it until I call it by the dollar sign $. Is there something R should remind me but it does not? Is there any remedy to work on it? head(dat1$in) Error: unexpected 'in' in head(dat1$in View(dat1) head(dat1[in]) in 1 3.28 2 9.6 3 7.24 4 4.45 5 2.33 6 2.83 head(dat1[out]) out 10 20 3 0.04 4 0.03 5 0.04 6 0.01 head(dat1$out) [1] 000.04 0.03 0.04 0.01 [[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. [[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] Problems with R package building
Hi, Following your advice, I install R tools from http://cran.r-project.org/bin/windows/Rtools/ Rtools215.exe http://cran.r-project.org/bin/windows/Rtools/Rtools215.exe Files are automatically installed here: C:\Rtools I run the code again and get the message Creating directories ... Error in package.skeleton(list = c(f, g, d, e), name = test1pkg, : directory 'D:/R/pkgtest/test1pkg' already exists R CMD build test1pkg Error: unexpected symbol in R CMD Is there anything else I need to do ? Miao 2013/6/14 Michael Weylandt michael.weyla...@gmail.com On Jun 14, 2013, at 7:18, jpm miao miao...@gmail.com wrote: Hi, I try to build a toy package by running the following codes in an R program require(stats) f - function(x,y) x+y g - function(x,y) x-y d - data.frame(a=1, b=2) e - rnorm(1000) package.skeleton(list=c(f,g,d,e), name=test1pkg, path=D:/R/pkgtest) Then the program runs smoothly Creating directories ... Creating DESCRIPTION ... Creating NAMESPACE ... Creating Read-and-delete-me ... Saving functions and data ... Making help files ... Done. Further steps are described in 'D:/R/pkgtest/test1pkg/Read-and-delete-me'. Since it is a test, I skip all the documentation work and then type this line: R CMD build test1pkg Error: unexpected symbol in R CMD I check on the web about the error message. It's said that the command should be typed in a DOS window (command prompt window?). However it does not work in my DOS window either. Could someone tell me how to process the package building process? Have you installed the Windows Rtools from CRAN and made sure your PATH is set properly? MW Thanks, Miao [[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. [[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] Problems with R package building
I ran it in a common window of R. It's said that I need to run it under DOS. I also open the command window of DOS C:\Documents and Settings\miao ,where miao is my username, and ran it, but it doesn't work either. An error message emerges. Miao 2013/6/20 Pascal Oettli kri...@ymail.com Hi, Did you run R CMD build test1pkg in a command prompt window? Regards, Pascal On 20/06/13 17:01, jpm miao wrote: Hi, Following your advice, I install R tools from http://cran.r-project.org/bin/**windows/Rtools/http://cran.r-project.org/bin/windows/Rtools/ Rtools215.exe http://cran.r-project.org/**bin/windows/Rtools/Rtools215.* *exe http://cran.r-project.org/bin/windows/Rtools/Rtools215.exe Files are automatically installed here: C:\Rtools I run the code again and get the message Creating directories ... Error in package.skeleton(list = c(f, g, d, e), name = test1pkg, : directory 'D:/R/pkgtest/test1pkg' already exists R CMD build test1pkg Error: unexpected symbol in R CMD Is there anything else I need to do ? Miao 2013/6/14 Michael Weylandt michael.weyla...@gmail.com On Jun 14, 2013, at 7:18, jpm miao miao...@gmail.com wrote: Hi, I try to build a toy package by running the following codes in an R program require(stats) f - function(x,y) x+y g - function(x,y) x-y d - data.frame(a=1, b=2) e - rnorm(1000) package.skeleton(list=c(f,**g,d,e), name=test1pkg, path=D:/R/pkgtest) Then the program runs smoothly Creating directories ... Creating DESCRIPTION ... Creating NAMESPACE ... Creating Read-and-delete-me ... Saving functions and data ... Making help files ... Done. Further steps are described in 'D:/R/pkgtest/test1pkg/Read-**and-delete-me'. Since it is a test, I skip all the documentation work and then type this line: R CMD build test1pkg Error: unexpected symbol in R CMD I check on the web about the error message. It's said that the command should be typed in a DOS window (command prompt window?). However it does not work in my DOS window either. Could someone tell me how to process the package building process? Have you installed the Windows Rtools from CRAN and made sure your PATH is set properly? MW Thanks, Miao [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Problems with R package building
Hi, What do you mean by Windows in a Windows console window? Is it the black screen of DOS? I change the directory of the DOS window to D:\R\pkgtest D:\R\pkgtest\test1pkg and run the command R CMD build test1pkg under each of the two paths, and the error message remains. Miao 2013/6/20 Berend Hasselman b...@xs4all.nl On 20-06-2013, at 10:01, jpm miao miao...@gmail.com wrote: Hi, Following your advice, I install R tools from http://cran.r-project.org/bin/windows/Rtools/ Rtools215.exe http://cran.r-project.org/bin/windows/Rtools/Rtools215.exe Files are automatically installed here: C:\Rtools I run the code again and get the message Creating directories ... Error in package.skeleton(list = c(f, g, d, e), name = test1pkg, : directory 'D:/R/pkgtest/test1pkg' already exists R CMD build test1pkg Error: unexpected symbol in R CMD You are supposed to run R CMD build test1pkg from the commandline in the directory directly above test1pkg On Windows in a Windows console window. Berend [[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] “arch.test” in “vars” package with multivariate.only = FALSE
arch.test in vars package with multivariate.only = FALSE The function arch.test(x, lags.single = 16, lags.multi = 5, multivariate.only = FALSE) produces the univariate and multivariate parts of the ARCH test By_t = C+A_1 y_{t-1}+ .. A_n y_{t-n}+\epsilon (homoskedastic VAR) And then u_t = B^{-1}\epsilon_t = y_t (B^{-1}C+B^{-1}A_1 y_{t-1}-..+ B^{-1} A_n y_{t-n}) u_k(t) is the k-th element of u_t u_k(t)= c+ \theta_1 u_k(t-1) + \theta_2 u_k(t-2)+.. \theta_q u_k(t-q)+\nu_k(t) Do the univariate parts of the ARCH test refer to the significance test of the last regression, H_0: \theta_i = 0 for all i against H_1: H_0 is false, for all k? Thanks, Miao [[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] Problems with R package building
Hi, I try to build a toy package by running the following codes in an R program require(stats) f - function(x,y) x+y g - function(x,y) x-y d - data.frame(a=1, b=2) e - rnorm(1000) package.skeleton(list=c(f,g,d,e), name=test1pkg, path=D:/R/pkgtest) Then the program runs smoothly Creating directories ... Creating DESCRIPTION ... Creating NAMESPACE ... Creating Read-and-delete-me ... Saving functions and data ... Making help files ... Done. Further steps are described in 'D:/R/pkgtest/test1pkg/Read-and-delete-me'. Since it is a test, I skip all the documentation work and then type this line: R CMD build test1pkg Error: unexpected symbol in R CMD I check on the web about the error message. It's said that the command should be typed in a DOS window (command prompt window?). However it does not work in my DOS window either. Could someone tell me how to process the package building process? Thanks, Miao [[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] Create a package with package.skeleton
Hi, I am trying to build a package with package.skeleton function. I already have the function quadprod2.R in the current folder. After running the program, library(frontier) source(quadprod2.R) package.skeleton(name=sfa_ext) package.skeleton(name=sfa_ext) Creating directories ... Creating DESCRIPTION ... Creating NAMESPACE ... Creating Read-and-delete-me ... Saving functions and data ... Making help files ... Done. Further steps are described in './sfa_ext/Read-and-delete-me'. Opening the Read-and-delete-me file by notepad, I find * Edit the help file skeletons in 'man', possibly combining help files for multiple functions. * Edit the exports in 'NAMESPACE', and add necessary imports. * Put any C/C++/Fortran code in 'src'. * If you have compiled code, add a useDynLib() directive to 'NAMESPACE'. * Run R CMD build to build the package tarball. * Run R CMD check to check the package tarball. Read Writing R Extensions for more information. Then it seems that I need to edit some documentation. Since I build the package primarily for myself, I spend as little time as possible editing the documentation. I almost do nothing on man and namespace. (Is that ok?) What should I do next? How can I run build and check commands? Thanks Miao [[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] How can we access an element in a structure
Hi, I have a structure, which is the result of a function How can I access the elements in the gradient? dput(test1) structure(-1.17782911684913, gradient = structure(c(-0.0571065371783791, -0.144708170683529), .Dim = 1:2, .Dimnames = list(NULL, c(x1, x2 test1[[1]] [1] -1.177829 test1 [1] -1.177829 attr(,gradient) x1 x2 [1,] -0.05710654 -0.1447082 test1[gradient] [1] NA Thanks, Miao [[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] convert a character string to a name
Hi, From time to time I need to do the aggregation. To illustrate, I present a toy example as below. In this example, the task is to aggregate x and y by z with the function mean. Could I call the aggregation function with x_test, where x_test=c(x,y)? Thanks Miao dftest-data.frame(x=1:12, y=(1:12)%%4, z=(1:12)%%2) dftest x y z 1 1 1 1 2 2 2 0 3 3 3 1 4 4 0 0 5 5 1 1 6 6 2 0 7 7 3 1 8 8 0 0 9 9 1 1 10 10 2 0 11 11 3 1 12 12 0 0 aggregate(cbind(x,y)~z, data=dftest, FUN=mean) z x y 1 0 7 1 2 1 6 2 x_test=c(x,y) aggregate(cbind(x_test)~z, data=dftest, FUN=mean) Error in model.frame.default(formula = cbind(x_test) ~ z, data = dftest) : variable lengths differ (found for 'z') a1aggregate(cbind(factor(x_test))~z, data=dftest, FUN=mean) Error in model.frame.default(formula = cbind(factor(x_test)) ~ z, data = dftest) : variable lengths differ (found for 'z') aggregate(factor(x_test)~z, data=dftest, FUN=mean) Error in model.frame.default(formula = factor(x_test) ~ z, data = dftest) : variable lengths differ (found for 'z') [[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] Could graph objects be stored in a two-dimensional list?
Hi, I have a few graph objects created by some graphic package (say, ggplot2, which I use frequently). Because of the existent relation between the graphs, I'd like to index them in two dimensions as p[1,1], p[1,2], p[2,1], p[2,2] for convenience. To my knowledge, the only data type capable of storing graph objects (and any R object) is list, but unfortunately it is available in only one dimension. Could the graphs be stored in any two-dimensional data type? One remedy that comes to my mind is to build a function f so that f(1,1)=1 f(1,2)=2 f(2,1)=3 f(2,2)=4 With functions f and f^{-1} (inverse function of f) , the two-dimensional indices could be mapped to and from a set of one-dimensional indices, and the functions are exactly the way R numbers elements in a matrix. Does R have this built-in function for a m by n matrix or more generally, m*n*p array? (I know this function is easy to write, but just want to make sure whether it exists already) Thanks, Miao [[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] Find the indices of non-NA elements of a sequence
Hi, I have a sequence whose 1st, 3rd, 4th, 6th are non-NAs. How could I let R return 1,3,4,6, the indices? I know only how to find the non-NA elements. Thanks, Miao test-c(2,NA,6,8,NA,12) test[is.na(test)==FALSE] [1] 2 6 8 12 [[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] How could I see the source code of functions in an R package?
Hi, How could I see the source code of functions in an R package? If we type ?function_name , we will see documentations of the function_name. If we type function_name, is what returns just the source code? Could we just save it in an .R file and modify as we want? However, it seems that sometimes the source code is hidden (or stored elsewhere?) As an example, could we see the source code of xyplot in the following example? Thanks, library(lattice) xyplot function (x, data, ...) UseMethod(xyplot) environment: namespace:lattice library(plm) Loading required package: bdsmatrix Attaching package: bdsmatrix The following object(s) are masked from package:base: backsolve Loading required package: nlme Loading required package: Formula Loading required package: MASS Loading required package: sandwich Loading required package: zoo Attaching package: zoo The following object(s) are masked from package:base: as.Date, as.Date.numeric ?plm plm function (formula, data, subset, na.action, effect = c(individual, time, twoways), model = c(within, random, ht, between, pooling, fd), random.method = c(swar, walhus, amemiya, nerlove, kinla), inst.method = c(bvk, baltagi), index = NULL, ...) { nframe - length(sys.calls()) is.a.list - class(formula)[1] == list if (is.a.list) { plmlist - match.call(expand.dots = FALSE) plmlist[[1]] - as.name(plm.list) plmlist - eval(plmlist, sys.frame(which = nframe)) return(plmlist) } dots - list(...) effect - match.arg(effect) if (!any(is.na(model))) model - match.arg(model) random.method - match.arg(random.method) inst.method - match.arg(inst.method) if (!is.na(model) model == ht) { ht - match.call(expand.dots = FALSE) m - match(c(formula, data, subset, na.action, index), names(ht), 0) ht - ht[c(1, m)] ht[[1]] - as.name(pht) ht - eval(ht, parent.frame()) return(ht) } if (!is.null(dots$instruments)) { as.Formula(formula, dots$instruments) deprec.instruments - paste(the use of the instruments argument is deprecated,, use two-part formulas instead) warning(deprec.instruments) } if (inherits(data, pdata.frame) !is.null(index)) warning(the index argument is ignored because data is a pdata.frame) if (!inherits(data, pdata.frame)) data - pdata.frame(data, index) if (!inherits(formula, pFormula)) formula - pFormula(formula) if (length(formula)[2] == 2) formula - expand.formula(formula) cl - match.call() mf - match.call(expand.dots = FALSE) m - match(c(formula, data, subset, na.action), names(mf), 0) mf - mf[c(1, m)] mf$drop.unused.levels - TRUE mf[[1]] - as.name(model.frame) mf$formula - formula mf$data - data data - eval(mf, parent.frame()) if (is.na(model)) { attr(data, formula) - formula return(data) } args - list(model = model, effect = effect, random.method = random.method, inst.method = inst.method) result - plm.fit(formula, data, model, effect, random.method, inst.method) result$call - cl result$args - args result } environment: namespace:plm [[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] How can I extract part of the data with a selection criterion?
Hi, As an example, how can I get the data such that field a of ab, ab[a], equals 3? I expect the answer to be the union of 2 and 4, as Thanks, a-c(1,3,4,3,5,6,5) b-c(2,4,6,7,3,1,2) ab-data.frame(a,b) ab a b 1 1 2 2 3 4 3 4 6 4 3 7 5 5 3 6 6 1 7 5 2 ab[a==3] Error in `[.data.frame`(ab, a == 3) : undefined columns selected ab[ab[a]==3] [1] 3 3 4 7 [[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] Calculates the mean/median from grouped data in R?
Let me revise the data as below. It is survey data. The respondent must answer the outlook of the oil price, say, in three months. Respondent A might answer that the price will be in the 80-90 interval, while B might answer 100-110. I think there should be a function that finds out the mean and the median of the data with the assumption that all data points inside each interval are evenly distributed. Are there such functions in R? 70-80480-90590-1008100-1107110-1203 2013/5/8 David Winsemius dwinsem...@comcast.net On May 7, 2013, at 8:40 PM, jpm miao wrote: Is there a function in R that calculate the mean and median for a grouped data? For example, a survey shows the oil price outlook in the future. How can I calculate the mean/median? (Of course, I understand that the groups below 80 and above 110 must be defined more specifically) below 80 4 80-90 5 90-100 8 100-110 7 above 110 3 Why would all groups need to be defined more specifically? How do we know whether items in the 80-90 range are evenly distributed? could be 80, 81, 82, 84, 85 or all 89's. David Winsemius Alameda, CA, USA [[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] How can I find negative items from a vector with a short command?
Thanks, but why does f[f=4] yield 16 instead of 4? f [1] -24 -8 16 -32 64 -128 f[f0] [1] -2 -8 -32 -128 f[f0] [1] 4 16 64 f[f=4] [1] 16 2013/5/8 Jorge I Velez jorgeivanve...@gmail.com f [ f 0 ] On Wed, May 8, 2013 at 11:54 AM, jpm miao miao...@gmail.com wrote: Hi, I have a vector f with some negative columns. I remember that there is an easy expression that can find out negative items. Can someone tell me how I can do it? It seems to be f[i such that f[i]0 ...] Thanks, Miao d-1:7 f-(-2)^d f [1] -24 -8 16 -32 64 -128 [[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. [[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] How can I find negative items from a vector with a short command?
Sorry. I just got it f[f==4] [1] 4 2013/5/8 jpm miao miao...@gmail.com Thanks, but why does f[f=4] yield 16 instead of 4? f [1] -24 -8 16 -32 64 -128 f[f0] [1] -2 -8 -32 -128 f[f0] [1] 4 16 64 f[f=4] [1] 16 2013/5/8 Jorge I Velez jorgeivanve...@gmail.com f [ f 0 ] On Wed, May 8, 2013 at 11:54 AM, jpm miao miao...@gmail.com wrote: Hi, I have a vector f with some negative columns. I remember that there is an easy expression that can find out negative items. Can someone tell me how I can do it? It seems to be f[i such that f[i]0 ...] Thanks, Miao d-1:7 f-(-2)^d f [1] -24 -8 16 -32 64 -128 [[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. [[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] Merge two dataframe with by, and problems with the common field
Hi, From time to time I merge two dataframes with possibly a common field. Then the common field is no longer present,but what are present fieldname.x and fieldname.y. How can I fix the problem so that I can still call by the orignal fieldname? If you don't understand my problem, please see the example below. Thanks Miao d1 a b c 1 1 4 5 2 2 5 6 3 3 6 7 d2 d a f b 1 6 1 8 4 2 7 2 9 5 3 8 3 10 6 d3-merge(d1, d2, by=b) d3 b a.x c d a.y f 1 4 1 5 6 1 8 2 5 2 6 7 2 9 3 6 3 7 8 3 10 d3[a] Error in `[.data.frame`(d3, a) : undefined columns selected d3[a.x] a.x 1 1 2 2 3 3 [[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] How can I find negative items from a vector with a short command?
Hi, I have a vector f with some negative columns. I remember that there is an easy expression that can find out negative items. Can someone tell me how I can do it? It seems to be f[i such that f[i]0 ...] Thanks, Miao d-1:7 f-(-2)^d f [1] -24 -8 16 -32 64 -128 [[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] Calculates the mean/median from grouped data in R?
Is there a function in R that calculate the mean and median for a grouped data? For example, a survey shows the oil price outlook in the future. How can I calculate the mean/median? (Of course, I understand that the groups below 80 and above 110 must be defined more specifically) below 80 4 80-90 5 90-100 8 100-110 7 above 110 3 [[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] How can I access the rowname of a data?
Hi, Below is the output from an R package. The first column (4, 5, 6, 7, which is unnamed) is the company name (code), while the second column efficiency is the performance of each company, which is the primary output result. How can I access the first column, rowname, 4, 5, 6, 7, 8, 9, 11? How can I build a dataframe consisting of two columns, the company name (code) and the efficiency? as.data.frame(a) produce only a column with company names, where company names are not accessible. Thanks, Miao a efficiency 4 0.26902196 5 0.30967213 6 0.33841116 7 0.36174368 8 0.36415004 9 0.37977151 11 0.42136627 12 0.40270465 13 0.49386586 15 0.12549416 16 0.17616129 17 0.45815803 18 0.09380655 21 0.97223375 40 0.43234228 48 0.25185516 50 0.28382549 52 0.44653074 53 0.27899931 54 0.42288119 81 0.49108330 101 0.20489971 102 0.24817017 103 0.36290391 108 0.23457172 118 0.25237865 147 0.25926483 803 0.45134936 805 0.36135729 806 0.28311573 807 0.32053914 808 0.35295777 809 0.17983115 810 0.30132804 812 0.48614262 814 0.30770005 815 0.29402445 816 0.35863589 822 0.50282266 825 0.46845802 dput(a) structure(c(0.269021958172058, 0.30967212679043, 0.338411157000573, 0.361743675159821, 0.364150044117951, 0.37977150519361, 0.421366274731659, 0.402704652137264, 0.49386585901599, 0.125494157670888, 0.176161288740361, 0.458158033521881, 0.0938065485975032, 0.972233754473899, 0.432342283512805, 0.251855164210068, 0.283825485987841, 0.446530739128589, 0.278999313704237, 0.422881194129863, 0.491083297407732, 0.20489970948236, 0.248170174737282, 0.362903909816553, 0.234571723781862, 0.252378650048782, 0.259264826952972, 0.451349355848852, 0.361357286628178, 0.283115732632982, 0.32053914247248, 0.352957770657268, 0.179831147819322, 0.30132803776434, 0.486142623827358, 0.307700045108983, 0.29402444509927, 0.358635886286322, 0.502822662489642, 0.468458021786023), .Dim = c(40L, 1L), .Dimnames = list(c(4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 16, 17, 18, 21, 40, 48, 50, 52, 53, 54, 81, 101, 102, 103, 108, 118, 147, 803, 805, 806, 807, 808, 809, 810, 812, 814, 815, 816, 822, 825 ), efficiency)) a1-as.data.frame(a) View(`a1`) a1$name NULL a1$names NULL a1$row.names NULL a1$efficiency [1] 0.26902196 0.30967213 0.33841116 0.36174368 [5] 0.36415004 0.37977151 0.42136627 0.40270465 [9] 0.49386586 0.12549416 0.17616129 0.45815803 [13] 0.09380655 0.97223375 0.43234228 0.25185516 [17] 0.28382549 0.44653074 0.27899931 0.42288119 [21] 0.49108330 0.20489971 0.24817017 0.36290391 [25] 0.23457172 0.25237865 0.25926483 0.45134936 [29] 0.36135729 0.28311573 0.32053914 0.35295777 [33] 0.17983115 0.30132804 0.48614262 0.30770005 [37] 0.29402445 0.35863589 0.50282266 0.46845802 a1 efficiency 4 0.26902196 5 0.30967213 6 0.33841116 7 0.36174368 8 0.36415004 9 0.37977151 11 0.42136627 12 0.40270465 13 0.49386586 15 0.12549416 16 0.17616129 17 0.45815803 18 0.09380655 21 0.97223375 40 0.43234228 48 0.25185516 50 0.28382549 52 0.44653074 53 0.27899931 54 0.42288119 81 0.49108330 101 0.20489971 102 0.24817017 103 0.36290391 108 0.23457172 118 0.25237865 147 0.25926483 803 0.45134936 805 0.36135729 806 0.28311573 807 0.32053914 808 0.35295777 809 0.17983115 810 0.30132804 812 0.48614262 814 0.30770005 815 0.29402445 816 0.35863589 822 0.50282266 825 0.46845802 View(`a1`) a1[1,] [1] 0.269022 a1[2,] [1] 0.3096721 [[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] Problems with reading data by readWorksheetFromFile of XLConnect Package
Hi Anthony, Thank you very much. It works very well. However, after this line temp - sapply( temp , as.numeric ) the data becomes a series of numbers instead of a matrix. Is there any way to keep it a matrix? Thanks, Miao temp-readWorksheetFromFile(130502temp.xlsx, sheet=1, header=FALSE, startRow=2, endRow= 11, startCol=2, endCol=5) temp - sapply( temp , function( x ) gsub( ',' , '' , x ) ) temp Col1 Col2 Col3Col4 [1,] 647853 1413 57662 27897 [2,] 491400 1365 40919 20411 [3,] 38604 -5505 985 [4,] 576-2054 [5,] 80845 21 10211 4494 [6,] 36428 27 1007 1953 [7,] 269915 587 32988 12779 [8,] 224494 -30554 9184 [9,] 11858 587 - 686 [10,] 3742 -81415 temp - sapply( temp , as.numeric ) Warning messages: 1: In lapply(X = X, FUN = FUN, ...) : NAs introduced by coercion 2: In lapply(X = X, FUN = FUN, ...) : NAs introduced by coercion 3: In lapply(X = X, FUN = FUN, ...) : NAs introduced by coercion 4: In lapply(X = X, FUN = FUN, ...) : NAs introduced by coercion 5: In lapply(X = X, FUN = FUN, ...) : NAs introduced by coercion temp 647853 491400 38604576 80845 36428 269915 647853 491400 38604576 80845 36428 269915 224494 11858 3742 1413 1365 - - 224494 11858 3742 1413 1365 NA NA 21 27587 -587 - 57662 21 27587 NA587 NA 57662 40919 5505 20 10211 1007 32988 30554 40919 5505 20 10211 1007 32988 30554 - 81 27897 20411985 54 4494 NA 81 27897 20411985 54 4494 1953 12779 9184686415 1953 12779 9184686415 temp[ is.na( temp ) ] - 0 temp 647853 491400 38604576 80845 36428 269915 647853 491400 38604576 80845 36428 269915 224494 11858 3742 1413 1365 - - 224494 11858 3742 1413 1365 0 0 21 27587 -587 - 57662 21 27587 0587 0 57662 40919 5505 20 10211 1007 32988 30554 40919 5505 20 10211 1007 32988 30554 - 81 27897 20411985 54 4494 0 81 27897 20411985 54 4494 1953 12779 9184686415 1953 12779 9184686415 2013/5/2 Anthony Damico ajdam...@gmail.com try adding colTypes = 'numeric' to your readWorkSheetFromFile() call if that doesn't work, try a few other steps # view what data types your file is being read in as sapply( temp , class ) # convert all fields to character if they're factor variables.. but i don't think you need this, readWorksheet defaults to `character` temp - sapply( temp , as.character ) # you can also convert a subset like this temp[ , c( 1 , 3:4 ) ] - sapply( temp[ , c( 1 , 3:4 ) ] , as.character ) # remove commas from character strings temp - sapply( temp , function( x ) gsub( ',' , '' , x ) ) # convert all fields to numeric temp - sapply( temp , as.numeric ) # convert all NA fields to zeroes if you prefer temp[ is.na( temp ) ] - 0 On Wed, May 1, 2013 at 11:55 PM, jpm miao miao...@gmail.com wrote: Hi, Attached are two datasheet to be read. My raw data 130502temp.xlsx contains numbers with ' symbols, and they can't be read as numbers. Even if I copy and paste as numbers to form a new file 130502temp_number1.xlsx, they could not be read smoothly. 1. How can I read the datasheet as numbers? 2. How can I treat the notation - as (1) NA or (2) zero? Thanks, Miao temp-readWorksheetFromFile(130502temp.xlsx, sheet=1, header=FALSE, startRow=2, endRow= 11, startCol=2, endCol=5) temp Col1 Col2 Col3 Col4 1 647,853 1,413 57,662 27,897 2 491,400 1,365 40,919 20,411 3 38,604 - 5,505985 4 576 - 20 54 5 80,84521 10,211 4,494 6 36,42827 1,007 1,953 7 269,915 587 32,988 12,779 8 224,494 - 30,554 9,184 9 11,858 587 -686 10 3,742 - 81415 temp[2,2] [1] 1,365 temp[2,2]+3 Error in temp[2, 2] + 3 : non-numeric argument to binary operator temp_num-readWorksheetFromFile(130502temp_number1.xlsx, sheet=1, header=FALSE, startRow=2, endRow= 11, startCol=2, endCol=5) temp_num[2,2] [1] 1,365 temp_num[2,2]+3 Error in temp_num[2, 2] + 3 : non-numeric argument to binary operator as.numeric(temp_num[2,2])+3 [1] NA Warning message: NAs introduced by coercion __ 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. [[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
[R] Declare a set (list?) of many dataframes or matrices
Hi, I would like to read several datasets and would like to create a set (list? sequence?) of many empty dataframes. How could this be done? How could I declare a set (list? sequence?) of many empty matrices? Thanks, Miao [[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] Why can't R understand if(num!=NA)?
I have a program, when I write if(num!=NA) it yields an error message. However, if I write if(is.na(num)==FALSE) it works. Why doesn't the first statement work? Thanks, Miao [[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] Stochastic Frontier: Finding the optimal scale/scale efficiency by frontier package
Dear Arne, Thank you very much for your response. I will certainly read it carefully and if I have further questions (after our discussion on this problem), I will go to R forge. I am relatively new in SFA and productivity analysis. Regarding your question on the presence of any software imposing concavity condition, please read the book Coelli et al 2005, p227-230 (page number of the book instead of the pdf file). According to the book, the software Shazam can do the estimation with concavity constraint. The book is here: http://facweb.knowlton.ohio-state.edu/pviton/courses/crp4700/coelli_Intro_effic.pdf According to my friend working on panel data, the case where efficiency 1 is seldom/never encountered, but the book says the opposite. Thanks, Miao 2013/4/25 Arne Henningsen arne.henning...@gmail.com Dear Miao On 25 April 2013 03:26, jpm miao miao...@gmail.com wrote: I am trying to find out the scale efficiency and optimal scale of banks by stochastic frontier analysis given the panel data of bank. I am free to choose any model of stochastic frontier analysis. The only approach I know to work with R is to estimate a translog production function by sfa or other related function in frontier package, and then use the Ray 1998 formula to find the scale efficiency. However, as the textbook Coelli et al 2005 point out that the concavity may not be satisfied, one needs to impose the nonpositive definiteness condition so that the scale efficiency 1. It might be that the true technology is not concave and that the elasticity of scale is larger than one. Indeed, most empirical studies find increasing returns to scale (in many different sectors). Therefore, it is probably inappropriate to impose concavity. How can I do it with frontier package? The frontier package cannot impose concavity on a Translog production function and I am not aware of any software that can do this in a stochastic frontier estimation -- probably, because imposing concavity usually does not make sense. Is there any other SFA model/function in R recommended to find out the scale efficiency and optimal scale? I suggest to plot the elasticity of scale against the firm size. If the elasticity of scale decreases with firm size, then the most productive firm size is at the firm size, where the elasticity of scale is one. However, there are some problems with using the Translog production function (and the Translog distance function) for determining the optimal firm size [1]. [1] http://econpapers.repec.org/RePEc:foi:wpaper:2012_12 If you have further questions regarding the frontier package, I suggest that you use the help forum at frontier's R-Forge site [2]. [2] https://r-forge.r-project.org/projects/frontier/ ... and please do not forget to cite the R packages that you use in your analysis in your publications. Thanks! Best wishes, Arne -- Arne Henningsen http://www.arne-henningsen.name [[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] Problems with reading data by readWorksheetFromFile of XLConnect Package
Hi, Attached are two datasheet to be read. My raw data 130502temp.xlsx contains numbers with ' symbols, and they can't be read as numbers. Even if I copy and paste as numbers to form a new file 130502temp_number1.xlsx, they could not be read smoothly. 1. How can I read the datasheet as numbers? 2. How can I treat the notation - as (1) NA or (2) zero? Thanks, Miao temp-readWorksheetFromFile(130502temp.xlsx, sheet=1, header=FALSE, startRow=2, endRow= 11, startCol=2, endCol=5) temp Col1 Col2 Col3 Col4 1 647,853 1,413 57,662 27,897 2 491,400 1,365 40,919 20,411 3 38,604 - 5,505985 4 576 - 20 54 5 80,84521 10,211 4,494 6 36,42827 1,007 1,953 7 269,915 587 32,988 12,779 8 224,494 - 30,554 9,184 9 11,858 587 -686 10 3,742 - 81415 temp[2,2] [1] 1,365 temp[2,2]+3 Error in temp[2, 2] + 3 : non-numeric argument to binary operator temp_num-readWorksheetFromFile(130502temp_number1.xlsx, sheet=1, header=FALSE, startRow=2, endRow= 11, startCol=2, endCol=5) temp_num[2,2] [1] 1,365 temp_num[2,2]+3 Error in temp_num[2, 2] + 3 : non-numeric argument to binary operator as.numeric(temp_num[2,2])+3 [1] NA Warning message: NAs introduced by coercion __ 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] Extrafont package: Fonts are not successfully installed
Hi, I am using Extrafont package to install more fonts for my graphs. My primary graphic tool is ggplot2. I seem to have problem installing the package, but could not pinpoint where it is. I try to follow the instruction here: https://github.com/wch/extrafont I guess (but am not sure) the fonts are successfully installed. Problem encountered: 1. The following line sometimes yields an error. Sometimes it works. pdf(font_plot.pdf, family=Times New Roman, width=4, height=4) 2. The compiler could not find the fonts installed, e.g., Georgia, Impact, Times New Romans, Arial Black. Error message: Font family not found in Windows font database. 3. The plot could not show up at all. I use RStudio. I need to close RStudio and reopen it in order to see the plots produced by ggplot2 . Could someone provide an example of how Extrafont package is used? Thanks, Miao rm(list=ls()) library(ggplot2) library(extrafont) font_import() Importing fonts may take a few minutes, depending on the number of fonts and the speed of the system. Continue? [y/n] y Scanning ttf files in C:\WINDOWS\Fonts ... Extracting .afm files from .ttf files... C:\WINDOWS\Fonts\arial.ttf : ArialMT already registered in fonts database. Skipping. C:\WINDOWS\Fonts\arialbd.ttf : Arial-BoldMT already registered in fonts database. Skipping. C:\WINDOWS\Fonts\arialbi.ttf : Arial-BoldItalicMT already registered in fonts database. Skipping. C:\WINDOWS\Fonts\ariali.ttf : Arial-ItalicMT already registered in fonts database. Skipping. C:\WINDOWS\Fonts\ariblk.ttf : Arial-Black already registered in fonts database. Skipping. C:\WINDOWS\Fonts\Braille.ttf : Braille already registered in fonts database. Skipping. C:\WINDOWS\Fonts\comic.ttf : ComicSansMS already registered in fonts database. Skipping. C:\WINDOWS\Fonts\comicbd.ttf : ComicSansMS-Bold already registered in fonts database. Skipping. C:\WINDOWS\Fonts\cour.ttf : CourierNewPSMT already registered in fonts database. Skipping. C:\WINDOWS\Fonts\courbd.ttf : CourierNewPS-BoldMT already registered in fonts database. Skipping. C:\WINDOWS\Fonts\courbi.ttf : CourierNewPS-BoldItalicMT already registered in fonts database. Skipping. C:\WINDOWS\Fonts\couri.ttf : CourierNewPS-ItalicMT already registered in fonts database. Skipping. C:\WINDOWS\Fonts\cwfs.ttf : cwTeXFangSong already registered in fonts database. Skipping. C:\WINDOWS\Fonts\cwheib.ttf : cwTeXHeiBold already registered in fonts database. Skipping. C:\WINDOWS\Fonts\cwkai.ttf : cwTeXKai already registered in fonts database. Skipping. C:\WINDOWS\Fonts\cwming.ttf : cwTeXMing already registered in fonts database. Skipping. C:\WINDOWS\Fonts\cwyen.ttf : cwTeXYen already registered in fonts database. Skipping. C:\WINDOWS\Fonts\Dr.eye phonetic symbol.ttf : Dr-eye-phonetic-symbol already registered in fonts database. Skipping. C:\WINDOWS\Fonts\estre.ttf : EstrangeloEdessa already registered in fonts database. Skipping. C:\WINDOWS\Fonts\framd.ttf : FranklinGothic-Medium already registered in fonts database. Skipping. C:\WINDOWS\Fonts\framdit.ttf : FranklinGothic-MediumItalic already registered in fonts database. Skipping. C:\WINDOWS\Fonts\gautami.ttf : Gautami already registered in fonts database. Skipping. C:\WINDOWS\Fonts\georgia.ttf : Georgia already registered in fonts database. Skipping. C:\WINDOWS\Fonts\georgiab.ttf : Georgia-Bold already registered in fonts database. Skipping. C:\WINDOWS\Fonts\georgiai.ttf : Georgia-Italic already registered in fonts database. Skipping. C:\WINDOWS\Fonts\georgiaz.ttf : Georgia-BoldItalic already registered in fonts database. Skipping. C:\WINDOWS\Fonts\impact.ttf : Impact already registered in fonts database. Skipping. C:\WINDOWS\Fonts\kaiu.ttf : DFKaiShu-SB-Estd-BF already registered in fonts database. Skipping. C:\WINDOWS\Fonts\kartika.ttf : Kartika already registered in fonts database. Skipping. C:\WINDOWS\Fonts\l_10646.ttf : LucidaSansUnicode already registered in fonts database. Skipping. C:\WINDOWS\Fonts\latha.ttf : Latha already registered in fonts database. Skipping. C:\WINDOWS\Fonts\lingoes.ttf : LingoesUnicode already registered in fonts database. Skipping. C:\WINDOWS\Fonts\liquidcr.ttf : LiquidCrystal already registered in fonts database. Skipping. C:\WINDOWS\Fonts\lucon.ttf : LucidaConsole already registered in fonts database. Skipping. C:\WINDOWS\Fonts\mangal.ttf : Mangal-Regular already registered in fonts database. Skipping. C:\WINDOWS\Fonts\marlett.ttf : Marlett already registered in fonts database. Skipping. C:\WINDOWS\Fonts\micross.ttf : MicrosoftSansSerif already registered in fonts database. Skipping. C:\WINDOWS\Fonts\mvboli.ttf : MVBoli already registered in fonts database. Skipping. C:\WINDOWS\Fonts\pala.ttf : PalatinoLinotype-Roman already registered in fonts database. Skipping. C:\WINDOWS\Fonts\palab.ttf : PalatinoLinotype-Bold already registered in fonts database. Skipping. C:\WINDOWS\Fonts\palabi.ttf : PalatinoLinotype-BoldItalic already registered in fonts database. Skipping.
[R] Is there a function that print a string vertically (by adding \n)?
Hi, I'd like to print a string vertically. For example, I would like to print abcd as a\nb\nc\nd Is there a function in R such that Input: abcd Output: a\nb\nc\nd? Thanks, Miao [[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] Stochastic Frontier: Finding the optimal scale/scale efficiency by frontier package
Hi, I am trying to find out the scale efficiency and optimal scale of banks by stochastic frontier analysis given the panel data of bank. I am free to choose any model of stochastic frontier analysis. The only approach I know to work with R is to estimate a translog production function by sfa or other related function in frontier package, and then use the Ray 1998 formula to find the scale efficiency. However, as the textbook Coelli et al 2005 point out that the concavity may not be satisfied, one needs to impose the nonpositive definiteness condition so that the scale efficiency 1. How can I do it with frontier package? Is there any other SFA model/function in R recommended to find out the scale efficiency and optimal scale? Thanks, Miao [[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] Questions on function readNamedRegionFromFile in XLConnect pacakge
Hi, I have two questions on the function readNamedRegionFromFile in XLConnect pacakge. 1. In the documentation, # multiregion xlsx file from demoFiles subfolder of package XLConnect demoExcelFile - system.file(demoFiles/multiregion.xlsx, package = XLConnect) # Load a single named region into a single data.frame. df - readNamedRegionFromFile(demoExcelFile, name=Iris) # Load multiple regions at once - returns a (named) list # of data.frames. df - readNamedRegionFromFile(demoExcelFile, name=c(Calendar, Iris, IQ)) What are the names Calendar, Iris, IQ? I just couldn't find them from the file. 2. Since my xlsx file is big, I might want to read data like AK9:AK18, for example. If my computation is right, AK is the 37th column. Then I need to tell the computer to read the 37th column, row 9 to row 18. Can I ask the function (any function in the package) to read the column by the header name (say, the name saved in AK1) instead of 37th? Thanks, Miao [[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] How can I ask R to skip the title when reading the data?
I have many xls grade report sheets with the same format XXX High School Grade Report Confidential Yes Math English Science John 90 85 90 Mary 75 88 93 Since the reports are prepared on a regular basis, I have many reports with identical format. Without the title XXX High School Grade Report Confidential Yes, I can just change the xls to csv and read them via read.csv. How can I read the data in the presence of the title? How can I ask R to skip the title and just read the data? Thanks, Miao [[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] Transformation of a variable in a dataframe
HI, I have a dataframe with two variable A, B. I transform the two variable and name them as C, D and save it in a dataframe dfcd. However, I wonder why can't I call them by dfcd$C and dfcd$D? Thanks, Miao A=c(1,2,3) B=c(4,6,7) dfab-data.frame(A,B) C=dfab[A]*2 D=dfab[B]*3 dfcd-data.frame(C,D) dfcd A B 1 2 12 2 4 18 3 6 21 dfcd$C NULL dfcd$A [1] 2 4 6 [[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] Is it possible to create Dual y axes with ggplot2 package?
Hi, Is it possible to create Dual y axes with ggplot2 package? If so, is there any sample codes that reaches (or partially) this goal? The author of the package, Dr Hadley Wickham, seem to discourage the dual axes, but some remedies were provided by other users (If I am wrong, please correct me). I have done some homework: This is the discussion which I find most helpful. https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/tImExPZg61o This is a nice graph with dual axes http://blog.revolutionanalytics.com/2010/01/r-package-growth.html Codes are provided here http://onertipaday.blogspot.tw/2010/01/scatter-plot-with-4-axes-labels-and.html Is it possible to modify the code so that it produces ggplot2 style dual-axis graph? Thanks, Miao [[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] Plot two separate curves in R Graphics and R Lattice package
Hi David, Many thanks. I try to follow your example and code as follows: xyplot( avg_cost_2012 ~ asset_2012, panel=function(x,y) { panel.xyplot(x,y, type=p) panel.lines(x2, y1, col=red)},scales=list(x=list(log=10))) However, I do see the points p of avg_cost_2012 ~ asset_2012, but do not see the line for y1 against x2. y1 and x1 are numeric vectors of the same size. How can I fix it? Thnaks Miao 2013/4/10 David Winsemius dwinsem...@comcast.net On Apr 9, 2013, at 8:21 PM, jpm miao wrote: Thank you very much. Could it be done in Lattice package? Your example was not presented in a form that lent itself to easy editing. Please learn to use dput to present data structures: xyplot( 4:6 ~ 1:3, panel=function(x,y) { panel.xyplot(x,y, type=l) panel.points(x=c(1.1, 2.1), y=c(4.1, 5.1), col=red) } ) -- David. Thanks, Miao 2013/4/10 Janesh Devkota janesh.devk...@gmail.com Hi, This should be fairly easy by using base R graphics. Lets suppose your first data is represented by (x1,y1) and second data is represented by (x2,y2) You can use the following command. plot(x1,y1,type=l) points(x2,y2) Hope it helps. On Tue, Apr 9, 2013 at 8:24 PM, jpm miao miao...@gmail.com wrote: Hi, How can I plot two curves with distinct x and y vectors? I would like to join one of them by regular lines and plot the other just by points (no lines). Can it be done in regular R graphic tools, say plot function? Can it be done in Lattice package, say xyplot function? Thanks, Miao My data look like this: two curves with different vector size x y 3973730 0.00322 2391576 0.003487 2840944 0.005145 2040943 0.006359 1982715 0.006253 1618162 0.00544 820082.3 0.004213 1658597 0.004883 1762794 0.006216 93439.5 0.004255 218481.3 0.006924 2332477 0.004862 725835.5 0.00089 811575.3 0.012962 292223 0.002614 153862.3 0.007524 1272367 0.006899 734199 0.00988 421404.5 0.005048 189047.5 0.004821 529102 0.009637 56833 0.006171 125856.3 0.00839 598893.8 0.006622 258240 0.00613 159086.3 0.008819 122863 0.010093 404699.5 0.008148 453514.5 0.008407 545028 0.006096 1233366 0.006111 1192758 0.008162 147563.3 0.00838 247293 0.010283 1074838 0.007413 459227.5 0.00862 202332 0.009061 377401.3 0.006923 1876753 0.010226 and x y 50118.72 0.012117 51286.14 0.012054 52480.75 0.011991 53703.18 0.011928 54954.09 0.011865 56234.13 0.011803 57543.99 0.011742 58884.37 0.01168 60255.96 0.011619 61659.5 0.011559 63095.73 0.011498 64565.42 0.011438 66069.34 0.011379 67608.3 0.011319 69183.1 0.01126 [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA [[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] Plot two separate curves in R Graphics and R Lattice package
, 426579.518801593, 436515.832240167, 446683.592150963, 457088.189614875, 467735.141287198, 478630.092322638, 489778.819368447, 501187.233627272, 512861.383991365, 524807.460249773, 537031.796370253, 549540.873857625, 562341.325190349, 575439.937337157, 588843.65535559, 602559.586074358, 616595.001861482, 630957.344480194, 645654.229034656, 660693.448007596, 676082.975391982, 691830.970918936, 707945.784384139, 724435.960074991, 741310.241300918, 758577.575029184, 776247.116628693, 794328.234724282, 812830.5161641, 831763.771102671, 851138.038202376, 870963.589956081, 891250.938133746, 912010.83935591, 933254.300796992, 954992.586021437, 977237.220955811, 1e+06, 1023292.99228075, 1047128.5480509, 1071519.30523761, 1096478.19614319, 1122018.45430197, 1148153.62149688, 1174897.55493953, 1202264.43461741, 1230268.77081238, 1258925.41179417, 1288249.55169313, 1318256.73855641, 1348962.88259165, 1380384.26460289, 1412537.54462276, 1445439.77074593, 1479108.38816821, 1513561.24843621, 1548816.61891248, 1584893.19246111, 1621810.09735893, 1659586.90743756, 1698243.65246175, 1737800.82874938, 1778279.41003892, 1819700.85860998, 1862087.13666287, 1905460.71796325, 1949844.59975805, 1995262.31496888, 2041737.94466953, 2089296.13085404, 2137962.08950223, 2187761.62394955, 2238721.13856834, 2290867.65276777, 2344228.81531992, 2398832.91901949, 2454708.91568503, 2511886.43150958, 2570395.78276886, 2630267.99189538, 2691534.80392691, 2754228.70333817, 2818382.93126445, 2884031.50312661, 2951209.2239, 3019951.72040202, 3090295.43251359, 3162277.66016838, 3235936.56929628, 3311311.21482591, 3388441.56139203, 3467368.50452532, 3548133.89233576, 3630780.54770102, 3715352.29097173, 3801893.96320561, 3890451.4499428, 3981071.70553498, 4073802.77804113, 4168693.83470336, 4265795.18801593, 4365158.32240167, 4466835.92150963, 4570881.89614875, 4677351.41287198, 4786300.92322638, 4897788.19368447, 5011872.33627272), .Dim = c(201L, 2L), .Dimnames = list(NULL, c(y1, x2))) 2013/4/11 David Winsemius dwinsem...@comcast.net On Apr 10, 2013, at 12:44 AM, jpm miao wrote: Hi David, Many thanks. I try to follow your example and code as follows: xyplot( avg_cost_2012 ~ asset_2012, panel=function(x,y) { panel.xyplot(x,y, type=p) panel.lines(x2, y1, col=red)},scales=list(x=**list(log=10))) However, I do see the points p of avg_cost_2012 ~ asset_2012, but do not see the line for y1 against x2. y1 and x1 are numeric vectors of the same size. How can I fix it? Without seeing the data it is difficult to enumerate the possible errors you could be making. I say again: Your example was not presented in a form that lent itself to easy editing. Please learn to use dput to present data structures. -- David Thnaks Miao 2013/4/10 David Winsemius dwinsem...@comcast.net On Apr 9, 2013, at 8:21 PM, jpm miao wrote: Thank you very much. Could it be done in Lattice package? Your example was not presented in a form that lent itself to easy editing. Please learn to use dput to present data structures: xyplot( 4:6 ~ 1:3, panel=function(x,y) { panel.xyplot(x,y, type=l) panel.points(x=c(1.1, 2.1), y=c(4.1, 5.1), col=red) } ) -- David. Thanks, Miao 2013/4/10 Janesh Devkota janesh.devk...@gmail.com Hi, This should be fairly easy by using base R graphics. Lets suppose your first data is represented by (x1,y1) and second data is represented by (x2,y2) You can use the following command. plot(x1,y1,type=l) points(x2,y2) Hope it helps. On Tue, Apr 9, 2013 at 8:24 PM, jpm miao miao...@gmail.com wrote: Hi, How can I plot two curves with distinct x and y vectors? I would like to join one of them by regular lines and plot the other just by points (no lines). Can it be done in regular R graphic tools, say plot function? Can it be done in Lattice package, say xyplot function? Thanks, Miao My data look like this: two curves with different vector size x y 3973730 0.00322 2391576 0.003487 2840944 0.005145 2040943 0.006359 1982715 0.006253 1618162 0.00544 820082.3 0.004213 1658597 0.004883 1762794 0.006216 93439.5 0.004255 218481.3 0.006924 2332477 0.004862 725835.5 0.00089 811575.3 0.012962 292223 0.002614 153862.3 0.007524 1272367 0.006899 734199 0.00988 421404.5 0.005048 189047.5 0.004821 529102 0.009637 56833 0.006171 125856.3 0.00839 598893.8 0.006622 258240 0.00613 159086.3 0.008819 122863 0.010093 404699.5 0.008148 453514.5 0.008407 545028 0.006096 1233366 0.006111 1192758 0.008162 147563.3 0.00838 247293 0.010283 1074838 0.007413 459227.5 0.00862 202332 0.009061 377401.3 0.006923 1876753 0.010226 and x y 50118.72 0.012117 51286.14 0.012054 52480.75 0.011991 53703.18 0.011928 54954.09 0.011865 56234.13 0.011803 57543.99 0.011742 58884.37 0.01168 60255.96 0.011619 61659.5 0.011559 63095.73 0.011498 64565.42 0.011438 66069.34 0.011379
Re: [R] Plot two separate curves in R Graphics and R Lattice package
Hi David, Thanks. How can I make the graph in log scale? Thanks Miao 2013/4/11 David Winsemius dwinsem...@comcast.net On Apr 10, 2013, at 6:11 PM, jpm miao wrote: Thanks for your comments, David avg_cost_2012 and asset_2012 are numeric vectors of length 39 while x2 and y1 are longer vectors whose range is about the same as (avg_cost_2012, asset_2012) I also present the data by dput below. Is it clear? Thanks, I've named the first object xy and the second object y1x2 xyplot( avg_cost_2012 ~ asset_2012, data=as.data.frame(xy), panel=function(x,y) { panel.xyplot(x,y, type=p) panel.points( x=y1x2[,'x2'], y= y1x2[,'y1'], col=red)} ) Throwing in the scales argument does make the points from panel.points disappear. Miao asset_2012 avg_cost_2012 1 3973730.0 0.0032199310 2 2391575.8 0.0034866607 3 2840943.5 0.0051450067 4 2040943.0 0.0063589398 5 1982715.2 0.0062530448 6 1618162.2 0.0054400342 7 820082.2 0.0042134623 8 1658596.8 0.0048834145 9 1762794.0 0.0062155737 10 93439.5 0.0042552036 11 218481.2 0.0069238420 12 2332477.0 0.0048621108 13 725835.5 0.0008902909 14 811575.2 0.0129624864 15 292223.0 0.0026141820 16 153862.2 0.0075244299 17 1272367.2 0.0068988788 18 734199.0 0.0098799510 19 421404.5 0.0050479335 20 189047.5 0.0048211174 21 529102.0 0.0096373243 22 56833.0 0.0061710425 23 125856.2 0.0083900410 24 598893.8 0.0066222964 25 258240.0 0.0061297368 26 159086.2 0.0088192099 27 122863.0 0.0100925693 28 404699.5 0.0081477489 29 453514.5 0.0084070531 30 545028.0 0.0060956804 31 1233365.5 0.0061105819 32 1192758.2 0.0081616218 33 147563.2 0.0083796600 34 247293.0 0.0102826553 35 1074838.2 0.0074134232 36 459227.5 0.0086199724 37 202332.0 0.0090614422 38 377401.2 0.0069230414 39 1876752.5 0.0102260772 x2 y1 1 50118.72 0.012116846 2 51286.14 0.012053508 3 52480.75 0.011990503 4 53703.18 0.011927830 5 54954.09 0.011865489 6 56234.13 0.011803480 7 57543.99 0.011741804 8 58884.37 0.011680460 9 60255.96 0.011619448 10 61659.50 0.011558769 11 63095.73 0.011498421 12 64565.42 0.011438406 13 66069.34 0.011378724 14 67608.30 0.011319373 15 69183.10 0.011260355 16 70794.58 0.011201669 17 72443.60 0.011143315 18 74131.02 0.011085294 19 75857.76 0.011027605 20 77624.71 0.010970248 21 79432.82 0.010913224 22 81283.05 0.010856531 23 83176.38 0.010800171 24 85113.80 0.010744143 25 87096.36 0.010688448 26 89125.09 0.010633085 27 91201.08 0.010578054 28 93325.43 0.010523355 29 95499.26 0.010468989 30 97723.72 0.010414954 31 10.00 0.010361253 32 102329.30 0.010307883 33 104712.85 0.010254846 34 107151.93 0.010202140 35 109647.82 0.010149768 36 112201.85 0.010097727 37 114815.36 0.010046019 38 117489.76 0.009994643 39 120226.44 0.009943599 40 123026.88 0.009892888 41 125892.54 0.009842508 42 128824.96 0.009792461 43 131825.67 0.009742747 44 134896.29 0.009693364 45 138038.43 0.009644314 46 141253.75 0.009595596 47 144543.98 0.009547211 48 147910.84 0.009499157 49 151356.12 0.009451436 50 154881.66 0.009404047 51 158489.32 0.009356991 52 162181.01 0.009310267 53 165958.69 0.009263875 54 169824.37 0.009217815 55 173780.08 0.009172087 56 177827.94 0.009126692 57 181970.09 0.009081629 58 186208.71 0.009036899 59 190546.07 0.008992500 60 194984.46 0.008948434 61 199526.23 0.008904700 62 204173.79 0.008861299 63 208929.61 0.008818229 64 213796.21 0.008775492 65 218776.16 0.008733088 66 223872.11 0.008691015 67 229086.77 0.008649275 68 234422.88 0.008607867 69 239883.29 0.008566791 70 245470.89 0.008526048 71 251188.64 0.008485636 72 257039.58 0.008445558 73 263026.80 0.008405811 74 269153.48 0.008366396 75 275422.87 0.008327314 76 281838.29 0.008288565 77 288403.15 0.008250147 78 295120.92 0.008212062 79 301995.17 0.008174309 80 309029.54 0.008136888 81 316227.77 0.008099799 82 323593.66 0.008063043 83 331131.12 0.008026619 84 338844.16 0.007990528 85 346736.85 0.007954768 86 354813.39 0.007919341 87 363078.05 0.007884246 88 371535.23 0.007849483 89 380189.40 0.007815053 90 389045.14 0.007780955 91 398107.17 0.007747189 92 407380.28 0.007713756 93 416869.38 0.007680654 94 426579.52 0.007647885 95 436515.83 0.007615449 96 446683.59 0.007583344 97 457088.19 0.007551572 98 467735.14 0.007520132 99 478630.09 0.007489024 100 489778.82 0.007458249 101 501187.23 0.007427806 102 512861.38 0.007397695 103 524807.46 0.007367916 104 537031.80 0.007338470 105 549540.87 0.007309356 106 562341.33 0.007280574 107 575439.94 0.007252125 108 588843.66 0.007224007 109 602559.59 0.007196222 110 616595.00 0.007168770 111 630957.34 0.007141649 112 645654.23 0.007114861 113 660693.45 0.007088405 114 676082.98 0.007062281 115 691830.97 0.007036490 116 707945.78 0.007011031 117 724435.96 0.006985904 118 741310.24 0.006961109 119 758577.58 0.006936647 120 776247.12 0.006912517 121 794328.23 0.006888719 122 812830.52
[R] Plot two separate curves in R Graphics and R Lattice package
Hi, How can I plot two curves with distinct x and y vectors? I would like to join one of them by regular lines and plot the other just by points (no lines). Can it be done in regular R graphic tools, say plot function? Can it be done in Lattice package, say xyplot function? Thanks, Miao My data look like this: two curves with different vector size x y 3973730 0.00322 2391576 0.003487 2840944 0.005145 2040943 0.006359 1982715 0.006253 1618162 0.00544 820082.3 0.004213 1658597 0.004883 1762794 0.006216 93439.5 0.004255 218481.3 0.006924 2332477 0.004862 725835.5 0.00089 811575.3 0.012962 292223 0.002614 153862.3 0.007524 1272367 0.006899 734199 0.00988 421404.5 0.005048 189047.5 0.004821 529102 0.009637 56833 0.006171 125856.3 0.00839 598893.8 0.006622 258240 0.00613 159086.3 0.008819 122863 0.010093 404699.5 0.008148 453514.5 0.008407 545028 0.006096 1233366 0.006111 1192758 0.008162 147563.3 0.00838 247293 0.010283 1074838 0.007413 459227.5 0.00862 202332 0.009061 377401.3 0.006923 1876753 0.010226 and x y 50118.72 0.012117 51286.14 0.012054 52480.75 0.011991 53703.18 0.011928 54954.09 0.011865 56234.13 0.011803 57543.99 0.011742 58884.37 0.01168 60255.96 0.011619 61659.5 0.011559 63095.73 0.011498 64565.42 0.011438 66069.34 0.011379 67608.3 0.011319 69183.1 0.01126 [[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] Plot two separate curves in R Graphics and R Lattice package
Thank you very much. Could it be done in Lattice package? Thanks, Miao 2013/4/10 Janesh Devkota janesh.devk...@gmail.com Hi, This should be fairly easy by using base R graphics. Lets suppose your first data is represented by (x1,y1) and second data is represented by (x2,y2) You can use the following command. plot(x1,y1,type=l) points(x2,y2) Hope it helps. On Tue, Apr 9, 2013 at 8:24 PM, jpm miao miao...@gmail.com wrote: Hi, How can I plot two curves with distinct x and y vectors? I would like to join one of them by regular lines and plot the other just by points (no lines). Can it be done in regular R graphic tools, say plot function? Can it be done in Lattice package, say xyplot function? Thanks, Miao My data look like this: two curves with different vector size x y 3973730 0.00322 2391576 0.003487 2840944 0.005145 2040943 0.006359 1982715 0.006253 1618162 0.00544 820082.3 0.004213 1658597 0.004883 1762794 0.006216 93439.5 0.004255 218481.3 0.006924 2332477 0.004862 725835.5 0.00089 811575.3 0.012962 292223 0.002614 153862.3 0.007524 1272367 0.006899 734199 0.00988 421404.5 0.005048 189047.5 0.004821 529102 0.009637 56833 0.006171 125856.3 0.00839 598893.8 0.006622 258240 0.00613 159086.3 0.008819 122863 0.010093 404699.5 0.008148 453514.5 0.008407 545028 0.006096 1233366 0.006111 1192758 0.008162 147563.3 0.00838 247293 0.010283 1074838 0.007413 459227.5 0.00862 202332 0.009061 377401.3 0.006923 1876753 0.010226 and x y 50118.72 0.012117 51286.14 0.012054 52480.75 0.011991 53703.18 0.011928 54954.09 0.011865 56234.13 0.011803 57543.99 0.011742 58884.37 0.01168 60255.96 0.011619 61659.5 0.011559 63095.73 0.011498 64565.42 0.011438 66069.34 0.011379 67608.3 0.011319 69183.1 0.01126 [[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. [[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] How can I extract part of the data in a panel dataset?
Taking the Grunfeld data, which is built-in in R, for example, (1)How can I construct a dataset (or dataframe) that consists of the data of all firms in 1951? (2)How can I calculate the average capital in each form over the period 1951-1954? What I can imagine is to categorize the data by firm, and then select the data between 1951 and 1954 for each firm, but how can I do it? Thanks, Miao Grunfeld data: invest value capital firm year 317.6 3078.5 2.8 General Motors 1935 391.8 4661.7 52.6 General Motors 1936 410.6 5387.1 156.9 General Motors 1937 257.7 2792.2 209.2 General Motors 1938 330.8 4313.2 203.4 General Motors 1939 461.2 4643.9 207.2 General Motors 1940 512 4551.2 255.2 General Motors 1941 448 3244.1 303.7 General Motors 1942 499.6 4053.7 264.1 General Motors 1943 547.5 4379.3 201.6 General Motors 1944 561.2 4840.9 265 General Motors 1945 688.1 4900.9 402.2 General Motors 1946 568.9 3526.5 761.5 General Motors 1947 529.2 3254.7 922.4 General Motors 1948 555.1 3700.2 1020.1 General Motors 1949 642.9 3755.6 1099 General Motors 1950 755.9 4833 1207.7 General Motors 1951 891.2 4924.9 1430.5 General Motors 1952 1304.4 6241.7 1777.3 General Motors 1953 1486.7 5593.6 2226.3 General Motors 1954 209.9 1362.4 53.8 US Steel 1935 355.3 1807.1 50.5 US Steel 1936 469.9 2676.3 118.1 US Steel 1937 262.3 1801.9 260.2 US Steel 1938 230.4 1957.3 312.7 US Steel 1939 361.6 2202.9 254.2 US Steel 1940 ... [[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] Generating a bivariate joint t distribution in R
Hi, I conduct a panel data estimation and obtain estimators for two of the coefficients beta1 and beta2. R tells me the mean and covariance of the distribution of (beta1, beta2). Now I would like to find the distribution of the quotient beta1/beta2, and one way to do it is to simulate via the joint distribution (beta1, beta2), where both beta1 and beta2 follow t distribution. How could we generate a joint t distrubuition in R? Thanks Miao [[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] Change the Chinese/English fonts in the Lattice graphic package
Hi, I am graphing with the following command in the Lattice and LatticeExtra package xyplot(xts,lty=c(1,2),col=c(blue,red),type=c(l,g),par.settings = list(layout.heights = list(panel = c(2, 2))), aspect=xy,xlab=,ylab=%, key=key1,screen=list(a,a,b,b,c,c,d,d), layout=c(2,2), scales=list(x=same,y=same)) where a, b, c, d contains English and Chinese characters How can I modify the preceding line to change the fonts? (1) I find from the manual that font=2 represents boldface, while 3 represents italics. Where should I add it? (2) The default Chinese character seems to be ²Ó©úÅé (Shi Ming Tee). How can I change it to Kai -Shu (·¢®Ñ)? Thanks, Miao [[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] About multivariate GARCH: DVEC and BEKK
Dear All, I attempted to fit a DVEC and a BEKK multivariate GARCH model, but am wondering which package to use. 1. I tried to use rmgarch package in R, but I couldn't find the subroutines for DVEC and BEKK. 2. I tried to find rmgarch package of R, which is not located on the official R site. This is the latest version I can find, where the programs were uploaded 2 years ago. https://github.com/vst/mgarch/downloads Are there later versions? Is there a manual on the functions? Thanks, Miao [[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] Are there multivariate GARCH packages in R?
Hi , Are there any multivariate GARCH package (e.g., BEKK) in R? I do see a few projects constructing multivariate GARCH package, but wonder if there is anyone that is ready for use. Thanks, Miao [[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] Do we have GARCH-in-mean VAR in R?
Hi everyone, Do we have GARCH-in-mean VAR in R? Is there any GARCH package in R? Thanks, Miao [[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] How can I read the following complicated table
Hello, I have a table (in a txt file) which look like this: Monday 12 78 89 Tuesday 34 44 67 Wednesday 78 98 2 Thursday 34 55 4 Then the table repeats Monday , Tuesday, ... followed by several numbers My goal is to read values after the table. My problem is a little more complicated, but I just present a simpler case for ease of illustration. Is there any way to ask R to read several number after you see the word 'Monday' and store somewhere, and read several number after you see the word 'Tuesday' and store somewhere? Thanks, miao [[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] A question on xyplot function in Lattice package
Hi, I am using xylot function in Lattice package. I find it excellently written, but I don't know how to find resources on this function. One thing I would like to change is the line type. To my knowledge, type =l means a regular line, type g means broken lines, but I can't find a complete list of the choices. The info obtained from the query in R is limited. Could anyone tell me where I can find the complete description of the function, including all types of lines it offers? Thanks! Miao [[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] Input and output of time series data - any function or packages that helps?
Hello, I work with time series data. From time to time I run programs to produce results that are in time series form (e.g., quarterly or monthly data). After a few days I might need to access part of the results and to run another program. Is there any function or package (like dataframe or zoo?) that might help so that I don't need to copy the results manually to a csv or xls file? If the data are not time series (just indexed by 1, 2,3), is there any function that can help? Thanks, Miao [[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] Is there a function that runs AR model with Schwarz Bayesian Information Criteria (BIC)?
Hello, Is there a function in R by which one can run AR model with Bayesian Information Criteria (BIC)? To my knowledge, functions ar and ar.ols could select the order only by AIC. Thanks, Miao [[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] Is there a function that runs AR model with Schwarz Bayesian Information Criteria (BIC)?
Thanks. Which function I can use for forecasting if I use the function auto.arima()? Should I use the function forecast or predict or anything else? Thanks, Miao 2012/9/27 Jose Iparraguirre jose.iparragui...@ageuk.org.uk You'll find this in the forecast package, function auto.arima() Regards, José José Iparraguirre Chief Economist Age UK T 020 303 31482 E jose.iparragui...@ageuk.org.uk Twitter @jose.iparraguirre@ageuk Tavis House, 1- 6 Tavistock Square London, WC1H 9NB www.ageuk.org.uk | ageukblog.org.uk | @ageukcampaigns For evidence and statistics on the older population, visit the Age UK Knowledge Hub http://www.ageuk.org.uk/professional-resources-home/knowledge-hub-evidence-statistics/ -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of jpm miao Sent: 27 September 2012 09:43 To: r-help Subject: [R] Is there a function that runs AR model with Schwarz Bayesian Information Criteria (BIC)? Hello, Is there a function in R by which one can run AR model with Bayesian Information Criteria (BIC)? To my knowledge, functions ar and ar.ols could select the order only by AIC. Thanks, Miao [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Age UK and YouthNet are official charities for the Virgin London Marathon 2013 We need you to Run for it. Join the team and help raise vital funds to bring generations together to combat loneliness and isolation. Go to http://www.runforit.org.uk for more information or contact Helen Parson at helen.pars...@ageuk.org.uk or on 020 303 31369. Age UK and YouthNet. A lifeline, online. www.runforit.org.uk Age UK Improving later life www.ageuk.org.uk --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you receive a message in error, please advise the sender and delete immediately. Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing through its network and may block or modify mails which are deemed to be unsuitable. Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: Age Scotland, Age NI, Age Cymru. [[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] Questions about the functions ar.ols and auto.arima when fitting an AR model
Hi, I am trying to fit an AR model, maximum order =4, order selection criterion is aic. I wonder why these two give different results: m1-ar.ols(x, aic=TRUE, method=ols, order.max=4) m1-auto.arima(x,d=0, D=0, max.p=4, max.P=0, max.q=0, max.Q=0, ic=aic) Could they both use the function predict to do forecasting? Is there any function that works better? temp1-predict(m1, n.ahead=4) PI.fore[i,j]-temp1$pred[4] Thanks Miao [[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] Adding legends on plots using Lattice package
To dear Dr Sarkar and anyone that knows about Lattice package, I make 4 graphs by Lattice package. Each of the graphs has two time series. All the series are plotted in plain lines by default, and I would like one series to be in plain line and the other to be in dotted line in each graph. How can I modify the command of xyplot in the following line to achieve this? It seems that key or auto.key parameters are needed, but I don't know how to do it. Thank you very much! require(graphics) library(lattice) data1-read.csv(file=G_Results_3FX1.csv, header=TRUE) xts-ts(data1[,2:9],frequency = 4, start = c(1983, 1)) xyplot(xts, screen=list(a,a,b,b,c,c,d,d), layout=c(2,2), scales=list(x=same,y=same)) Miao [[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] How can I find the principal components and run regression/forecasting using dynlm
Hello, I would like to write a program that compute the principal components of a set of data and then 1. Run the dependent variable against the principal components (lagged value) 2. Do prediction , following Stock and Watson (1999) Forecasting Inflation. All data are time series. Now I can run the program using single factor (first principal component), but I don't know how to write a program for muli-factor model (first several principal component). The core subroutine called is dynlm, which runs OLS for time series. I think the primary problem is that (1) I don't how to run dynlm with matrix rather than vector as explanatory variables (2)I don't know how to do a forecast with the estimation results of dynlm properly. In lm model, function predict.lm can do it. For the case of first principal component (In order to accentuate the main problem, I have simplify the codes): Mpca-prcomp(M1, center=TRUE, scale =TRUE) # M1 is the data matrix of explanatory variables Mpca1st-Mpca$x[,1] # first principle component X-as.matrix(Mpca1st) model-dynlm(as.ts(y[(h+1):t]) ~ L(as.ts(X[1:(t-h)]), 0:i) + L(as.ts(z[1:(t-h)]),0:j)) # y, X, z are a zoo objects defined earlier; i and j, t, h are given earlier; h is the forecasting horizon; since dynlm can't work for zoo object, the variables need to be transformed to ts objects. Xlast-as.matrix(X[(t-h):(t-h-i+1)]) zlast-t(as.matrix(z[(t-h):(t-h-j+1)])) # Make it a column matrix beta-as.matrix(model$coefficient) pi1fore[t]-pi1[t-h]+c(1, Xlast, zIlast)%*%beta # pi1fore is defined earlier . I just use the inner product as a vehicle for forecasting. I don't know if there's a way that the codes can be written neatly? return(pi1fore) Then I attempt to program similarly for the multi-factor case: Mpca-prcomp(M1, center=TRUE, scale =TRUE) # M1 is the data matrix of explanatory variables Mpca1f-Mpca$x[,(1:f)] # first f principle components X-as.matrix(Mpca1f) model-dynlm(as.ts(y[(h+1):t]) ~ L(as.ts(X[1:(t-h),]), 0:i) + L(as.ts(z[1:(t-h)]),0:j)) # Since X has more than one column, I add a comma after 1:(t-h). I don't know if I am right here? Xlast-as.matrix(X[(t-h):(t-h-i+1), ]) zlast-t(as.matrix(z[(t-h):(t-h-j+1)])) # Make it a column matrix beta-as.matrix(model$coefficient) pi1fore[t]-pi1[t-h]+c(1, Xlast, zIlast)%*%beta # It does not seem to work here! How can I modify the program...?. return(pi1fore) [[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] How should one handle NA properly in a .csv dataset?
Hi, I am reading several .csv file of time series. Some values of the time series are unavailable. Some of the unavailable series are marked NA, and some are just blank. The NA value can be read, but the blank cannot be read. Then I change the change the blank to NA, but they can't be properly read. When I check the difference between the two types of NA, I find: Those can be read are outputed as NA. Those can't be read (which I change from the blank) are outputed as NA. Could anyone tell me how I can input the NA properly? Thanks, Miao [[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] How should one handle NA properly in a .csv dataset?
Hi, I find the problem. Some of the numbers like 1357 are presented as 1,357. After deleting the comma, everything is ok. Thank you for your attention! Miao 2012/8/22 jpm miao miao...@gmail.com Hi, I am reading several .csv file of time series. Some values of the time series are unavailable. Some of the unavailable series are marked NA, and some are just blank. The NA value can be read, but the blank cannot be read. Then I change the change the blank to NA, but they can't be properly read. When I check the difference between the two types of NA, I find: Those can be read are outputed as NA. Those can't be read (which I change from the blank) are outputed as NA. Could anyone tell me how I can input the NA properly? Thanks, Miao [[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] Accessing the (first or more) principal component with princomp or prcomp
Hi , To my knowledge, there're two functions that can do principal component analysis, princomp and prcomp. I don't really know the difference; the only thing I know is that when the sample size number of variable, only prcomp will work. Could someone tell me the difference or where I can find easy-to-read reference? To access the first PC using princomp: Mpca-princomp(M, cor=T) Mpca$scores[,1] How can I access the first PC using prcomp? Mpca-prcomp(M) Is there an option for cor=T? In case where both functions work, will the results be the same? Thanks, Miao [[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] Symbolic computation in R-solving system of equations
Hi, To my knowledge, Ryacas can do symbolic computation in R, like Mathematica or Maple. I wonder if it (or any other R package) can solve symbolically a system of equations? I have a system of four equations in four variables (non-linear, but not very hard to solve) and wonder if Ryacas or any other package can do it. I do not find the solution in Ryacas. Can it find a symbolic solution to a linear system? Thanks, Miao [[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] Zoo object problem: problem when I attempt to create a zoo object of only one column
Hi, Part of my program is to calculate the number of time series in a zoo object. It works well if it has more than one time series, but it fails if it has only one. How can I access the number of column (i.e. the number of time series) when I have only one column? Why is the number of an object of only one object NULL? It should be one, shouldn't it? (The following example does not involve the creation of a zoo object; in reality, similar problems are encountered when I create a zoo object) temp5-read.csv(A_Consumption.csv, header=TRUE) temp5[1:3,]TIME C C_D C_ND 1 196101 70345 1051 69294 2 196102 61738 905 60833 3 196103 63838 860 62978 temp6-temp5[,2:ncol(temp5)] temp6[1:3,] C C_D C_ND 1 70345 1051 69294 2 61738 905 60833 3 63838 860 62978 colnames(temp6)[1] CC_D C_ND temp7-read.csv(A_FX_EUR_Q.csv, header=TRUE) temp7[1:3,]TIME EUR 1 198001 1.41112 2 198002 1.39108 3 198003 1.42323 temp8-temp7[,2:ncol(temp7)] temp8[1:3,]Error in temp8[1:3, ] : incorrect number of dimensions ncol(temp6)[1] 3 ncol(temp8) # Why isn't it 1?NULL temp8 [1] 1.411120 1.391080 1.423230 1.342050 1.232870 [6] 1.115090 1.032930 1.089250 1.036320 1.001850 [11] 0.950641 0.933593 0.947940 0.911204 0.860682 [16] 0.843864 0.831666 0.824776 0.768626 0.732064 [21] 0.684473 0.726018 0.784729 0.852911 0.922885 [26] 0.958778 1.012740 1.038160 1.124550 1.149780 [31] 1.128450 1.214120 1.233530 1.216270 1.113620 [36] 1.170250 1.126230 1.074330 1.078480 1.127870 [41] 1.205540 1.222740 1.296500 1.366550 1.341280 [46] 1.187600 1.176790 1.254490 1.262610 1.271820 [51] 1.385930 1.268130 1.190480 1.206840 1.150270 [56] 1.140010 1.125200 1.163450 1.226830 1.240210 [61] 1.273300 1.331010 1.312420 1.317350 1.287330 [66] 1.254500 1.274210 1.261930 1.178970 1.143500 [71] 1.093320 1.123400 1.086770 1.100380 1.117670 [76] 1.176960 1.121600 1.056900 1.048600 1.038000 [81] 0.986500 0.933200 0.905200 0.868300 0.923200 [86] 0.872500 0.890300 0.895900 0.876600 0.918800 [91] 0.983800 0.999400 1.073100 1.137200 1.124800 [96] 1.189000 1.249700 1.204600 1.222000 1.297700 [101] 1.311300 1.259400 1.219900 1.188400 1.202300 [106] 1.258200 1.274300 1.288700 1.310600 1.348100 [111] 1.373800 1.448600 1.497600 1.562200 1.505000 [116] 1.318000 1.302900 1.363200 1.430300 1.477900 [121] 1.382900 1.270800 1.291000 1.358300 1.368000 [126] 1.439100 1.412700 1.348200 1.310800 1.281400 [[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] Zoo object problem: Find the column name of a univariate zoo object
Hi everyone and Achim, Achim, I appreciate your help about the function NCOL. When I use NCOL instead of ncol, I can find out the number of columns (number of time series) in the presence of only one time series (one variable, one column). Now I want to know how I can find out the column names of the zoo objects? In case of more than one time series, the function colnames works, but not for the univariate time series. Thanks, Miao 2012/8/9 Achim Zeileis achim.zeil...@uibk.ac.at On Thu, 9 Aug 2012, jpm miao wrote: Hi, Part of my program is to calculate the number of time series in a zoo object. It works well if it has more than one time series, but it fails if it has only one. How can I access the number of column (i.e. the number of time series) when I have only one column? Why is the number of an object of only one object NULL? It should be one, shouldn't it? (The following example does not involve the creation of a zoo object; in reality, similar problems are encountered when I create a zoo object) Univariate zoo series are by default vectors, i.e., have no dim attribute. You can either choose to store a matrix instead of a vector in the zoo series - or you can use NCOL() instead of ncol() to extract the number of columns. See the corresponding manual pages for more details. An illustration is included below: ## univariate series R x - sin(1:4) R z - zoo(x) R z 1 2 3 4 0.8414710 0.9092974 0.1411200 -0.7568025 R dim(z) NULL R ncol(z) NULL R NCOL(z) [1] 1 ## alternatives to create a 1-column matrix instead of a vector R z1 - zoo(matrix(x, ncol = 1)) R z1 1 0.8414710 2 0.9092974 3 0.1411200 4 -0.7568025 R dim(z1) [1] 4 1 R dim(z) - c(NROW(z), NCOL(z)) R z 1 0.8414710 2 0.9092974 3 0.1411200 4 -0.7568025 R dim(z) [1] 4 1 temp5-read.csv(A_**Consumption.csv, header=TRUE) temp5[1:3,]TIME C C_D C_ND 1 196101 70345 1051 69294 2 196102 61738 905 60833 3 196103 63838 860 62978 temp6-temp5[,2:ncol(temp5)] temp6[1:3,] C C_D C_ND 1 70345 1051 69294 2 61738 905 60833 3 63838 860 62978 colnames(temp6)[1] CC_D C_ND temp7-read.csv(A_FX_EUR_Q.**csv, header=TRUE) temp7[1:3,]TIME EUR 1 198001 1.41112 2 198002 1.39108 3 198003 1.42323 temp8-temp7[,2:ncol(temp7)] temp8[1:3,]Error in temp8[1:3, ] : incorrect number of dimensions ncol(temp6)[1] 3 ncol(temp8) # Why isn't it 1?NULL temp8 [1] 1.411120 1.391080 1.423230 1.342050 1.232870 [6] 1.115090 1.032930 1.089250 1.036320 1.001850 [11] 0.950641 0.933593 0.947940 0.911204 0.860682 [16] 0.843864 0.831666 0.824776 0.768626 0.732064 [21] 0.684473 0.726018 0.784729 0.852911 0.922885 [26] 0.958778 1.012740 1.038160 1.124550 1.149780 [31] 1.128450 1.214120 1.233530 1.216270 1.113620 [36] 1.170250 1.126230 1.074330 1.078480 1.127870 [41] 1.205540 1.222740 1.296500 1.366550 1.341280 [46] 1.187600 1.176790 1.254490 1.262610 1.271820 [51] 1.385930 1.268130 1.190480 1.206840 1.150270 [56] 1.140010 1.125200 1.163450 1.226830 1.240210 [61] 1.273300 1.331010 1.312420 1.317350 1.287330 [66] 1.254500 1.274210 1.261930 1.178970 1.143500 [71] 1.093320 1.123400 1.086770 1.100380 1.117670 [76] 1.176960 1.121600 1.056900 1.048600 1.038000 [81] 0.986500 0.933200 0.905200 0.868300 0.923200 [86] 0.872500 0.890300 0.895900 0.876600 0.918800 [91] 0.983800 0.999400 1.073100 1.137200 1.124800 [96] 1.189000 1.249700 1.204600 1.222000 1.297700 [101] 1.311300 1.259400 1.219900 1.188400 1.202300 [106] 1.258200 1.274300 1.288700 1.310600 1.348100 [111] 1.373800 1.448600 1.497600 1.562200 1.505000 [116] 1.318000 1.302900 1.363200 1.430300 1.477900 [121] 1.382900 1.270800 1.291000 1.358300 1.368000 [126] 1.439100 1.412700 1.348200 1.310800 1.281400 [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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.