[R] Sweave \Sexpr{} advice please
Dear List, First off, my deepest gratitude to the Sweave developers: this tool has improved my quality greatly. A question in my work I use \Sexpr{} statements scalar values and the xtable package for all manner of tables. What I'd like to do is to use a vector inline, rather than a whole separate table. Something like: begin code % Latex junk % Sweave block: = covmat - cov(matrix(runif(100),ncol=3)) @ % back to Latex, typing up a report, my homework, etc. The first column of the covariance matrix is $(\Sexpr{covmat[1,1]}, \Sexpr{covmat[2,1]}, \Sexpr{covmat[3,1]})^T$ % end code but, of course, this is poor way of going about it. Any suggestions? Thanks in advance. Regards, Kyle [[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] question about the tisPlot function in package tis
List, I am using the 'tisPlot' function in Jeff Hallman's excellent tis package and was hoping that someone could spare me from having to dig into the code of his 'tisPlot' function. So far as I can tell, the preferred method of controlling the plotting of the x-axis is using the 'xTickFreq' and 'xTickSkip' options. Unfortunately, the where the data ends up on the resultant plot is not invariant to this choice, as indicated in the documentation of the 'xTickFreq' option. Has anyone adjusted the frequency of their x-axis label using this package before? I imagine that there must be a better way of doing what I am trying to accomplish, but if not, does anyone have a suggestion on how to work around this without digging into the function itself? ## an example library(tis) strt - ti(2101, monthly) dat - tis(runif(9*12 - 1), start=strt) # ends in 11/2008 par(mfrow=c(2,1)) tisPlot(dat, xTickFreq=monthly, xTickSkip=6) # graph ends in 11/2008, but looks to start some time in late 1999 tisPlot(dat, xTickFreq=monthly, xTickSkip=12) # graph looks to end around 3/2009 ## end TIA, Kyle ___ Research Associate, Macroeconomics Federal Reserve Bank of San Francisco [[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] including Sweave tangled code in '.Rnw' document
Hello List, I have been using Sweave for my homework this last quarter and have been very impressed at how much time and effort it saves me. I, however, have run up against a problem which I have not been able to solve using any of the Sweave/LaTeX tricks I know. I work through my homework one problem at a time, typesetting equations and writing R code, etc. and occasionally use 'Stangle()' from within R to extract the code if I need to pin down a problem or experiment interactively. I would like to be able to include this resultant code in a verbatim environment in my final TeX'ed up document as an appendix so that the grader can look it over, etc. I could implement this in any number of ways using linux tools, but would like to know if there is a clean way to do so using LaTeX or Sweave so that the latest version of the code is included in my homework each time I run 'R CMD Sweave HW4.Rnw; pdflatex HW4.tex'. e.g I envision something such as: \begin{document} fig3, echo=false, results=hide, fig=true, eps=F= plot(runif(1000)) @ TA here is my code: % some manner of Sweave/LaTeX macro to include the R code tangled out of this '.Rnw' document % in this case it would just be 'plot(runif(1000))', perhaps manually enclosed in a verbatim environment \end{document} I am running R-2.6.2 on Ubuntu Hardy Heron. Thanks for all your help with Sweave. I think it is a fantastic tool. Kyle [[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] function for simultaneous confidence interval of regression coefficients
List, Would someone be so kind as to point me to a function that will calculate simultaneous confidence intervals of regression coefficients based upon their distribution as (under the assumption of normal errors, with \mathbf{X} as the design matrix): $\hat{\mathbf{\beta}} \sim N(\mathbf{\beta}, \sigma^2(\mathbf{X}^T\mathbf{X})^{-1})$. 'confint' calculates individual coefficients so far as I can tell, but I need simultaneous CIs based on the confidence ellipse/ F distribution. Inverting the ellipse gives this equation: \mathbf{\hat{\beta}} \pm \sqrt{\mathrm{diag}(s^2(\mathbf{X}^T\mathbf{X})^{-1}) \times p \times F_{p, n-p, .95}} Thanks, and sorry for such a dumb question. Either I am not searching for the right thing or this hasn't already been addressed in the lists (perhaps because it is so easy). Kyle [[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] including Sweave tangled code in '.Rnw' document
Vincent, Ista, Berwin: Thank you all for your help. It is great that a student like myself can receive help from Professors and experts such as yourselves. To the list, I found Berwin's solution to work excellently, though I chose to change the font of the included text, e.g. \texttt{ \lstinputlisting[emptylines=0]{XYZ.R} } Ista's suggestion also seems excellent, though I am required to submit a paper copy of the work and Ista's is a bit easier to manage with this goal in mind. Vincent's comment is also quite appropriate, unfortunately I have enough trouble with LaTeX as it is and the problem has been solved to my satisfaction I have chosen to put off exploration of this package for another day. Best, Kyle On Sun, Nov 30, 2008 at 8:42 AM, Vincent Goulet [EMAIL PROTECTED] wrote: Kyle, In addition to listings already mentioned by Berwin, you may find useful the answers package. This is what I use to create assignments/exams/exercise sets with solutions all in one file. HTH Vincent --- Vincent Goulet, Associate Professor École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca Le sam. 29 nov. à 14:11, Kyle Matoba a écrit : Hello List, I have been using Sweave for my homework this last quarter and have been very impressed at how much time and effort it saves me. I, however, have run up against a problem which I have not been able to solve using any of the Sweave/LaTeX tricks I know. I work through my homework one problem at a time, typesetting equations and writing R code, etc. and occasionally use 'Stangle()' from within R to extract the code if I need to pin down a problem or experiment interactively. I would like to be able to include this resultant code in a verbatim environment in my final TeX'ed up document as an appendix so that the grader can look it over, etc. I could implement this in any number of ways using linux tools, but would like to know if there is a clean way to do so using LaTeX or Sweave so that the latest version of the code is included in my homework each time I run 'R CMD Sweave HW4.Rnw; pdflatex HW4.tex'. e.g I envision something such as: \begin{document} fig3, echo=false, results=hide, fig=true, eps=F= plot(runif(1000)) @ TA here is my code: % some manner of Sweave/LaTeX macro to include the R code tangled out of this '.Rnw' document % in this case it would just be 'plot(runif(1000))', perhaps manually enclosed in a verbatim environment \end{document} I am running R-2.6.2 on Ubuntu Hardy Heron. Thanks for all your help with Sweave. I think it is a fantastic tool. Kyle [[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] declaring constants in an Sweave / LaTeX document
List, I would like to set a variable to hold, say, the size of my plots in a Sweave document. i.e. something like the following in my '.Rnw' file: == smallPlotSize = 4 fig1, echo=false, results=hide, height=smallPlotSize, width=smallPlotSize, fig=true= dat - read.table( http://www.stanford.edu/~xing/statfinbook/_BookData/Chap05/q_us_gdp.txt;, skip=2, header=T) GDP - ts(data=dat$VALUE, start=c(1947,1), frequency=4) acf(GDP, type=correlation, main= ACF of US GDP) @ == This way I can tweak things if I have to include a bunch of graphics of the same size in a file. I am not great with LaTeX and still very new to using Sweave, so I was wondering what the preferred method of doing something like this is between LaTeX and Sweave. I have seen some people doing some tricky stuff from within R such that when their code is preprocessed it is compiled as LaTeX source, but this seems like an ugly hack for something so simple. Please forgive me if this has been addressed elsewhere; I have found documentation on Sweave to be rather sparse. Best, Kyle [[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 about diparate device quality
List, I have a question about why plots sent to certain devices can be of so much worse quality than others. Whenever I plot to x11 or pdf the graphs are of excellent quality. eps is a bit poorer, but of passable quality, and jpeg or tiff are terrible. I tried all manner of parameters, on many versions of R (most major releases from about 2.2 - present) under linux and windows and on a few different (pc) hardware setups and this patterns seems to be invariant. Could anyone explain why this is the case? For school and work I just pdflatex my pdf graphs into latex so it isn't a problem, but my new job likes to include them in, say, MS word documents for which I cannot easily use pdf. TIA, Kyle [[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] multiple page pdf file using pdf()
List, I am currently producing a series of charts using multiple calls to pdf() but, rather than having 'n' single plot files, would like them all to go into one 'n'-page pdf file. Would someone be so kind as to explain how, if at all, I might go about doing this from within R? I have only ever previously used devices besides x11 by analogy with printing things to x11. I am running R-2.7.2 on Red Hat Linux. TIA, Kyle [[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] multiple page pdf file using pdf()
Peter, Ah, I was under the impression that I had to 'dev.off()' after every plot. Naturally I had wondered about that strange argument that did not seem to do anything... Problem solved, thanks everyone. Many thanks, Kyle On Mon, Sep 29, 2008 at 9:43 AM, Peter Dalgaard [EMAIL PROTECTED]wrote: Kyle Matoba wrote: List, I am currently producing a series of charts using multiple calls to pdf() but, rather than having 'n' single plot files, would like them all to go into one 'n'-page pdf file. Would someone be so kind as to explain how, if at all, I might go about doing this from within R? I have only ever previously used devices besides x11 by analogy with printing things to x11. I am running R-2.7.2 on Red Hat Linux. Did you as much as look at help(pdf) Specifically, there is a onefile argument. It is even TRUE by default! So just don't close and reopen the device between plots. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 [[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] rbinom not using probability of success right
Message: 24 Date: Wed, 28 May 2008 05:53:26 -0700 (PDT) From: Philip Twumasi-Ankrah [EMAIL PROTECTED] Subject: [R] rbinom not using probability of success right To: r-help@r-project.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain I am trying to simulate a series of ones and zeros (1 or 0) and I am using rbinom but realizing that the number of successes expected is not accurate. Any advice out there. This is the example: N-500 status-rbinom(N, 1, prob = 0.15) count-sum(status) 15 percent of 500 should be 75 but what I obtain from the count variable is 77 that gives the probability of success to be 0.154. Not very good. Is there another way beyond using sample and rep together? I understand you correctly you want there to be exactly 75 ones. If this is what you are trying to do then using pseudorandom variables is the incorrect way of going about it. Your suggestion of sample(c(rep (0,545),rep(1,75))) seems to me to be the best way of going about it since conceptually this is what you are doing: taking permutation of a fixed set of numbers. Best, Kyle __ 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.