Re: [R] Error Message Documentation
cjkogan111 wrote: Hello, I am new to R, and trying to work with it. I have a couple of quick questions. First, I made a program and got the following error message. -- Error in if (DatMdFile$Time.Value[NmRecord] VBinTimesMinTop[NmCounter]) { : missing value where TRUE/FALSE needed In addition: Warning message: not meaningful for factors in: Ops.factor(DatMdFile$Time.Value[NmRecord], VBinTimesMinTop[NmCounter]) - I noticed that one of the values had decimal places, while the other didn't, so the comparison would be 11.00 10 I don't know if that might have anything to do with my problem. Well, not really the decimal places, but the data type. Anyway, I don't have much idea what the error means, and I don't know how to check what data type the different vectors are. So time to start looking at the documentation? class() is your friend, you might also want to try str(). I was wondering if anyone could help me out, and also, I was wondering if there is any error documentation (stuff that tells what the error means.) Probably one of your objects is a factor rather than a numeric value. Thanks! - cjkogan111 ujligges1234 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] regarding chaos
[EMAIL PROTECTED] wrote: hi all, I have a simple question that does power spectral analysis related to capacity dimension, information dimension, lyapunov exponent, hurst exponent. Hurst Aanalysis is implemented in fSeries from Rmetrics. The following functions are available: ### # PART I: Simulation # FUNCTIONS:FRACTIONAL BROWNIAN MOTION: # fbmSimGenerates fractional Brownian motion # Available Methods: # Numerical approximation of the stochastic integral # Choleki's decomposition of the covariance matrix # Method of Levinson # Method of Wood and Chan # Wavelet synthesis # FUNCTIONS:FRACTIONAL GAUSSIAN NOISE: # fgnSimGenerates fractional Gaussian noise # Available Methods: # Durbin's Method # Paxson's Method # Beran's Method # FUNCTIONS:FARIMA PROCESS: # farimaSim Generates FARIMA time series process # PART II: Reimplemented functions from Beran's SPlus Scripts # FUNCTIONS:DESCRIPTION: # farimaTrueacf Returns FARMA true autocorrelation function # farimaTruefft Returns FARMA true fast Fourier transform # fgnTrueacfReturns FGN true autocorrelation function # fgnTruefftReturns FGN true fast Fourier transform # FUNCTIONS:WHITTLE ESTIMATOR: # whittleFitWhittle Estimator # PART III: Reimplemented SPlus/C functions from # Taqqu M.S, Teverovsky V, Willinger W. # Estimators for Long-Range Dependence: An Empirical Study # Fractals, Vol 3, No. 4, 785-788, 1995 # FUNCTIONS: HURST EXPONENT: # 'fHURST'S4 Class Representation # print.fHURSTS3 Print Method # plot.fHURST S3 Plot Method # aggvarFit Aggregated variance method # diffvarFit Differenced aggregated variance method # absvalFit Absolute values (moments) method # higuchiFit Higuchi's method # pengFit Peng's or Residuals of Regression method # rsFit R/S method # perFit Periodogram and cumulated periodogram method # boxperFit Boxed (modified) peridogram method # whittleFit Whittle estimator - PART II # hurstSlider Hurst Slider Diethelm Wuertz If yes then please show me the way. I am newbie in the world of chaos. Sayonara With Smile With Warm Regards :-) G a u r a v Y a d a v Senior Executive Officer, Economic Research Surveillance Department, Clearing Corporation Of India Limited. Address: 5th, 6th, 7th Floor, Trade Wing 'C', Kamala City, S.B. Marg, Mumbai - 400 013 Telephone(Office): - +91 022 6663 9398 , Mobile(Personal) (0)9821286118 Email(Office) :- [EMAIL PROTECTED] , Email(Personal) :- [EMAIL PROTECTED] DISCLAIMER AND CONFIDENTIALITY CAUTION:\ \ This message and ...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using table in R
hi, here's a way: attr(table(unlist(d)),'dimnames')[[1]] [1] 1 2 3 as.numeric(table(unlist(d))) [1] 1 1 2 soren - Original Message - From: Bingshan Li [EMAIL PROTECTED] To: jim holtman [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Sunday, September 17, 2006 6:14 AM Subject: Re: [R] using table in R Hi Jim, This is the way to get the frequencies. But what I want is to store the elements in one vector and their frequencies in another vector. My problem is that when I call table to return the frequency table, I do not know how to extract these two vectors. I tried table(...)$dinnames and it did not work. It returned NULL. Thanks! --- jim holtman [EMAIL PROTECTED] wrote: Here is one way; you create a vector of the data in the dataframe with 'unlist' and then use table: d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2)) d V1 V2 1 1 3 2 2 3 table(unlist(d)) 1 2 3 1 1 2 On 9/16/06, Bingshan Li [EMAIL PROTECTED] wrote: Hi there, I have a dataframe whose elements are numbers or characters. I want to extract the frequencies of each elements in the dataframe. For example, d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2)) What I want is first what are the elements in the data (1,2,3 here) and second what are their frequencies (1,1,2 respectively). How to use table to extract these two pieces of information? I played with table but couldn't extract the information. Please assume that we do not know how many elements in the dataframe a priori. Thanks a lot! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help on data frame and matrix
Hey, I am given a data frame, which actually contains a matrix. But I need to convert the data frame into a matrix so that I can use the matrix operators. Can anybody help me out? Thanks a lot. Thaleia [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help on data frame and matrix
look at ?data.matrix() Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Finosaur [EMAIL PROTECTED]: Hey, I am given a data frame, which actually contains a matrix. But I need to convert the data frame into a matrix so that I can use the matrix operators. Can anybody help me out? Thanks a lot. Thaleia [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help on sampling from Dirichlet process
Hey, I have a question on Dirichlet process. I am using a Dirichlet process as a prior. So I end up with a mixture distribution with a continuous component and a random number of discrete components at some mass-points. I tried some algorithms, but it's too too inefficient. Anyone know some efficient algorithm? Any easy-to-read paper or some templates? Thanks a lot. I am so frustrated. Thaleia [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using table in R
You can use 'names' d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2)) x - table(unlist(d)) x 1 2 3 1 1 2 names(x) [1] 1 2 3 On 9/17/06, Søren Merser [EMAIL PROTECTED] wrote: hi, here's a way: attr(table(unlist(d)),'dimnames')[[1]] [1] 1 2 3 as.numeric(table(unlist(d))) [1] 1 1 2 soren - Original Message - From: Bingshan Li [EMAIL PROTECTED] To: jim holtman [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Sunday, September 17, 2006 6:14 AM Subject: Re: [R] using table in R Hi Jim, This is the way to get the frequencies. But what I want is to store the elements in one vector and their frequencies in another vector. My problem is that when I call table to return the frequency table, I do not know how to extract these two vectors. I tried table(...)$dinnames and it did not work. It returned NULL. Thanks! --- jim holtman [EMAIL PROTECTED] wrote: Here is one way; you create a vector of the data in the dataframe with 'unlist' and then use table: d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2)) d V1 V2 1 1 3 2 2 3 table(unlist(d)) 1 2 3 1 1 2 On 9/16/06, Bingshan Li [EMAIL PROTECTED] wrote: Hi there, I have a dataframe whose elements are numbers or characters. I want to extract the frequencies of each elements in the dataframe. For example, d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2)) What I want is first what are the elements in the data (1,2,3 here) and second what are their frequencies (1,1,2 respectively). How to use table to extract these two pieces of information? I played with table but couldn't extract the information. Please assume that we do not know how many elements in the dataframe a priori. Thanks a lot! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using table in R
This is the way to get the frequencies. But what I want is to store the elements in one vector and their frequencies in another vector. My problem is that when I call table to return the frequency table, I do not know how to extract these two vectors. I tried table(...)$dinnames and it did not work. It returned NULL. Try: as.data.frame(table(1:10)) Hadley __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using table in R
On Sun, 17 Sep 2006, jim holtman wrote: You can use 'names' d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2)) x - table(unlist(d)) x 1 2 3 1 1 2 names(x) [1] 1 2 3 You can, but Søren was equally correct: names() on a 1D array actually looks up the dimnames. OTOH, we do really want to encourage people to use the accessor functions, so dimnames(x)[[1]] [1] 1 2 3 is better supported. On 9/17/06, Søren Merser [EMAIL PROTECTED] wrote: hi, here's a way: attr(table(unlist(d)),'dimnames')[[1]] [1] 1 2 3 as.numeric(table(unlist(d))) [1] 1 1 2 You don't need as.numeric here: as.vector will remove the attributes if that is the intention. soren - Original Message - From: Bingshan Li [EMAIL PROTECTED] To: jim holtman [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Sunday, September 17, 2006 6:14 AM Subject: Re: [R] using table in R Hi Jim, This is the way to get the frequencies. But what I want is to store the elements in one vector and their frequencies in another vector. My problem is that when I call table to return the frequency table, I do not know how to extract these two vectors. I tried table(...)$dinnames and it did not work. It returned NULL. Thanks! --- jim holtman [EMAIL PROTECTED] wrote: Here is one way; you create a vector of the data in the dataframe with 'unlist' and then use table: d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2)) d V1 V2 1 1 3 2 2 3 table(unlist(d)) 1 2 3 1 1 2 On 9/16/06, Bingshan Li [EMAIL PROTECTED] wrote: Hi there, I have a dataframe whose elements are numbers or characters. I want to extract the frequencies of each elements in the dataframe. For example, d = as.data.frame(matrix(c(1, 2, 3, 3), 2,2)) What I want is first what are the elements in the data (1,2,3 here) and second what are their frequencies (1,1,2 respectively). How to use table to extract these two pieces of information? I played with table but couldn't extract the information. Please assume that we do not know how many elements in the dataframe a priori. Thanks a lot! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Insert R code in LaTeX document
Hello, i would like to insert R code in LaTeX document. I see something about the 'listings' package, but i would like if it is the best way and if it is possible to use the command \include{programme.R}. I have the following solution but it doesn't work with \include and \input == LaTex == main.tex -- \documentclass{report} \usepackage{listings} \lstloadlanguages{R} \begin{document} \include{annexe} \end{document} annexe.tex --- The code is: \lstset{language=R} #\include{} or \input or direct code ??? R code # test rm(list=ls()) x-1:10 mean(x) [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Insert R code in LaTeX document
On Sun, 2006-09-17 at 16:45 +0200, Alexandre Depire wrote: Hello, i would like to insert R code in LaTeX document. I see something about the 'listings' package, but i would like if it is the best way and if it is possible to use the command \include{programme.R}. I have the following solution but it doesn't work with \include and \input == LaTex == main.tex -- \documentclass{report} \usepackage{listings} \lstloadlanguages{R} \begin{document} \include{annexe} \end{document} annexe.tex --- The code is: \lstset{language=R} #\include{} or \input or direct code ??? R code # test rm(list=ls()) x-1:10 mean(x) Depending upon how much functionality you actually need, using the 'verbatim' environment may be easier: \begin{verbatim} R Code Here \end{verbatim} Then you don't need the rest of the LaTeX packages and associated code. The verbatim environment will use a monospace font by default. It is available by default in LaTeX, but you can also load the verbatim package (\usepackage{verbatim}) for a better implementation. The verbatim environment also provides a \verbatiminput{FileName} command that will enable you to insert a text file that will automatically be put in a verbatim environment: \verbatiminput{FileName.R} The listings package provides a lot of other functionality such as syntax highlighting, line numbers and so forth. I presume, given what you have above, that you have already looked at the manual for the package. If not and you are mimicking some online examples, then you might want to review it: ftp://indian.cse.msu.edu/pub/mirrors/CTAN/macros/latex/contrib/listings/listings-1.3.pdf In either case, if you have an external file, you don't want to use \include, as that is for .tex files specifically. The file argument is the base name of the file only, without the extension and .tex is presumed. Thus, you want to use \input, where you can specify the full FileName.R as the argument: \input{FileName.R} If you just have a small amount of R code to include, then just put it in the body of your main .tex file and you don't have to worry about multiple files or using \input, etc. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help on data frame and matrix
--- Finosaur [EMAIL PROTECTED] wrote: I am given a data frame, which actually contains a matrix. But I need to convert the data frame into a matrix so that I can use the matrix operators. Can anybody help me out? Thanks a lot. Thaleia d - as.matrix(data.frame) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Insert R code in LaTeX document
Alexandre Depire depire at gmail.com writes: Hello, i would like to insert R code in LaTeX document. I see something about the 'listings' package, but i would like if it is the best way and if it is possible to use the command \include{programme.R}. I have the following solution but it doesn't work with \include and \input Following latex code worked for me. Anupam \documentclass{report} \usepackage{listings} \begin{document} Somethings . \lstset{% general command to set parameter(s) basicstyle=\small, % print whole in small stringstyle=\ttfamily, % typewriter type for strings numbers=left, % numbers on the left numberstyle=\tiny, % Tiny numbers stepnumber=2, % number every second line of code numbersep=5pt, % 5pt seperation between numbering and code listing language=R } \lstinputlisting{text1.R} \end{document} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Building the call of an arbitrary function
Hy all, Is there a direct way to build the complete function call of an arbitrary function? Here's what I want to do. A function will build a function which will itself call a probability density function for some law given in argument to the first function: f(gamma, 1000) will return, say, function(x, shape, rate, scale = 1/rate) dgamma(x + 1000, shape, rate, scale = 1/rate) (Notice that the arguments of the output function are those of dgamma().) I tried all sorts of combinations of call(), formals(), args() et al. to no avail. But then, I avoided, so far, to build the whole thing as a character string. Would it be the only option? Thanks for any help. -- Vincent Goulet, Professeur agrégé École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Any other R users in Philadelphia?
Mitchell Maltenfort mmalten at gmail.com writes: I'm still new to R and wouldn't mind meeting other R users, at any level of experience. This list is as good a place as any. Other is an R conference. There may also be some undergrads at economics dept at UPenn. Anupam. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: R Reference Card and other help (especially useful for Newbies)
New users may also want to look at SciViews R Graphical User Interface(GUI). It can be a good learning tool. Its text based editor is basic compared to WinEdt with the R editing plug-in, or ESS and (X)Emacs combination. But it has point-and-click menus that help in writing code, and easy view of objects, etc can be very helpful for new users. Using this GUI may require you to install some R packages listed on the SciViews page. http://www.sciviews.org/SciViews-R/ Anupam. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with Variance Components (and general glmmconfusion)
With minor modifications, I got your example to work. After reading in your 'testdata', I then made 'site' and 'Array' factors: testdata$site - factor(testdata$site) testdata$Array - factor(testdata$Array) # Note: S-Plus and R are case sensitive, so 'array' and 'Array' are two different things. Then rather than using 'attach', I used the 'data' argument. It's extra book keeping, but to me seems cleaner. library(lme4) modelusd-lmer(USD~1 + (1|forest/site), testdata) MC.modelusd-mcmcsamp(modelusd, 5) modelusd2-lmer(USD~1 + (1|forest/site/Array), data=testdata) MC.modelusd2-mcmcsamp(modelusd2, 5) These all worked fine for me; see 'sessionInfo()' below. However, the second model is nonsense, because you have only one level of Array within each forest/site combination. Thus, Array is completely confounded with the residual. The variance decomposition for modelusd and modelusd2 are identical, except that the Residual Variance in the first is the sum of the Variances for Array:(site:forest) in the second. From HPDinterval, I got the following for the two: HPDinterval(MC.modelusd) lower upper (Intercept) -4.6265645 24.168019 log(sigma^2) 2.1184607 2.595467 log(st:f.(In)) 0.8987962 2.901460 log(frst.(In)) 1.7248681 6.889331 deviance 814.9391134 827.032135 attr(,Probability) [1] 0.95 HPDinterval(MC.modelusd2) lower upper (Intercept) -4.6414218 23.653071 log(sigma^2) -16.4372306 2.666573 log(A:(:.(In)) -4.6028284 2.744530 log(st:f.(In)) 0.8660924 2.987095 log(frst.(In)) 1.4793119 6.981519 deviance 814.8988318 827.634986 attr(,Probability) [1] 0.95 The intervals are similar for site and forest between the two models. However, the interval for log(sigma^2) is not terribly wide for the first but is essentially unbounded below in the second for both log(sigma^2) and log(Variance(Array)): The lower limit for sigma^2 = exp(-16.44) = 7e-8 and for var(Array) = exp(-4.6) = 0.01. Regarding intraclass correlation, it's not clear to me what definition you are using. (Dave Howell notes that there are many different definitions; www.uvm.edu/~dhowell/StatPages/More_Stuff/icc/icc.html.) Whatever definition you are using, however, there is no easy way to combine multiple intervals into one with a transformation. Before MCMC, it was common to use a first order Taylor approximation. That procedure was great when there was nothing else sensible available, but could be highly misleading if the original intervals were not symmetric or the linear approximation not very good over most of the intervals of interest. Fortunately, with MCMC, it's fairly easy. The documentation says that the output of 'mcmcsamp' is an object of class 'mcmc'. Using 'str', I find that it looks like it might be a numeric array, which is confirmed as follows: is.array(MC.modelusd) [1] TRUE Therefore, I will try to just add columns to that array as follows: MC.modelusd. - cbind(MC.modelusd, sigma2=exp(MC.modelusd[, log(sigma^2)]), site=exp(MC.modelusd[, log(st:f.(In))]), forest=exp(MC.modelusd[, log(frst.(In))] ) ) MC.modelusd.a - cbind(MC.modelusd., intraclass.site=MC.modelusd.[, site] / ( MC.modelusd.[, site]+MC.modelusd.[, sigma2]) ) When I tried 'HPDinterval(MC.modelusd.a) at this point, I got an error message. Therefore, I changed the class and tried again: class(MC.modelusd.a) - class(MC.modelusd) HPDinterval(MC.modelusd.a) lower upper (Intercept) -4.626564547 24.1680185 log(sigma^2) 2.118460743 2.5954665 log(st:f.(In))0.898796162 2.9014600 log(frst.(In))1.724868091 6.8893307 deviance814.939113359 827.0321354 sigma28.198757903 13.2489330 site 1.627992273 15.8475869 forest0.003788248 650.2006949 intraclass.site 0.173906803 0.6321633 attr(,Probability) [1] 0.95 If you follow this example, I believe you should be able to get other desired highest posterior density (HPD) intervals. Hope this helps. Spencer Graves sessionInfo() Version 2.3.1 Patched (2006-08-13 r38872) i386-pc-mingw32 attached base packages: [1] methods stats graphics grDevices utils datasets [7] base other attached packages: coda lme4 Matrixlattice 0.10-6 0.995-2 0.995-16 0.13-10 Toby Gardner wrote: snip What I am really after are the intra-class correlation coefficients so I can demonstrate the variability in a given environmental variable at different spatial scales. I can of course calculate the % variance explained for each random effect from the summary(lmer). However - and this may be a stupid question! - but can the intervals for the StDev of the random effects also just be transformed to intervals of the variance (and then converted to
[R] time series simulation
Hi everybody I'm trying to simulate a stochastic process in R. I would like consider n log normal time series. The first time serie has a growth rate lower than the second and so on. the initial time of the first serie is lower than the initial time of the second and so on. In the long run the series have the same value. Do you have any idea at running such a process? Other question: How can I reduce the domain of a random variable? Thanks March -- View this message in context: http://www.nabble.com/time-series-simulation-tf2287059.html#a6352577 Sent from the R help forum at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Building the call of an arbitrary function
Try this. We use do.call to call f with the args defined by ... except that we replace the first arg with ..1+a (where ..1 means first arg in R): F - function(f, a) function(...) do.call(match.fun(f), replace(list(...), 1, ..1 + a)) g - F(+, 1000) g(1,2) # 1003 On 9/17/06, Vincent Goulet [EMAIL PROTECTED] wrote: Hy all, Is there a direct way to build the complete function call of an arbitrary function? Here's what I want to do. A function will build a function which will itself call a probability density function for some law given in argument to the first function: f(gamma, 1000) will return, say, function(x, shape, rate, scale = 1/rate) dgamma(x + 1000, shape, rate, scale = 1/rate) (Notice that the arguments of the output function are those of dgamma().) I tried all sorts of combinations of call(), formals(), args() et al. to no avail. But then, I avoided, so far, to build the whole thing as a character string. Would it be the only option? Thanks for any help. -- Vincent Goulet, Professeur agrégé École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Standard error of coefficient in linear regression
Hello R users, I have a substantial question about statistics, not about R itself, but I would love to have an answer from an R user, in form of an example in R syntax. I have spent whole Sunday searching in Google and browsing the books. I've been really close to the answer but there are at least three standard errors you can talk about in the linear regression and I'm really confused. The question is: How exactly are standard errors of coefficients calculated in the linear regression? Here's an example from a website I've read [1]. A company wants to know if there is a relationship between its advertising expenditures and its sales volume. exped - c(4.2, 6.1, 3.9, 5.7, 7.3, 5.9) sales - c(27.1, 30.4, 25.0, 29.7, 40.1, 28.8) S - data.frame(exped, sales) summary(lm(sales ~ exped, data = S)) Call: lm(formula = sales ~ exped, data = S) Residuals: 1 2 3 4 5 6 1.7643 -1.9310 0.7688 -1.1583 3.3509 -2.7947 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 9.8725 5.2394 1.884 0.1326 exped 3.6817 0.9295 3.961 0.0167 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.637 on 4 degrees of freedom Multiple R-Squared: 0.7968, Adjusted R-squared: 0.7461 F-statistic: 15.69 on 1 and 4 DF, p-value: 0.01666 I can calculate the standard error of the estimate, according to the equation [2]... S.m - lm(sales ~ exped, data = S) S$pred - predict(S.m) S$ye - S$sales - S$pred S$ye2 - S$ye ^ 2 Se - sqrt(sum(S$ye2)/(length(S$sales) - 1 - 1)) Se [1] 2.636901 ...which matches the Residual standard error and I'm on the right track. Next step would be to use the equation [3] to calculate the standard error of the regression coefficient (here: exped). The equation [3] uses two variables, meaning of which I can't really figure out. As the calculated value Sb is scalar, all the parameters need also to be scalars. I've already calculated Se, so I'm missing x and \bar{x}. The latter could be the estimated coefficient. What is x then? Regards, Maciej [1] http://www.statpac.com/statistics-calculator/correlation-regression.htm [2] http://www.answers.com/topic/standard-error-of-the-estimate [3] http://www.answers.com/topic/standard-error-of-the-regression-coefficient -- Maciej Bliziński [EMAIL PROTECTED] http://automatthias.wordpress.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Building the call of an arbitrary function
On 9/17/2006 12:36 PM, Vincent Goulet wrote: Hy all, Is there a direct way to build the complete function call of an arbitrary function? Here's what I want to do. A function will build a function which will itself call a probability density function for some law given in argument to the first function: f(gamma, 1000) will return, say, function(x, shape, rate, scale = 1/rate) dgamma(x + 1000, shape, rate, scale = 1/rate) (Notice that the arguments of the output function are those of dgamma().) I tried all sorts of combinations of call(), formals(), args() et al. to no avail. But then, I avoided, so far, to build the whole thing as a character string. Would it be the only option? No, do.call is what you want. dgamma(x + 1000, shape, rate, scale = 1/rate) is the same as do.call(dgamma, list(x+1000, shape, rate, scale=1/rate)) But since you're going to have to look up the parameters that are appropriate to your target density (i.e. shape, rate, scale), I'm not sure how useful this will be. It might be easier just to code the call to dgamma directly. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Standard error of coefficient in linear regression
An easier way is to use summary() summary(lmfit) or summary(lmfit)$coefficients Estimate Std. Error t value Pr(|t|) (Intercept) 9.872541 5.2394254 1.884279 0.13262386 exped 3.681715 0.9294818 3.961040 0.01666313 or summary(lmfit)$coefficients[,2] (Intercept) exped 5.2394254 0.9294818 Charles Annis, P.E. [EMAIL PROTECTED] phone: 561-352-9699 eFax: 614-455-3265 http://www.StatisticalEngineering.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dimitrios Rizopoulos Sent: Sunday, September 17, 2006 3:13 PM To: Maciej Bliziński Cc: R - help Subject: Re: [R] Standard error of coefficient in linear regression these standard errors and other quantities are calculated as by products of the QR decomposition used in lm.fit(). A simple way (but not efficient) to obtain them is: exped - c(4.2, 6.1, 3.9, 5.7, 7.3, 5.9) sales - c(27.1, 30.4, 25.0, 29.7, 40.1, 28.8) S - data.frame(exped, sales) lmfit - lm(sales ~ exped, data = S) X - model.matrix(lmfit) sigma2 - sum((sales - fitted(lmfit))^2) / (nrow(X) - ncol(X)) sqrt(sigma2) sqrt(diag(solve(crossprod(X))) * sigma2) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Maciej Bliziński [EMAIL PROTECTED]: Hello R users, I have a substantial question about statistics, not about R itself, but I would love to have an answer from an R user, in form of an example in R syntax. I have spent whole Sunday searching in Google and browsing the books. I've been really close to the answer but there are at least three standard errors you can talk about in the linear regression and I'm really confused. The question is: How exactly are standard errors of coefficients calculated in the linear regression? Here's an example from a website I've read [1]. A company wants to know if there is a relationship between its advertising expenditures and its sales volume. exped - c(4.2, 6.1, 3.9, 5.7, 7.3, 5.9) sales - c(27.1, 30.4, 25.0, 29.7, 40.1, 28.8) S - data.frame(exped, sales) summary(lm(sales ~ exped, data = S)) Call: lm(formula = sales ~ exped, data = S) Residuals: 1 2 3 4 5 6 1.7643 -1.9310 0.7688 -1.1583 3.3509 -2.7947 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 9.8725 5.2394 1.884 0.1326 exped 3.6817 0.9295 3.961 0.0167 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.637 on 4 degrees of freedom Multiple R-Squared: 0.7968, Adjusted R-squared: 0.7461 F-statistic: 15.69 on 1 and 4 DF, p-value: 0.01666 I can calculate the standard error of the estimate, according to the equation [2]... S.m - lm(sales ~ exped, data = S) S$pred - predict(S.m) S$ye - S$sales - S$pred S$ye2 - S$ye ^ 2 Se - sqrt(sum(S$ye2)/(length(S$sales) - 1 - 1)) Se [1] 2.636901 ...which matches the Residual standard error and I'm on the right track. Next step would be to use the equation [3] to calculate the standard error of the regression coefficient (here: exped). The equation [3] uses two variables, meaning of which I can't really figure out. As the calculated value Sb is scalar, all the parameters need also to be scalars. I've already calculated Se, so I'm missing x and \bar{x}. The latter could be the estimated coefficient. What is x then? Regards, Maciej [1] http://www.statpac.com/statistics-calculator/correlation-regression.htm [2] http://www.answers.com/topic/standard-error-of-the-estimate [3] http://www.answers.com/topic/standard-error-of-the-regression-coefficient -- Maciej Bliziński [EMAIL PROTECTED] http://automatthias.wordpress.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained,
[R] Excluding columns from dataframe and selecting row records
Dear R-friends, I have to simple questions. First I would like to exclude some columns from a dataframe and after I need select rows that satisfy some conditions. My data frame looks like Region Species Bodysize Weigth Age Africa Sp1 10.2 20 2 Africa Sp2 12.2 12 2 Africa Sp3 15.3 18 3 Africa Sp4 11.5 40 4 Brazil Sp1 10.2 40 3 Brazil Sp2 22.2 32 2 Brazil Sp3 12.3 28 3 Brazil Sp4 21.5 30 5 And I need for example only columns Bodysize Weigth and Age when Region==Brazil AND Species==Sp2 AND Age=3 In fact my dataset is greater than this, but it is just a example. Thanks for all helps, Kind regards, Miltinho - Música para ver e ouvir: You're Beautiful, do James Blunt [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] histogram frequency weighing
Fellow R-helpers, Suppose we create a histogram as follows (although it could be any vector with zeroes in it): R lenh - hist(iris$Sepal.Length, br=seq(4, 8, 0.05)) R lenh$counts [1] 0 0 0 0 0 1 0 3 0 1 0 4 0 2 0 5 0 6 0 10 0 9 0 4 0 [26] 1 0 6 0 7 0 6 0 8 0 7 0 3 0 6 0 6 0 4 0 9 0 7 0 5 [51] 0 2 0 8 0 3 0 4 0 1 0 1 0 3 0 1 0 1 0 0 0 1 0 4 0 [76] 0 0 1 0 0 and we wanted to apply a weighing scheme where frequencies immediately following (and only those) empty class intervals (0) should be adjusted by averaging them over the number of preceding empty intervals + 1. For example, the first frequency that would need to be adjusted in 'lenh' is element 6 (1), which has 5 preceding empty intervals, so its adjusted count would be 1/6. Similarly, the second one would be element 8 (3), which has 1 preceding empty interval, so its adjusted count would be 3/2. Can somebody please provide a hint to implement such a weighing scheme? I thought about some very contrived ways to accomplish this, involving 'which' and 'diff', but I sense a function might already be available to do this efficiently. I couldn't find relevant info in the usual channels. Thanks in advance for any pointers. Cheers, -- Seb __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Excluding columns from dataframe and selecting row records
Miltinho, On Sun, Sep 17, 2006 at 05:08:29PM -0300, Milton Cezar wrote: Dear R-friends, I have to simple questions. First I would like to exclude some columns from a dataframe and after I need select rows that satisfy some conditions. My data frame looks like Region Species Bodysize Weigth Age Africa Sp1 10.2 20 2 Africa Sp2 12.2 12 2 Africa Sp3 15.3 18 3 Africa Sp4 11.5 40 4 Brazil Sp1 10.2 40 3 Brazil Sp2 22.2 32 2 Brazil Sp3 12.3 28 3 Brazil Sp4 21.5 30 5 And I need for example only columns Bodysize Weigth and Age when Region==Brazil AND Species==Sp2 AND Age=3 The subset command should suit your needs: subset(dataframe, Region==Brazil Species==Sp2 Age=3,select = c(Bodysize,Weigth,Age)) See help(subset) for more info. Regards, Logan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] currency or stock trading strategy
Hi, are there any good charting and analysis tools for use with currencies, stocks, etc. in R? I have some tools to download currency data from the NYFRB using python and XML. Can we get and parse an XML download using R? Can we have interaction in R plots? Does anyone use R for back-testing trading strategies? Are there any forums for discussion of using R for this specific purpose (apart from this general list)? Is anyone aware of any general open-source developments for these purposes (I don't see any from GNU or google searches)? Take care, Darren __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Thousand separator in format of axis
Hi: How can i make that the numbers in the tick annotations of an axis be written as, say 20 000 and not 2 (i.e. with the little gap seprating thousands)? Thanks Ruben __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] histogram frequency weighing
I think this should do it: lenh - hist(iris$Sepal.Length, br=seq(4, 8, 0.05))$counts lenh # original data [1] 0 0 0 0 0 1 0 3 0 1 0 4 0 2 0 5 0 6 0 10 0 9 0 4 0 1 0 6 0 7 0 6 0 [34] 8 0 7 0 3 0 6 0 6 0 4 0 9 0 7 0 5 0 2 0 8 0 3 0 4 0 1 0 1 0 3 0 1 [67] 0 1 0 0 0 1 0 4 0 0 0 1 0 0 l.rle - rle(lenh) # determine where '0's are Zero - which(l.rle$values == 0) # if last entry in rle was 0, delete from offsets since we are changing +1 if (tail(l.rle$values,1) == 0) Zero - Zero[-length(Zero)] l.offsets - cumsum(l.rle$lengths) # offsets into original vector# modify original input lenh[l.offsets[Zero+1]] - lenh[l.offsets[Zero + 1]] / (l.rle$lengths[Zero]+1) lenh # modified data [1] 0.000 0.000 0.000 0.000 0.000 0.167 0.000 1.500 0.000 0.500 [11] 0.000 2.000 0.000 1.000 0.000 2.500 0.000 3.000 0.000 5.000 [21] 0.000 4.500 0.000 2.000 0.000 0.500 0.000 3.000 0.000 3.500 [31] 0.000 3.000 0.000 4.000 0.000 3.500 0.000 1.500 0.000 3.000 [41] 0.000 3.000 0.000 2.000 0.000 4.500 0.000 3.500 0.000 2.500 [51] 0.000 1.000 0.000 4.000 0.000 1.500 0.000 2.000 0.000 0.500 [61] 0.000 0.500 0.000 1.500 0.000 0.500 0.000 0.500 0.000 0.000 [71] 0.000 0.250 0.000 2.000 0.000 0.000 0.000 0.250 0.000 0.000 On 9/17/06, Sebastian P. Luque [EMAIL PROTECTED] wrote: Fellow R-helpers, Suppose we create a histogram as follows (although it could be any vector with zeroes in it): R lenh - hist(iris$Sepal.Length, br=seq(4, 8, 0.05)) R lenh$counts [1] 0 0 0 0 0 1 0 3 0 1 0 4 0 2 0 5 0 6 0 10 0 9 0 4 0 [26] 1 0 6 0 7 0 6 0 8 0 7 0 3 0 6 0 6 0 4 0 9 0 7 0 5 [51] 0 2 0 8 0 3 0 4 0 1 0 1 0 3 0 1 0 1 0 0 0 1 0 4 0 [76] 0 0 1 0 0 and we wanted to apply a weighing scheme where frequencies immediately following (and only those) empty class intervals (0) should be adjusted by averaging them over the number of preceding empty intervals + 1. For example, the first frequency that would need to be adjusted in 'lenh' is element 6 (1), which has 5 preceding empty intervals, so its adjusted count would be 1/6. Similarly, the second one would be element 8 (3), which has 1 preceding empty interval, so its adjusted count would be 3/2. Can somebody please provide a hint to implement such a weighing scheme? I thought about some very contrived ways to accomplish this, involving 'which' and 'diff', but I sense a function might already be available to do this efficiently. I couldn't find relevant info in the usual channels. Thanks in advance for any pointers. Cheers, -- Seb __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Thousand separator in format of axis
format(1, big.mark= ) [1] 10 000 format(seq(1,10,1), big.mark= , scientific=FALSE) [1] 10 000 20 000 30 000 40 000 50 000 60 000 70 000 [8] 80 000 90 000 100 000 plot(seq(1, 10, 1), yaxt=n) axis(2, at=seq(1, 10, 1), labels=format(seq(1,10,1), + big.mark= , scientific=FALSE)) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Thousand separator in format of axis
On Sun, 2006-09-17 at 17:47 -0400, Ruben Roa Ureta wrote: Hi: How can i make that the numbers in the tick annotations of an axis be written as, say 20 000 and not 2 (i.e. with the little gap seprating thousands)? Thanks Ruben There are several ways to format numbers: ?format ?sprintf ?formatC A quick example: y - seq(0, 10, 1) # Set the y axis so that it does not get drawn # See ?par plot(1:11, y, yaxt = n, ylab = ) # Use formatC() and set 'big.mark' to # See ?axis also axis(2, at = y, labels = formatC(y, big.mark = , format = d), las = 2) HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] histogram frequency weighing
On Sun, 17 Sep 2006 15:12:30 -0500, Sebastian P. Luque [EMAIL PROTECTED] wrote: [...] I thought about some very contrived ways to accomplish this, involving 'which' and 'diff', but I sense a function might already be available to do this efficiently. I think I found a better combination of those two functions than I what I was initially playing with: R lenh - hist(iris$Sepal.Length, br=seq(4, 8, 0.05)) R ok - which(lenh$counts 0) R lenh$counts[ok] - lenh$counts[ok] / diff(c(0, ok)) R lenh$counts [1] 0. 0. 0. 0. 0. 0.1667 0. 1.5000 0. 0.5000 [11] 0. 2. 0. 1. 0. 2.5000 0. 3. 0. 5. [21] 0. 4.5000 0. 2. 0. 0.5000 0. 3. 0. 3.5000 [31] 0. 3. 0. 4. 0. 3.5000 0. 1.5000 0. 3. [41] 0. 3. 0. 2. 0. 4.5000 0. 3.5000 0. 2.5000 [51] 0. 1. 0. 4. 0. 1.5000 0. 2. 0. 0.5000 [61] 0. 0.5000 0. 1.5000 0. 0.5000 0. 0.5000 0. 0. [71] 0. 0.2500 0. 2. 0. 0. 0. 0.2500 0. 0. It makes sense, although I'm a bit nervous about floating-point issues that might make this fail in some cases. Any suggestions/comments welcome. -- Seb __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] histogram frequency weighing
On Sun, 17 Sep 2006 18:05:15 -0400, jim holtman [EMAIL PROTECTED] wrote: I think this should do it: [...] Thank you Jim, the idea with 'rle' is great. I missed your follow-up before mine a minute ago with another solution. I'll do some testing with both. Cheers, -- Seb __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] merge gives me too many rows
Hi, I am using merge to add some variables to an existing dataframe. I use the option all.x=F so that my final dataframe will only have as many rows as the first file I name in the call to merge. With a large dataframe using a lot of by variables, the number of rows of the merged dataframe increases from 177325 to 179690: dim(test) [1] 177325 9 test2 - merge(test, fish, by=c(predateu, origin, navire, nbpc, no_rel, trait, tagno), all.x=F) dim(test2) [1] 179690 11 I tried to make a smaller dataset with R commands that I could post here so that other people could reproduce, but merge behaved as expected: final number of rows was the same as the number of rows in the first file named in the call to merge. I took a subset of my large dataframe and could mail this to anyone interested in verifying the problem. test3 - test[11:16,] dim(test3) [1] 6 9 test4 - merge(test3, fish, by=c(predateu, origin, navire, nbpc, no_rel, trait, tagno), all.x=F) dim(test4) [1] 6004311 I compared test3 and test4 line by line. The first 11419 lines were the same (except for added variables, obviously) in both dataframes, but then lines 11420 to 11423 were repeated in test4. Then no problem for a lot of rows, until rows 45756-45760 in test3. These are offset by 4 in test4 because of the first group of extraneous lines just reported, and are found on lines 45760 to 45765. But they are also repeated on lines 45765 to 45769. And so on a few more times. Thus merge added lines (repeated a small number of lines) to the final dataframe despite my use of all.x=F. Am I doing something wrong? If not, is there a solution? Not being able to merge is a setback! I was attempting to move the last few things I was doing with SAS to R... Please let me know if you want the file test3 (2.3 MB as a csv file, but only 352 KB in R (.rda) format). Sincerely, Denis Chabot R.Version() $platform [1] powerpc-apple-darwin8.6.0 $arch [1] powerpc $os [1] darwin8.6.0 $system [1] powerpc, darwin8.6.0 $status [1] $major [1] 2 $minor [1] 3.1 $year [1] 2006 $month [1] 06 $day [1] 01 $`svn rev` [1] 38247 $language [1] R $version.string [1] Version 2.3.1 (2006-06-01) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] merge strings
Hi all, I have a vector and want to merge its elements one by one into a single string or number. For example, x=c(1,2,3), what I want is a new number 123. I used paste but it just output 1 2 3 which is not what I want. Is there any way to do this? Thanks! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merge strings
Bingshan Li wrote: Hi all, I have a vector and want to merge its elements one by one into a single string or number. For example, x=c(1,2,3), what I want is a new number 123. I used paste but it just output 1 2 3 which is not what I want. Is there any way to do this? Thanks! Use the collapse argument to paste: paste(x, collapse=) Or, if you want a number, sum(x * 10^rev(1:length(x) - 1)) Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merge strings
Hi Duncan Murdoch, Thanks for the trick and it works! --- Duncan Murdoch [EMAIL PROTECTED] wrote: Bingshan Li wrote: Hi all, I have a vector and want to merge its elements one by one into a single string or number. For example, x=c(1,2,3), what I want is a new number 123. I used paste but it just output 1 2 3 which is not what I want. Is there any way to do this? Thanks! Use the collapse argument to paste: paste(x, collapse=) Or, if you want a number, sum(x * 10^rev(1:length(x) - 1)) Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] 404 HTTP not found
Hi I wrote a script which retrieves links from websites and loads them with scan: ... website-tolower(scan(current.pages[i], what=character, sep=\n, quiet=TRUE)) ... However occasionally, the script finds broken links, such as http://www.google.com/test. when the script tries to access such websites, the repeat loop breaks and I get the error message Error in file(file, r) : unable to open connection In addition: Warning message: cannot open: HTTP status was '404 Not Found' Now my question: is there a way to test whether the target of a link exists that does not result in an error and, thus, discontinues my loop? I looked at the help files for files, scans, connections, and did a search for 404?' in th archives but couldn't find anything. I work with R 2.3.1 patched on Windows XP (both Home and Prof) and would appreciate any pointers ... Thanks a lot, STG __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 404 HTTP not found
See ?try as in this example: current.pages - c(http://www.google.com;, http://www.google.com/test;, http://www.yahoo.com;) for(i in seq(along = current.pages)) { website - try(tolower(scan(current.pages[i], what=character, sep=\n, quiet=TRUE))) if (inherits(website, try-error)) cat(current.pages[i], bad\n) else cat(current.pages[i], ok\n) } On 9/18/06, Stefan Th. Gries [EMAIL PROTECTED] wrote: Hi I wrote a script which retrieves links from websites and loads them with scan: ... website-tolower(scan(current.pages[i], what=character, sep=\n, quiet=TRUE)) ... However occasionally, the script finds broken links, such as http://www.google.com/test. when the script tries to access such websites, the repeat loop breaks and I get the error message Error in file(file, r) : unable to open connection In addition: Warning message: cannot open: HTTP status was '404 Not Found' Now my question: is there a way to test whether the target of a link exists that does not result in an error and, thus, discontinues my loop? I looked at the help files for files, scans, connections, and did a search for 404?' in th archives but couldn't find anything. I work with R 2.3.1 patched on Windows XP (both Home and Prof) and would appreciate any pointers ... Thanks a lot, STG __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merge gives me too many rows
I think you may misunderstand the meaning of all.x = FALSE. Setting all.x to false ensures that only rows of x that have matches in y will be included. Equivalently, if a row of x is not matched in y, it will not be in the output. However, if a row in x is matched by more than one row in y, then that row will be repeated as many times as there are matching rows in y. That is, you have a 1 to many match (1 in x to many in y). SAS behaves the same way. Are you sure this is not what is happening? Also, all.x = FALSE is the default; it is not necessary to specify it. In fact, the default is to output only rows that are found in both x and y (matching on the specified variables, of course). -Don At 9:11 PM -0400 9/17/06, Denis Chabot wrote: Hi, I am using merge to add some variables to an existing dataframe. I use the option all.x=F so that my final dataframe will only have as many rows as the first file I name in the call to merge. With a large dataframe using a lot of by variables, the number of rows of the merged dataframe increases from 177325 to 179690: dim(test) [1] 177325 9 test2 - merge(test, fish, by=c(predateu, origin, navire, nbpc, no_rel, trait, tagno), all.x=F) dim(test2) [1] 179690 11 I tried to make a smaller dataset with R commands that I could post here so that other people could reproduce, but merge behaved as expected: final number of rows was the same as the number of rows in the first file named in the call to merge. I took a subset of my large dataframe and could mail this to anyone interested in verifying the problem. test3 - test[11:16,] dim(test3) [1] 6 9 test4 - merge(test3, fish, by=c(predateu, origin, navire, nbpc, no_rel, trait, tagno), all.x=F) dim(test4) [1] 6004311 I compared test3 and test4 line by line. The first 11419 lines were the same (except for added variables, obviously) in both dataframes, but then lines 11420 to 11423 were repeated in test4. Then no problem for a lot of rows, until rows 45756-45760 in test3. These are offset by 4 in test4 because of the first group of extraneous lines just reported, and are found on lines 45760 to 45765. But they are also repeated on lines 45765 to 45769. And so on a few more times. Thus merge added lines (repeated a small number of lines) to the final dataframe despite my use of all.x=F. Am I doing something wrong? If not, is there a solution? Not being able to merge is a setback! I was attempting to move the last few things I was doing with SAS to R... Please let me know if you want the file test3 (2.3 MB as a csv file, but only 352 KB in R (.rda) format). Sincerely, Denis Chabot R.Version() $platform [1] powerpc-apple-darwin8.6.0 $arch [1] powerpc $os [1] darwin8.6.0 $system [1] powerpc, darwin8.6.0 $status [1] $major [1] 2 $minor [1] 3.1 $year [1] 2006 $month [1] 06 $day [1] 01 $`svn rev` [1] 38247 $language [1] R $version.string [1] Version 2.3.1 (2006-06-01) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- - Don MacQueen Lawrence Livermore National Laboratory Livermore, CA, USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.