Re: [R] Importing CSV File
Hi r-help-boun...@r-project.org napsal dne 25.10.2010 00:47:22: sales - read.csv(file=C:/Program Files/R/Test Data/sales.csv, header=TRUE, row.names = Month) ^^^ -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jason Kwok Sent: Monday, 25 October 2010 8:27 AM To: Erik Iverson Cc: r-help@r-project.org Subject: Re: [R] Importing CSV File Thanks for the response Erik. In this case, I would like to keep the row name as the month. How would I do that? Following Bill's answer I would add that you can not have duplicated row names. In your example it does not matter as each month is unique, but if you have more occurrences of some months you can not use it as a row name. Regards Petr Thanks, Jason On Sun, Oct 24, 2010 at 6:20 PM, Erik Iverson er...@ccbr.umn.edu wrote: On 10/24/2010 04:57 PM, Jason Kwok wrote: I'm trying to import a CSV file into R and when it gets imported, the entries get numbered down the left side. How do I get rid of that? When you imported the CSV file into R, an object of class data.frame was created, and since you did not assign it to a variable name, (e.g., df1 - read.csv(...) ), the object got printed. A data.frame object is going to have a row.names attribute by definition, which is what you're seeing. In ?data.frame, we see documentation for the row.names argument: If 'row.names' was supplied as 'NULL' or no suitable component was found the row names are the integer sequence starting at one (and such row names are considered to be 'automatic', and not preserved by 'as.matrix'). The method that prints out a data.frame is called print.data.frame, and it does have an argument to suppress printing of the row.names. The question is, why do you not want row.names? Are they just distracting you when printed, or is there some reason not to carry them along in the object? --Erik Thanks, Jason * read.csv(file=C:\\Program Files\\R\\Test Data\\sales.csv,head=TRUE) Month Sales 1January 422 2 February 151 3 March 451 4 April 175 5May 131 6 June 307 7 July47 8 August12 9 September 488 10 October 122 11 November54 12 December 244 * [[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-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] Random Integer Number in Uniform Distribution
Is there a way to do it? At best what I can achieve is non integer: runif(10, min=1, max=100) [1] 51.959151 56.654146 63.630251 3.172794 4.073018 11.977437 86.601869 [8] 75.788618 11.734361 6.770962 -G.V. __ 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] Random Integer Number in Uniform Distribution
Check ?sample. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Gundala Viswanath Sent: maandag 25 oktober 2010 8:38 To: r-h...@stat.math.ethz.ch Subject: [R] Random Integer Number in Uniform Distribution Is there a way to do it? At best what I can achieve is non integer: runif(10, min=1, max=100) [1] 51.959151 56.654146 63.630251 3.172794 4.073018 11.977437 86.601869 [8] 75.788618 11.734361 6.770962 -G.V. __ 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-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] structural equation modeling in sem, error, The model has negative degrees of freedom = -3, and The model is almost surely misspecified...
Hi all, I am attempting to learn my way through the sem package by constructing a simple structural model for some of my data on bird diversity, abundance, and primary productivity. I have constructed a covariance matrix between these variables as per the following: S_matrix = matrix(c( + 0.003083259, 0, 0, + 0.143870284, 89.7648490, 0, + 0.276950919, 81.3484101, 215.3570157 ), ncol = 3, byrow = T) rownames(S_matrix) = colnames(S_matrix) = c(dec_mean_EVI, density, ALL_Jack1) I then construct a model using a symbolic ram specification as follows tmodel - specify.model() dec_mean_EVI - density, gam1, NA density - ALL_Jack1, gam2, NA dec_mean_EVI - ALL_Jack1, gam3, NA dec_mean_EVI - dec_mean_EVI, ps1, NA density - density, ps2, NA ALL_Jack1 - ALL_Jack1, theta1, NA dec_mean_EVI - density, theta2, NA dec_mean_EVI - ALL_Jack1, theta2, NA density - ALL_Jack1, theta3, NA I then try to run the sem analysis using the matrix and model. sem_1 - sem(ram = tmodel, S = S_matrix, N = 88, fixed.x = c(dec_mean_EVI)) summary(sem_1) However, I only get the following error message: Error in sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : The model has negative degrees of freedom = -3 In addition: Warning message: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : The following variables have no variance or error-variance parameter (double-headed arrow): density, ALL_Jack1, dec_mean_EVI, density, density, ALL_Jack1 The model is almost surely misspecified; check also for missing covariances. It must be obvious to those experienced with sem, but I can't yet see where I have gone wrong in constructing my matrix or model, any thoughts would be much appreciated. thanks in advance, Alex __ 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] if statement and truncated distribution
Hi R helpers, I am trying to use the if statement to generate a truncated random variable as follows: if (y[i]==0) { v[i] ~ rnorm(1,0,1) | (-inf ,0) } if (y[i]==1) { v[i] ~ rnorm(1,0,1) | (0, inf) } I guess I cannot use | ( , ) to restrict the range of a variable in R. Could you let me know how to write the code correctly in R? Many thanks for your help. Maomao [[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] if statement and truncated distribution
What I guess you want is something like (this is for zero-truncation): rZeroTruncNormal1d-function(mu, sig, invalidSign) #sig holds standard deviation! { val-rnorm(1, mu, sig) while(val * invalidSign 0) { val-rnorm(1, mu, sig) } return(val) } Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sally Luo Sent: maandag 25 oktober 2010 2:01 To: r-help@r-project.org Subject: [R] if statement and truncated distribution Hi R helpers, I am trying to use the if statement to generate a truncated random variable as follows: if (y[i]==0) { v[i] ~ rnorm(1,0,1) | (-inf ,0) } if (y[i]==1) { v[i] ~ rnorm(1,0,1) | (0, inf) } I guess I cannot use | ( , ) to restrict the range of a variable in R. Could you let me know how to write the code correctly in R? Many thanks for your help. Maomao [[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-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] .R file
Hello everyone Can you please teach me how to save my homework as .R file? I write my code in RGui. When I tried to save my work, the RGui only allows me to save it as .RData. By the way, after I save my work as .RData, I cannot reopen it. when I open it, only one message comes out as following: ARGUMENT_ignored_. -- View this message in context: http://r.789695.n4.nabble.com/R-file-tp3009812p3009812.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Using tapply?
Dear R helpers, I am trying to calculate the Annualized Percent Rate using following R - Code. # ## R Code library(animation) # INPUT C = 25 # Loan Amount E = 2500 # Other Cost R = 6 # Interest rate r = R/1200 # Monthly interest rate q = 12 # No of Compoundings n = 20 # No of years # # COMPUTATIONS N = n * q # No of months P = ((C + E)*r*(1+r)^N) / ((1+r)^N - 1) # Monthly Payments ani.options(nmax = 500) solu = newton.method(function(a) C * (a*(1+a)^N) - P * ((1+a)^N - 1), 1, c(R - 0.25*R, R + 0.25*R)) solu$root APR = ((1+solu$root)^q-1)*100 # _ ## RESULTS P = 1808.988, APR = 6.298708 These are the values I obtain. # ## PROBLEM This R code holds or yields results if I am dealing with only one value for each of the input. However, if there are more than one input values, how do I proceed? Say, E.g. C = c(25, 40) E = c(2500, 5000) R = c(6, 6) q = c(12, 12) n = c(20, 20) So using above code, I am able to obtain the values of P as 1808.988 and 2901.546 respectively. However, using this code I am not able to obtain solu as defined above. I tried using the tapply instead but seems its not working. Please guide as to how do I use tapply here. Regards and thanking in advance Amy [[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 with make distribution
Dear R People: I'm trying to experiment with the make distribution with R-2.12.0 when compiling from source on Windows. It works fine on Windows XP, but I'm having a snag with Windows 7. Here is the snag: cp -prf ../../../Tcl R-2.12.0 cp: preserving permissions for `R-2.12.0/Tcl/bin': Invalid argument cp: preserving permissions for `R-2.12.0/Tcl/doc': Invalid argument and so on. Has anyone run into this, please? Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Contour Plot on a non Rectangular Grid
On 10/25/2010 03:30 AM, Lorenzo Isella wrote: Hello, I feel I am drowning in a glass of water. Consider the following snippet at the end of the email, where I generated a set of {x,y,s=f(x,y)} values, i.e. a set of 2D coordinates + a scalar on a circle. Now, I can get a scatterplot in 3D, but how to get a 2D surface plot/levelplot? An idea could be to artificially set the z coordinate of the plot as a constant (instead of having it equal to s as in the scatterplot) and calculate the colormap with the values of s, along the lines of the volcano example + surface plot at http://bit.ly/9MRncd but I am experiencing problems. However, should I really go through all this? There is nothing truly 3D in the plot that I have in mind, you can think of it as e.g. some temperature measurement along a tube cross section. Hi Lorenzo, I'm a bit pressed for time at the moment so I can't write an example, but why not just define an empty rectangular plot: plot(0,xlim=your xlimits,ylim=your ylimits,type=n,axes=FALSE, xlab=,ylab=) create a matrix of NA values, only calculate the ones that are inside your shape and display it in the same way that color2D.matplot(plotrix) does? You should get the shape you want with all of the unwanted cells blank. Jim __ 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] .R file
There is most of what you need here: http://www.statmethods.net/interface/workspace.html Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Mon, Oct 25, 2010 at 8:57 AM, zhiji19 zhij...@gmail.com wrote: Hello everyone Can you please teach me how to save my homework as .R file? I write my code in RGui. When I tried to save my work, the RGui only allows me to save it as .RData. By the way, after I save my work as .RData, I cannot reopen it. when I open it, only one message comes out as following: ARGUMENT_ignored_. -- View this message in context: http://r.789695.n4.nabble.com/R-file-tp3009812p3009812.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] font.lab and font.axis
Hi all, In the course of ongoing improvement of plotrix, I was alerted to the fact that setting, e.g.: par(font.lab=3, font.axis=3) only seems to work for plot (and maybe other functions), but not for axis. par(font=3) works for everything (except the title, which is probably specified separately), but there are probably situations in which someone doesn't want to change all of the text on the plot. Would someone like to suggest a better way to get axis to look at the font it's supposed to be using? Thanks. Jim __ 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] Error: could not find function lmList
Dear colleges, I would like to use the lmList function. I have installed the lme4 library but when I try to use the lmList function I get this error message. Error: could not find function lmList Here you can see what kind of messages I am getting when installing lme4 package. Does anyone know how to solve this problem? Thanks Rosario install.packages() --- Please select a CRAN mirror for use in this session --- Warning: dependency 'Matrix' is not available trying URL 'http://ftp.sunet.se/pub/lang/CRAN/bin/windows/contrib/2.9/lme4_0.999375-32.zip' Content type 'application/zip' length 992275 bytes (969 Kb) opened URL downloaded 969 Kb package 'lme4' successfully unpacked and MD5 sums checked The downloaded packages are in C:\Documents and Settings\mroga\Local Settings\Temp\RtmpuExQmQ\downloaded_packages updating HTML package descriptions ?lmList No documentation for 'lmList' in specified packages and libraries: you could try '??lmList' library(lme4) Error: package 'Matrix' 0.999375-30 was found, but = 0.999375.31 is required by 'lme4' In addition: Warning message: package 'lme4' was built under R version 2.9.2 __ 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] Error: could not find function lmList
Hi, You need to update your packages (and maybe upgrade R at the same time). See the FAQ for Windows 2.8 to know how to do it correctly. Ivan Le 10/25/2010 10:14, Rosario Garcia Gil a écrit : Dear colleges, I would like to use the lmList function. I have installed the lme4 library but when I try to use the lmList function I get this error message. Error: could not find function lmList Here you can see what kind of messages I am getting when installing lme4 package. Does anyone know how to solve this problem? Thanks Rosario install.packages() --- Please select a CRAN mirror for use in this session --- Warning: dependency 'Matrix' is not available trying URL 'http://ftp.sunet.se/pub/lang/CRAN/bin/windows/contrib/2.9/lme4_0.999375-32.zip' Content type 'application/zip' length 992275 bytes (969 Kb) opened URL downloaded 969 Kb package 'lme4' successfully unpacked and MD5 sums checked The downloaded packages are in C:\Documents and Settings\mroga\Local Settings\Temp\RtmpuExQmQ\downloaded_packages updating HTML package descriptions ?lmList No documentation for 'lmList' in specified packages and libraries: you could try '??lmList' library(lme4) Error: package 'Matrix' 0.999375-30 was found, but= 0.999375.31 is required by 'lme4' In addition: Warning message: package 'lme4' was built under R version 2.9.2 __ 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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php __ 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] Controlling number of numbers before R rewrites to +e18 etc
Thanks Jim, but I still got the problem that the pre-processing becomes way too computationally expensive. R seems to handle characters and factors much much worse than numeric IDs. I don't have enough RAM to even write the file when they are viewed as chars instead of numeric values! Anyone have any other ideas? Is it not possible to tell R not to rewrite upon import? It wouldn't matter if it only would write the correct IDs to the exported csv file, but it exports the abbreviated version which is of no use. Mike On Sat, Oct 23, 2010 at 3:56 AM, jim holtman jholt...@gmail.com wrote: Your best bet is to make sure that you read the IDs in as characters. If they are being read in as floating point numbers, then there is only 15 digits of accuracy, so if you have IDs 18-22 digits, you will be missing data. So if you are using read.table, then look at colClasses to see how to do this. Provide a subset of your data and the statements that you are using to read in the data. On Fri, Oct 22, 2010 at 1:15 PM, ZeMajik zema...@gmail.com wrote: Hey, I'm using R as a pre-processor for a large dataset with IDs which are numeric (but has no numeric meaning so can be seen as factors). I do some data formating and then write it out to a csv file. However the problem is that the IDs are very long, 18-22 chars long more precisely. R is constantly rewriting these IDs to the abbreviated +eX which hinders me from exporting the data to the csv since the IDs are no longer intact. I've tried telling R that ID column is a factor, but this results in two problems: 1) Since I have millions of rows and R is slower handling factors than numbers my comp can't run the process in any kind of reasonable time. and 2) Some IDs STILL seem to be rewritten somehow. The second point made me believe that perhaps R is rewriting upon import? Does anyone have any tips on how to solve this problem? Thanks, Mike [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] re-vertical conversion of data entries
It is just that the vertical (column) vector is represented that way in R. If you want to dsiplay it in a column, just generate a matrix, for simplicity: matrix(x, ncol=1) Uwe Ligges On 25.10.2010 05:45, Penny Adversario wrote: Dear R user, Can you please help me. How do I convert part of a cluster analysis output under the heading “Clustering vector� as shown below, showing the clusters to which each respondent belongs to:    [1] 1 1 2 2 1 2 1 2 1 1 2 2 1 2 2 2 2 1 1 1 1 2 2 1 2 2 1 2 2 2 2 2 2 2 2 1 2  [38] 2 1 1 2 2 2 2 2 1 2 1 2 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 1 2 1 2 2 2 1 1 2 2  [75] 2 1 2 2 2 2 2 2 2 1 1 2 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 2 2 1 2 2 2 1 2 2 . . . [8696] 2 1 1 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 2 2 2 2 2 2 2 1 2 2 2 [8733] 2 2 1 1 2 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 1 1  to a single vertical column? Thanks.  I used the following code to arrive at the above output: pam(dm,2,diss=TRUE, medoids=NULL, cluster.only=FALSE,do.swap=TRUE, keep.data=FALSE, trace.lev=0)  Penny [[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-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] font.lab and font.axis
2010/10/25 Jim Lemon j...@bitwrit.com.au Would someone like to suggest a better way to get axis to look at the font it's supposed to be using? Are you looking for something like this? x-rnorm(100) hist(x,axes=F,font.lab=12,font.main=9) axis(1,font.axis=4) axis(2,font.axis=3) -- Mi³ego dnia [[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] RODBC: data base with decimal point ,
Hello Marc, thanks very much for your answer! I had tried setting options(dec) before doing anything else, but that didn't solve the problem. Reading section Internationalization Issues didn't make me much wiser, so I'll search the archives of the e-mail list you mentioned, maybe I find something there. Best wishes, Heinrich. -Ursprüngliche Nachricht- Von: Marc Schwartz [mailto:marc_schwa...@me.com] Gesendet: Freitag, 22. Oktober 2010 14:53 An: RINNER Heinrich Cc: r-h...@stat.math.ethz.ch Betreff: Re: [R] RODBC: data base with decimal point , On Oct 22, 2010, at 1:53 AM, RINNER Heinrich wrote: Dear R-users, I am working with R version 2.10.1 and package RODBC Version: 1.3-2 under windows. Say I have a table testtable (in an Access data base) with 3 columns and 1 row that looks like this: X Y Z 0012345 42 42,1 The columns are of these types: X - character, Y - Long Integer, Z - Decimal. I use RODBC to get these data into R: library(RODBC) channel - odbcConnectAccess(C:\\temp\\testdb.mdb) x - sqlFetch(channel, testtable, as.is = TRUE) # need as.is so that X won't be converted to numeric summary(x) X Y Z Length:1 Min. :42 Length:1 Class :character 1st Qu.:42 Class :character Mode :character Median :42 Mode :character Mean :42 3rd Qu.:42 Max. :42 So the problem seems to be the decimal point, as I am on an Austrian locale: Sys.getlocale() [1] LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;L C_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Aus tria.1252 I tried options(dec) $dec decimal_point . options(dec = ,) , but that doesn't change anything. How can I tell RODBC that the decimal point in my data base is ,? Your advice would be appreciated; kind regards Heinrich. Heinrich, Check Section 6 Internationalization Issues in: vignette(RODBC) for guidance on dealing with decimal point character issues. The potential issue with options(dec) is that it needs to be set before RODBC is loaded. So if you changed if after using require(RODBC) or library(RODBC), it will be ineffectual. There are also other system locale related settings and the settings in the ODBC driver and perhaps Access itself, referenced in the above. Also, as an FYI, there is an e-mail list focused on R and database issues. More info at: https://stat.ethz.ch/mailman/listinfo/r-sig-db HTH, Marc Schwartz __ 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] Unable to allocate arrays of size 2GB in 64 bit Windows 7 R
Do you use a 64-bit version of R? I suspect you are using a 32-bit build. The R-2.12.0 installer comes with binaries for both architectures. Uwe Ligges On 25.10.2010 04:25, Bhattacharyya, Siddhartha wrote: I seem Unable to allocate arrays of size around 2GB in 64 bit Windows 7 R. There is a lot of main memory available. The memory.limit is set to the max memory available, and there is more than 10GB of that available when R returns an 'unable to allocate memory' error. Is this a limitation of R even in 64 bit Windows 7? Or is there a wY to get I've this? Thanks. __ 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-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] plot does not work
Hello everyone The following two commands plot.default(seq(1,5),seq(2,6)) plot(seq(1,5),seq(2,6)) plot nothing. One day ago this would create a simple plot diagram but unfortunately right now no plot appears. ?plot returns Help on topic 'plot' was found in the following packages: Plot a Raster* object (in package raster in library /home/apa/R/x86_64-unknown-linux-gnu-library/2.11) Generic X-Y Plotting (in package graphics in library /usr/lib64/R/library) What do you think I should blame for that? Best Regards Alex [[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 does not work
You are probably plotting into a pdf device (the default if no X11 available). Uwe Ligges On 25.10.2010 11:44, Alaios wrote: Hello everyone The following two commands plot.default(seq(1,5),seq(2,6)) plot(seq(1,5),seq(2,6)) plot nothing. One day ago this would create a simple plot diagram but unfortunately right now no plot appears. ?plot returns Help on topic 'plot' was found in the following packages: Plot a Raster* object (in package raster in library /home/apa/R/x86_64-unknown-linux-gnu-library/2.11) Generic X-Y Plotting (in package graphics in library /usr/lib64/R/library) What do you think I should blame for that? Best Regards Alex [[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-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] problem with make distribution
On Mon, 25 Oct 2010, Erin Hodgess wrote: Dear R People: I'm trying to experiment with the make distribution with R-2.12.0 when compiling from source on Windows. It works fine on Windows XP, but I'm having a snag with Windows 7. Here is the snag: cp -prf ../../../Tcl R-2.12.0 cp: preserving permissions for `R-2.12.0/Tcl/bin': Invalid argument cp: preserving permissions for `R-2.12.0/Tcl/doc': Invalid argument and so on. Has anyone run into this, please? Yes. This is an issue with how you unpacked the Tcl directory. Without knowing how you did that, you will need either to - Use Windows Explorer to correct the ownership/permissions of Tcl and those subdirectories -- sometimes simply renaming it and making a copy called 'Tcl' is the easiest way forward. - Remove it and unpack it some other way, e.g. via the zip file available at http://www.stats.ox.ac.uk/pub/Rtools/ Cygwin and Windows 7/Vista do sometimes fight over permissions (and this is using cp from Cygwin): I've seen this more often with the Cygwin update in the current Rtools212 than in earlier versions. Thanks for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk 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@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] Interpolate irregular time series
On Fri, 2010-10-22 at 12:50 +, Salim Alexander (salimale) wrote: Hi all, Issue: I have two datasets, one is a regular time series (rain gauge) with resolution of 10 minutes. The other one is an irregular time series (link). Now I want to analyze the correlation between these two datasets with linear regression. The regular time series is a data.frame and the irregular time series is a zoo object. Problem: For the irregular time series (link) I want also a 10 minutes resolution. Therefore I smoothed the curve and with the function 'loess.smooth()' it's possible to evaluate the points of the curve. R has a number code for every date (e.g. 2009-05-01 00:02:11 = 1241136131). My idea is to use this number code to receive the function value of the smoothed curve. So far, unsuccessfully. I read a lot of manuals but I couldn't find an answer. If this issue is already answered I apologize. Thank a lot, Alex Do you really want to interpolate? The interpolated data won't necessarily have the same properties as the original data. Why not model with the time points you do have that are at the same time point in the two data sets? Or is the problem that the irregular data don't ever match the sample times of the regular series. G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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 to save R file into specific type
Hello everyone Can you please teach me how to save my homework as .R file? I write my code in RGui. When I tried to save my work, the RGui only allows me to save it as .RData. Is there any difference between .R and .RData? By the way, after I save my work as .RData, I cannot reopen it. when I open it, only one message comes out as following: ARGUMENT_ignored_. -- View this message in context: http://r.789695.n4.nabble.com/How-to-save-R-file-into-specific-type-tp3009879p3009879.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] gam plots and seWithMean
hadn't realised the answer would be in the source code! anyway, this appears to work. The only difference is in the last section. greg -- library(mgcv) #simulate some data x1-runif(500) x2-rnorm(500) x3-rpois(500,3) d-runif(500) t-runif(500,20,50) linp--6.5+x1+2*x2-x3+2*exp(-2*d)*sin(2*pi*d) lam-t*exp(linp) y-rpois(500,lam) sum(y) table(y) #fit the data without d by glm and with d by gam f1-glm(y~offset(log(t))+x1+x2+x3,poisson) f2-gam(update.formula(as.formula(f1),~.+s(d)),poisson) anova(f1,f2) summary(f2) plot(f2) #the solid line s(d) dat-data.frame(t,d,x1,x2,x3) datn-transform(dat,d=0) dif-predict(f2)-predict(f2,datn) cdif-dif-mean(dif) points(d,cdif,cex=0.5,col=rgb(0,1,0,0.2)) #another approach to the solid line s(d) devAskNewPage(ask=T) plot(f2) premat2-PredictMat(f2$smooth[[1]],data=dat) dim(premat2) pars-f2$coef pars2-pars[5:13] pars2-as.matrix(pars2,9,1) pars2 points(d,premat2%*%pars2,cex=0.5,col=rgb(0,0.6,0.3,0.2)) #premat2%*%pars2 = cdif #confidence intervals when seWithMean = FALSE devAskNewPage(ask=T) plot(f2) points(d,cdif,cex=0.5,col=rgb(0,1,0,0.2)) Vp2-f2$Vp[5:13,5:13] se2-sqrt(diag(premat2%*%Vp2%*%t(premat2))) points(d,cdif+qnorm(0.975)*se2,cex=0.5,col=rgb(1,0,0,0.2)) points(d,cdif-qnorm(0.975)*se2,cex=0.5,col=rgb(0,0,1,0.2)) #numerical output for the confidence bands is given by #cdif+qnorm(0.975)*se2 #cdif-qnorm(0.975)*se2 #confidence intervals when seWithMean = TRUE devAskNewPage(ask=T) plot(f2,seWithMean=T) points(d,cdif,cex=0.5,col=rgb(0,1,0,0.2)) premat-cbind(rep(1,500),x1,x2,x3,premat2) pars-as.matrix(pars,13,1) range(predict.gam(f2)-log(t)-as.numeric(premat%*%pars)) #so predict.gam(f2) = log(t) + as.numeric(premat%*%pars) sew-sqrt(diag(premat%*%f2$Vp%*%t(premat))) range(sew-predict(f2,se.fit=T)$se.fit) #sew = predict(f2,se.fit=T)$se.fit points(d,cdif+qnorm(0.975)*sew,cex=0.5,col=rgb(1,0,0,0.2)) points(d,cdif-qnorm(0.975)*sew,cex=0.5,col=rgb(0,0,1,0.2)) #so this is not what plot.gam is doing #but this is devAskNewPage(ask=T) plot(f2,seWithMean=T) points(d,cdif,cex=0.5,col=rgb(0,1,0,0.2)) premat-cbind(rep(1,500),x1,x2,x3,premat2) pars-as.matrix(pars,13,1) premat1-premat premat1[,1:4]-rep(f2$cmX[1:4],each=500) sew1-sqrt(diag(premat1%*%f2$Vp%*%t(premat1))) points(d,cdif+qnorm(0.975)*sew1,cex=0.5,col=rgb(1,0,0,0.2)) points(d,cdif-qnorm(0.975)*sew1,cex=0.5,col=rgb(0,0,1,0.2)) __ 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 does not work
What is a pdf device? How to change this? From: Uwe Ligges lig...@statistik.tu-dortmund.de Cc: Rhelp r-help@r-project.org Sent: Mon, October 25, 2010 11:49:37 AM Subject: Re: [R] plot does not work You are probably plotting into a pdf device (the default if no X11 available). Uwe Ligges On 25.10.2010 11:44, Alaios wrote: Hello everyone The following two commands plot.default(seq(1,5),seq(2,6)) plot(seq(1,5),seq(2,6)) plot nothing. One day ago this would create a simple plot diagram but unfortunately right now no plot appears. ?plot returns Help on topic 'plot' was found in the following packages: Plot a Raster* object (in package raster in library /home/apa/R/x86_64-unknown-linux-gnu-library/2.11) Generic X-Y Plotting (in package graphics in library /usr/lib64/R/library) What do you think I should blame for that? Best Regards Alex [[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] plot does not work
See ?x11 ?pdf Uwe Ligges On 25.10.2010 12:16, Alaios wrote: What is a pdf device? How to change this? *From:* Uwe Ligges lig...@statistik.tu-dortmund.de *To:* Alaios ala...@yahoo.com *Cc:* Rhelp r-help@r-project.org *Sent:* Mon, October 25, 2010 11:49:37 AM *Subject:* Re: [R] plot does not work You are probably plotting into a pdf device (the default if no X11 available). Uwe Ligges On 25.10.2010 11:44, Alaios wrote: Hello everyone The following two commands plot.default(seq(1,5),seq(2,6)) plot(seq(1,5),seq(2,6)) plot nothing. One day ago this would create a simple plot diagram but unfortunately right now no plot appears. ?plot returns Help on topic 'plot' was found in the following packages: Plot a Raster* object (in package raster in library /home/apa/R/x86_64-unknown-linux-gnu-library/2.11) Generic X-Y Plotting (in package graphics in library /usr/lib64/R/library) What do you think I should blame for that? Best Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailto: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-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] Contour Plot on a non Rectangular Grid
On 10/25/2010 01:32 AM, David Winsemius wrote: You were advised to look at rms. Why have you dismissed this suggestion? Using your data setup below and packaging into a dataframe. require(rms) ddf - datadist(xysf - as.data.frame(xys)) olsfit - ols(V3~rcs(V1,3)+rcs(V2,3), data=xysf) bounds - perimeter(xysf$V1, xysf$V2) plot(xysf$V1, xysf$V2) #demonstrates the extent of the data bplot(Predict(olsfit, V1,V2), perim=bounds) # a levelplot is the default bplot(Predict(olsfit, V1,V2), perim=bounds, lfun=contourplot) bplot(Predict(olsfit, V1,V2), perim=bounds, lfun=contourplot, xlim=c(-2.5,2.5)) # to demonstrate that perimeter works # and as expected this shows very little variability d/t V1 olsfit # note that anova(olsfit) Analysis of Variance Response: V3 Factor d.f. Partial SS MS F P V1 2 0.01618738 8.093691e-03 19.47 .0001 Nonlinear 1 0.01618738 1.618738e-02 38.93 .0001 V2 2 470.67057254 2.353353e+02 566040.95 .0001 Nonlinear 1 470.67057254 4.706706e+02 1132081.91 .0001 TOTAL NONLINEAR 2 527.78127558 2.638906e+02 634723.80 .0001 REGRESSION 4 527.78127558 1.319453e+02 317361.90 .0001 ERROR 7663 3.18594315 4.157566e-04 # most the the regression SS is in the V2 variable # Q.E.D. Thanks David, But I am experiencing some problems with your snippet. When I run the code at the end of the email (saved as plot_circular.R), I get the following error source('plot_circular.R') Error in value.chk(at, which(name == n), NA, np, lim) : variable V1 does not have limits defined by datadist which you clearly do not have on your machine. Have I left out some bits of your code? Lorenzo require(rms) R - pi/2 n - 100 x - y - seq(-R,R, length=n) xys - c() temp - seq(3) for (i in seq(n)){ for (j in seq(n)) #check I am inside the circle if ((sqrt(x[i]^2+y[j]^2))=R){ temp[1] - x[i] temp[2] - y[j] temp[3] - abs(cos(y[j])) xys - rbind(xys,temp) } } ddf - datadist(xysf - as.data.frame(xys)) olsfit - ols(V3~rcs(V1,3)+rcs(V2,3), data=xysf) bounds - perimeter(xysf$V1, xysf$V2) plot(xysf$V1, xysf$V2) #demonstrates the extent of the data bplot(Predict(olsfit, V1,V2), perim=bounds) # a levelplot is the default bplot(Predict(olsfit, V1,V2), perim=bounds, lfun=contourplot) bplot(Predict(olsfit, V1,V2), perim=bounds, lfun=contourplot, xlim=c(-2.5,2.5)) # to demonstrate that perimeter works __ 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] Unable to allocate arrays of size 2GB in 64 bit Windows 7 R
Bhattacharyya, Siddhartha wrote: I seem Unable to allocate arrays of size around 2GB in 64 bit Windows 7 R. There is a lot of main memory available. The memory.limit is set to the max memory available, and there is more than 10GB of that available when R returns an 'unable to allocate memory' error. Is this a limitation of R even in 64 bit Windows 7? Or is there a wY to get I've this? There's currently a limit of 2^31-1 in the length of a vector in all versions, so that's the most entries you can have in a matrix as well. The data in each entry is usually more than one byte, so the total size of allocation can be much bigger than 2 GB, but the number of entries can't. Duncan Murdoch __ 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] R-Fortran question (multiple subroutines)
G'day Remko, On Mon, 25 Oct 2010 15:33:30 +1100 Remko Duursma remkoduur...@gmail.com wrote: apologies if this is somewhere in a manual, I have not been able to find anything relevant. You probably have to set some appropriate flags and the information should be somewhere in the manual of your compiler. Though, Writing R Exensions will tell you now to change/specify flags for compilers. I run Windows Vista. My condolences. :) But is it possible to have more than one subroutine in my source file, one depending on the other? Yes. I.e, my code looks something like this: subroutine f(x,y,z) call g(x,y,z) end subroutine g(x,y,z) z = x*y end calling this from R shows that subroutine g is not called. What do you mean with g is not called? How did you assert this? If the code functions correctly, then g has to be called, either explicitly or implicitly (e.g. if it was inlined). Do you mean that when you compile the code and load the resulting DLL from R, you can only call subroutine f via .Fortran but not subroutine g? The code compiled as executable works fine. What do you mean with compiled as executable? The snippet that you showed would not compile as an executable as there is no main program. So what do you mean with works fine? That you can call the subroutine g from the main program that you use when creating an executable? My guess, based on this snippet, is that your compiler notices that subroutine g is not really needed and replaces the call to g within f by the body of g and does not create a separate entry point for g in the compiled object; a process known as in-lining (IIRC) and typically used by compilers if high levels of optimisations are requested. The compiler does not know that you intend to call g later directly from R via .Fortran, all it sees is the code in the file and, if high optimisation is requested, it may feel free to rearrange the code to stream-line it (e.g. by in-lining). So possible solutions could be: 1) ask for a lower level of optimisation 2) tell the compiler not to do in-lining (flag --no-inline??) 3) put the routines into separate files, compile the files separately and then link all the resulting object files together into a DLL. AFAIK, optimising/inlining across separate files is a tricky issue so few, if any, compilers would do so. 4) Check whether there is an option to specify which exportable symbols have to be in the DLL in the end. Cheers, Berwin == Full address Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Maths and Stats (M019)+61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009e-mail: ber...@maths.uwa.edu.au Australiahttp://www.maths.uwa.edu.au/~berwin __ 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] R-Fortran question (multiple subroutines)
Remko Duursma wrote: Dear R-helpers, apologies if this is somewhere in a manual, I have not been able to find anything relevant. I run Windows Vista. I have some Fortran code in a subroutine, and have no problem calling this from R with .Fortran, compiling the code either with 'R CMD SHLIB' or independently with gfortran. But is it possible to have more than one subroutine in my source file, one depending on the other? Or is this not supported, or is there a trick? Of course, I could rewrite my code, but there are lots of subroutines... I.e, my code looks something like this: subroutine f(x,y,z) call g(x,y,z) end subroutine g(x,y,z) z = x*y end calling this from R shows that subroutine g is not called. The code compiled as executable works fine. There are no such limitations imposed by R. I'd suggest your diagnosis of the problem is wrong. If you can't spot the problem, please post a real example (simplified if possible, but not as much as the one above). Duncan Murdoch thanks, Remko - Remko Duursma Research Lecturer Centre for Plants and the Environment University of Western Sydney Hawkesbury Campus Richmond NSW 2753 Mobile: +61 (0)422 096908 www.remkoduursma.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] Using tapply?
Hi: I'm pretty sure that newton.method in the animation package is meant to illustrate the technique rather than to be used as an optimizer in practice. Look at ?optim; it that doesn't meet your needs, consult the Optimization Task View at CRAN, where you will find several packages, in addition to functions in the base package, devoted to function optimization. HTH, Dennis On Mon, Oct 25, 2010 at 12:18 AM, Amy Milano milano_...@yahoo.com wrote: Dear R helpers, I am trying to calculate the Annualized Percent Rate using following R - Code. # ## R Code library(animation) # INPUT C = 25# Loan Amount E = 2500 # Other Cost R = 6 # Interest rate r = R/1200# Monthly interest rate q = 12# No of Compoundings n = 20# No of years # # COMPUTATIONS N = n * q # No of months P = ((C + E)*r*(1+r)^N) / ((1+r)^N - 1) # Monthly Payments ani.options(nmax = 500) solu = newton.method(function(a) C * (a*(1+a)^N) - P * ((1+a)^N - 1), 1, c(R - 0.25*R, R + 0.25*R)) solu$root APR = ((1+solu$root)^q-1)*100 # _ ## RESULTS P = 1808.988, APR = 6.298708 These are the values I obtain. # ## PROBLEM This R code holds or yields results if I am dealing with only one value for each of the input. However, if there are more than one input values, how do I proceed? Say, E.g. C = c(25, 40) E = c(2500, 5000) R = c(6, 6) q = c(12, 12) n = c(20, 20) So using above code, I am able to obtain the values of P as 1808.988 and 2901.546 respectively. However, using this code I am not able to obtain solu as defined above. I tried using the tapply instead but seems its not working. Please guide as to how do I use tapply here. Regards and thanking in advance Amy [[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] difftime error
R community, I am trying to create an array of the time differences between datapoints for a very large set. For some reason for 4 of the values the difference has been calculated as NA. Looking at the individual points two of them are 1981-03-29 01:40:00 and 1981-03-29 02:00:00 This is the exact same format as the other points that return values of 20 mins as expected. In such a large dataset (600,000+ entries) I don't know why only 4 would be doing this. Apologies for such a vague question but can anyone shed any light on what may be wrong? Thanks, Doug -- View this message in context: http://r.789695.n4.nabble.com/difftime-error-tp3010105p3010105.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] difftime error
On 25.10.2010 12:55, dpender wrote: R community, I am trying to create an array of the time differences between datapoints for a very large set. For some reason for 4 of the values the difference has been calculated as NA. Looking at the individual points two of them are 1981-03-29 01:40:00 and 1981-03-29 02:00:00 Note that 1981-03-29 02:00:00 is exactly the time of a daylight saving time change and needs declaration of a time zone. You may want to force tz=GMT if you think the time difference was really 20 minutes (rather than 1:20 or -0:40 or whatever that is). Best, Uwe Ligges This is the exact same format as the other points that return values of 20 mins as expected. In such a large dataset (600,000+ entries) I don't know why only 4 would be doing this. Apologies for such a vague question but can anyone shed any light on what may be wrong? Thanks, Doug __ 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 to save R file into specific type
You should probably ask your professor to be certain, but I would suggest writing your code in a text editor and saving it with the .R extension. Saving a .RData file using save() [you didn't tell us what you did] saves the objects but not the code used to generate them. An .RData file can be opened using load(). Sarah On Mon, Oct 25, 2010 at 4:07 AM, zhiji19 zhij...@gmail.com wrote: Hello everyone Can you please teach me how to save my homework as .R file? I write my code in RGui. When I tried to save my work, the RGui only allows me to save it as .RData. Is there any difference between .R and .RData? By the way, after I save my work as .RData, I cannot reopen it. when I open it, only one message comes out as following: ARGUMENT_ignored_. -- -- Sarah Goslee http://www.functionaldiversity.org __ 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] penalized regression analysis
Hi All, I am using the package 'penalized' to perform a multiple regression on a dataset of 33 samples and 9 explanatory variables. The analysis appears to have performed as outlined and I have ended up with 4 explanatory variables and their respective regression coefficients. What I am struggling to understand is where do I get the variance explained information from and how do I determine the relative importance of the 4 variables selected? It does not appear to be a part of the penalized procedure. I submit the final call to 'penalized' with the estimated values of lambda1 and lambda2 fitfinal - penalized(CHAB~.,data=chabun,lambda1=356.0856,lambda2=3.458605,model = linear,steps=1,standardize = TRUE) # nonzero coefficients: 5 fitfinal Penalized linear regression object 10 regression coefficients of which 5 are non-zero Loglikelihood = -154.1055 L1 penalty = 4944.889 at lambda1 = 356.0856 L2 penalty = 234.7781 at lambda2 = 3.458605 coefficients (fitfinal) (Intercept)BC POC EXPFI 4.685739e+01 2.074521e-01 1.079459e-01 -1.373058e-05 -2.295339e+00 cheers Andy -- Andrew Halford Ph.D Associate Research Scientist Marine Laboratory University of Guam Ph: +1 671 734 2948 [[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] difftime error
On Mon, 25 Oct 2010, dpender wrote: R community, I am trying to create an array of the time differences between datapoints for a very large set. For some reason for 4 of the values the difference has been calculated as NA. Looking at the individual points two of them are 1981-03-29 01:40:00 and 1981-03-29 02:00:00 Do such times exist in your unstated timezone? The first definitely does not in the UK timezone (hint DST started at 1am on that day). What precisely happens when you specify invalid date-times is system-dependent, and you have not stated yours (pace the posting guide). But I am surprised you got NA. This is the exact same format as the other points that return values of 20 mins as expected. In such a large dataset (600,000+ entries) I don't know why only 4 would be doing this. Apologies for such a vague question but can anyone shed any light on what may be wrong? Thanks, Doug -- View this message in context: http://r.789695.n4.nabble.com/difftime-error-tp3010105p3010105.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk 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@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] .R file
Hi : It's not clear whether you want to save your code, your R object or both. Tal has already directed you to help for saving objects created in your workspace. As for saving the code, many people write their code in an editor and either copy/paste it into the workspace or, with certain editors, mark text to be sent to the R console directly. You can use almost any editor to copy/paste code, but some, like Eclipse and Emacs, can interface with the R console directly. It's a good idea to keep your code somewhere outside the R console in case of a crash, but it is also easier to modify and organize code in an editor and send it to R, especially if you're making a lot of changes on the fly or writing functions. I use Emacs and Eclipse myself, but other editors, such as Tinn-R, have similar capabilities. A tutorial to configure Eclipse with StatET, its R plug-in: http://www.splusbook.com/R_Eclipse_StatET.pdf A blog post that provides steps to configure Eclipse with StatET and TeXlipse, in case you want/need to use Sweave in conjunction with R at some point: http://www.r-bloggers.com/getting-started-with-sweave-r-latex-eclipse-statet-texlipse/ The home page of ESS (Emacs Speaks Statistics): http://ess.r-project.org/index.php?Section=home Emacs is kind of an 'all-in-one' editor that lets you work on several projects simultaneously - with ESS, for example, you could be working on a text document in one buffer, an R document in another, a C program in a third, etc. Most of the R veterans who use it swear by it - I like it, too :) If you want it, the best option on Windows or Mac is to use the installer provided by Vincent Goulet, who did a wonderful job in producing it. Eclipse has similar capabilities and may be a better choice if you program in Java, Python or C++ regularly. Home page for Tinn-R: http://www.sciviews.org/Tinn-R/ All three of these editors are external to R but have the capability of sending code from the editor to the console. All of them are good and have loyal user bases. Notepad++ is another option; but you have to copy/paste code to R - I mention it because it has syntax highlighting and is capable of saving files in numerous formats. In fact, all of the editors mentioned above have syntax highlighting capabilities, which is very useful when writing/developing code and documents, and all of them let you save a file with a .R extension (unlike certain Windows editors, for example). I'm certain I've missed a few, especially on the Linux and Mac platforms, and I expect others will chime in with their preferences. HTH, Dennis On Sun, Oct 24, 2010 at 11:57 PM, zhiji19 zhij...@gmail.com wrote: Hello everyone Can you please teach me how to save my homework as .R file? I write my code in RGui. When I tried to save my work, the RGui only allows me to save it as .RData. By the way, after I save my work as .RData, I cannot reopen it. when I open it, only one message comes out as following: ARGUMENT_ignored_. -- View this message in context: http://r.789695.n4.nabble.com/R-file-tp3009812p3009812.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Using tapply?
Dear Sir, Thanks a lot for your advice and surely I will be going through your suggestion as regards ?optim. In the mean time, is it possible to guide me regarding one general question. Suppose instead of using newton.method function, I am using some other function resulting in some other process and which is using say C, E, N, R only. (i.e. I am not calculating root anymore). My problem is how do I apply this function row-wise to a table. I am not sure whether I am able to put up my query properly. Basically, I need to apply the function to a table and store the result row-wise. Thanks in advance Sir. Regards Amy --- On Mon, 10/25/10, Dennis Murphy djmu...@gmail.com wrote: From: Dennis Murphy djmu...@gmail.com Subject: Re: [R] Using tapply? To: Amy Milano milano_...@yahoo.com Cc: r-help@r-project.org Date: Monday, October 25, 2010, 10:47 AM Hi: I'm pretty sure that newton.method in the animation package is meant to illustrate the technique rather than to be used as an optimizer in practice. Look at ?optim; it that doesn't meet your needs, consult the Optimization Task View at CRAN, where you will find several packages, in addition to functions in the base package, devoted to function optimization. HTH, Dennis On Mon, Oct 25, 2010 at 12:18 AM, Amy Milano milano_...@yahoo.com wrote: Dear R helpers, I am trying to calculate the Annualized Percent Rate using following R - Code. # ## R Code library(animation) # INPUT C = 25 # Loan Amount E = 2500 # Other Cost R = 6 # Interest rate r = R/1200 # Monthly interest rate q = 12 # No of Compoundings n = 20 # No of years # # COMPUTATIONS N = n * q # No of months P = ((C + E)*r*(1+r)^N) / ((1+r)^N - 1) # Monthly Payments ani.options(nmax = 500) solu = newton.method(function(a) C * (a*(1+a)^N) - P * ((1+a)^N - 1), 1, c(R - 0.25*R, R + 0.25*R)) solu$root APR = ((1+solu$root)^q-1)*100 # _ ## RESULTS P = 1808.988, APR = 6.298708 These are the values I obtain. # ## PROBLEM This R code holds or yields results if I am dealing with only one value for each of the input. However, if there are more than one input values, how do I proceed? Say, E.g. C = c(25, 40) E = c(2500, 5000) R = c(6, 6) q = c(12, 12) n = c(20, 20) So using above code, I am able to obtain the values of P as 1808.988 and 2901.546 respectively. However, using this code I am not able to obtain solu as defined above. I tried using the tapply instead but seems its not working. Please guide as to how do I use tapply here. Regards and thanking in advance Amy [[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] Find index of a string inside a string?
Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do in SAS. thanks, y. baranan. [[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] Find index of a string inside a string?
For simple searches, use grep with fixed=TRUE. Check ?grep. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of yoav baranan Sent: maandag 25 oktober 2010 13:27 To: r-help@r-project.org Subject: [R] Find index of a string inside a string? Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do in SAS. thanks, y. baranan. [[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-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] Find index of a string inside a string?
Thank you. I know grep, but I don't know how to use it for what I need to do. for instance: grep(bcd, abcd) returns: [1] 1 grep(bcd, aabcd) returns: [1] 1 I need the first one to return 2 (b is in the 2nd cell), and the second one return 3 (b is in the 3rd cell). thanks From: nick.sa...@ugent.be To: ybara...@hotmail.com; r-help@r-project.org Subject: RE: [R] Find index of a string inside a string? Date: Mon, 25 Oct 2010 13:42:23 +0200 For simple searches, use grep with fixed=TRUE. Check ?grep. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of yoav baranan Sent: maandag 25 oktober 2010 13:27 To: r-help@r-project.org Subject: [R] Find index of a string inside a string? Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do in SAS. thanks, y. baranan. [[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] difftime error
That's it exactly. Do you know how to specify the timezone for Sydney, Australia? -- View this message in context: http://r.789695.n4.nabble.com/difftime-error-tp3010105p3010175.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Find index of a string inside a string?
I think what you want is 'regexpr': regexpr(bcd, aabcd) [1] 3 attr(,match.length) [1] 3 On Mon, Oct 25, 2010 at 7:27 AM, yoav baranan ybara...@hotmail.com wrote: Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do in SAS. thanks, y. baranan. [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Find index of a string inside a string?
Or str_locate: library(stringr) str_locate(aabcd, bcd) Hadley On Mon, Oct 25, 2010 at 5:53 AM, jim holtman jholt...@gmail.com wrote: I think what you want is 'regexpr': regexpr(bcd, aabcd) [1] 3 attr(,match.length) [1] 3 On Mon, Oct 25, 2010 at 7:27 AM, yoav baranan ybara...@hotmail.com wrote: Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do in SAS. thanks, y. baranan. [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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. -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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 does not work
try 'graphics.off()' to close any device that might be open and see if you see any output. On Mon, Oct 25, 2010 at 5:44 AM, Alaios ala...@yahoo.com wrote: Hello everyone The following two commands plot.default(seq(1,5),seq(2,6)) plot(seq(1,5),seq(2,6)) plot nothing. One day ago this would create a simple plot diagram but unfortunately right now no plot appears. ?plot returns Help on topic 'plot' was found in the following packages: Plot a Raster* object (in package raster in library /home/apa/R/x86_64-unknown-linux-gnu-library/2.11) Generic X-Y Plotting (in package graphics in library /usr/lib64/R/library) What do you think I should blame for that? Best Regards Alex [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] R-Fortran question (multiple subroutines)
G'day all, On Mon, 25 Oct 2010 06:52:15 -0400 Duncan Murdoch murdoch.dun...@gmail.com wrote: Remko Duursma wrote: [...] I.e, my code looks something like this: subroutine f(x,y,z) call g(x,y,z) end subroutine g(x,y,z) z = x*y end calling this from R shows that subroutine g is not called. The code compiled as executable works fine. There are no such limitations imposed by R. I'd suggest your diagnosis of the problem is wrong. If you can't spot the problem, please post a real example (simplified if possible, but not as much as the one above). Actually, it turns out that this example is simplified enough. :) I put this snippet into a file, compiled it via R CMD SHLIB, loaded it into R and then was very surprised about the result of .Fortran(f, x=1.1, y=2.2, z=0.0). Eventually it dawned to me, Remko needs to read the table in section 5.2 of Writing R Extensions. The simple fix in this case is to put a double precision x, y, z at the beginning of each subroutine. The default precision in FORTRAN is not double precision, that's why the code seems to work when compiled as stand alone but not when called from R. In general, I would recommend to start each subroutine with implicit none (o.k., I know that this is not standard FORTRAN77 but most compiler support that construct; the alternative, that would confrom with the FORTRAN77 standard, is to declare everything to be implicitly of type character and then let the fun begin) and then to explicitly declare all variables to be of the appropriate type. HTH. Cheers, Berwin __ 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] Controlling number of numbers before R rewrites to +e18 etc
You can always read a portion of the file and then write it out. For large files, I will read in 10,000 line, fix them up and then write them out and go back and process the next batch of lines. You haven't shown us what a sample of your input/output is, or how you are processing them. Depending on what type of preprocessing needs to be done to the data, PERL is also an option. But most things I used to use PERL for, I can do within R these days. Here is an example of reading in your IDs: x - read.table(textConnection(1234567890123456789012 987654321234567898765432 98765432123456789876543 + 1234567890123456789012 987654321234567898765432 98765432123456789876543 + 1234567890123456789012 987654321234567898765432 98765432123456789876543 + 1234567890123456789012 987654321234567898765432 98765432123456789876543 + 1234567890123456789012 987654321234567898765432 98765432123456789876543 + 1234567890123456789012 987654321234567898765432 98765432123456789876543 + 1234567890123456789012 987654321234567898765432 98765432123456789876543) + , colClasses = rep('character', 3)) closeAllConnections() str(x) 'data.frame': 7 obs. of 3 variables: $ V1: chr 1234567890123456789012 1234567890123456789012 1234567890123456789012 1234567890123456789012 ... $ V2: chr 987654321234567898765432 987654321234567898765432 987654321234567898765432 987654321234567898765432 ... $ V3: chr 98765432123456789876543 98765432123456789876543 98765432123456789876543 98765432123456789876543 ... x V1 V2 V3 1 1234567890123456789012 987654321234567898765432 98765432123456789876543 2 1234567890123456789012 987654321234567898765432 98765432123456789876543 3 1234567890123456789012 987654321234567898765432 98765432123456789876543 4 1234567890123456789012 987654321234567898765432 98765432123456789876543 5 1234567890123456789012 987654321234567898765432 98765432123456789876543 6 1234567890123456789012 987654321234567898765432 98765432123456789876543 7 1234567890123456789012 987654321234567898765432 98765432123456789876543 On Mon, Oct 25, 2010 at 4:41 AM, ZeMajik zema...@gmail.com wrote: Thanks Jim, but I still got the problem that the pre-processing becomes way too computationally expensive. R seems to handle characters and factors much much worse than numeric IDs. I don't have enough RAM to even write the file when they are viewed as chars instead of numeric values! Anyone have any other ideas? Is it not possible to tell R not to rewrite upon import? It wouldn't matter if it only would write the correct IDs to the exported csv file, but it exports the abbreviated version which is of no use. Mike On Sat, Oct 23, 2010 at 3:56 AM, jim holtman jholt...@gmail.com wrote: Your best bet is to make sure that you read the IDs in as characters. If they are being read in as floating point numbers, then there is only 15 digits of accuracy, so if you have IDs 18-22 digits, you will be missing data. So if you are using read.table, then look at colClasses to see how to do this. Provide a subset of your data and the statements that you are using to read in the data. On Fri, Oct 22, 2010 at 1:15 PM, ZeMajik zema...@gmail.com wrote: Hey, I'm using R as a pre-processor for a large dataset with IDs which are numeric (but has no numeric meaning so can be seen as factors). I do some data formating and then write it out to a csv file. However the problem is that the IDs are very long, 18-22 chars long more precisely. R is constantly rewriting these IDs to the abbreviated +eX which hinders me from exporting the data to the csv since the IDs are no longer intact. I've tried telling R that ID column is a factor, but this results in two problems: 1) Since I have millions of rows and R is slower handling factors than numbers my comp can't run the process in any kind of reasonable time. and 2) Some IDs STILL seem to be rewritten somehow. The second point made me believe that perhaps R is rewriting upon import? Does anyone have any tips on how to solve this problem? Thanks, Mike [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] .R file
All three of these editors are external to R but have the capability of sending code from the editor to the console. All of them are good and have loyal user bases. Notepad++ is another option; but you have to copy/paste code to R - I mention it because it has syntax highlighting and is capable of saving files in numerous formats. In fact, all of the editors mentioned above have syntax highlighting capabilities, which is very useful when writing/developing code and documents, and all of them let you save a file with a .R extension (unlike certain Windows editors, for example). I'm certain I've missed a few, especially on the Linux and Mac platforms, and I expect others will chime in with their preferences. You mention Notepad++, I'm still using vi under cygwin and an ancient copy of ultra edit. When I was first learning Java and c++, the various commercial IDE packages were great. However, I've found that with most things I end up integrating with bash scripts and end up in vi for touch up anyway- and if you take the time to learn it many of the odd commands are quite helpful. IIRC many of the IDE's offer language-specific help beyond syntax highlighting such as signature suggestions as you type or menu options for compiling and debugging that pure text editors lack, not sure what the R IDE does. I finally developed alt approaches for finding signatures and it turned out to be easier to do this outside ide although sometimes I compile bad code due to typo that IDE would have flagged. In the simple case on windows, I vi my .R file and then invoke a script to run it. In many cases ,the IDE menu's for more language specific actions like compile and build are confusing and limited and have a learning curve and there too I end up editing bash scripts using cmd line alt. So, I guess my point is that I would not just run to an IDE for R or others :) HTH, Dennis On Sun, Oct 24, 2010 at 11:57 PM, zhiji19 wrote: Hello everyone Can you please teach me how to save my homework as .R file? I write my code in RGui. When I tried to save my work, the RGui only allows me to save it as .RData. __ 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] Find index of a string inside a string?
Indeed, thank you. The exact equivalent of index in SAS seems to me: regexpr(bcd, aabcd, fixed=T)[1] [1] 3 Date: Mon, 25 Oct 2010 07:53:22 -0400 Subject: Re: [R] Find index of a string inside a string? From: jholt...@gmail.com To: ybara...@hotmail.com CC: r-help@r-project.org I think what you want is 'regexpr': regexpr(bcd, aabcd) [1] 3 attr(,match.length) [1] 3 On Mon, Oct 25, 2010 at 7:27 AM, yoav baranan ybara...@hotmail.com wrote: Hi, I am searching for the equivalent of the function Index from SAS. In SAS: index(abcd, bcd) will return 2 because bcd is located in the 2nd cell of the abcd string. The equivalent in R should do this: myIndex - foo(abcd, bcd) #return 2. What is the function that I am looking for? I want to use the return value in substr, like I do in SAS. thanks, y. baranan. [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] font.lab and font.axis
W dniu 25 pa¼dziernika 2010 13:14 u¿ytkownik Jim Lemon j...@bitwrit.com.aunapisa³: On 10/25/2010 08:02 PM, £ukasz Rêc³awowicz wrote: 2010/10/25 Jim Lemon j...@bitwrit.com.au mailto:j...@bitwrit.com.au Would someone like to suggest a better way to get axis to look at the font it's supposed to be using? Are you looking for something like this? x-rnorm(100) hist(x,axes=F,font.lab=12,font.main=9) axis(1,font.axis=4) axis(2,font.axis=3) -- Something like that, except that I was thinking of a par command that would affect subsequent calls to axis, not as an argument to the function itself. Jim Could you give an example code which doesn't work with par()? -- Mi³ego dnia [[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.read intraday data
Hello all, I'm trying to use zoo.read but can't figure out how to deal with the time format. (example below) would be nice if someone could help. best regards, Immanuel --- L - Date,Time,Open,High,Low,Close,Up,Down 05.02.2001,00:30,421.20,421.20,421.20,421.20,11,0 05.02.2001,01:30,421.20,421.40,421.20,421.40,7,0 05.02.2001,02:00,421.30,421.30,421.30,421.30,0,5 05.02.2001,02:30,421.60,421.60,421.50,421.50,26,1 library(zoo) library(chron) f - function(x) chron(paste(x[,1]),paste(x[,2]), format = c(dates = D.M.Y, times = hh:mm)) z - read.zoo(textConnection(L), index = 1:2, sep=,, header = TRUE, FUN = f) print(z) __ 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] .R file
On Mon, Oct 25, 2010 at 9:11 AM, Mike Marchywka marchy...@hotmail.com wrote: You mention Notepad++, I'm still using vi under cygwin and an ancient copy of ultra edit. People who uses vi or vim may be interested in looking at the plugin to Vim that I'm developing. The plugin works in Windows, Linux and OS X: http://www.vim.org/scripts/script.php?script_id=2628 It's main features are: * Syntax highlighting for R syntax, including: - Special characters in strings. - Functions of all installed packages (must be updated manually). - Special highlighting for R output (.Rout files). * Smart indentation for R syntax. * Integrated communication with R: - Start/Close R. - Send lines, selection, paragraphs, functions, blocks, entire file. - Send commands with the object under cursor as argument: help, args, plot, print, str, summary, example, names. - Send to R the Sweave and pdflatex commands. - Run R inside a Vim's buffer (with Conque Shell plugin; currently available only on Unix -- Linux or OS X). * Omni completion (auto-completion) for R objects (.GlobalEnv and installed packages. The list of installed packages must be updated manually. * Ability to see R's documentation in a Vim's buffer: - Automatic calculation of the best layout of the R documentation buffer (split the window either horizontally or vertically according to the available room). - Automatic formating of the text to fit the panel width. - Send code and commands to R (useful to run examples). - Jump to another R documentation. - Syntax highlighting of R documentation. * Object browser (.GlobalEnv and loaded packages; must be updated manually): - Send commands with object under cursor as argument. - Call R's help() with object under cursor as argument. - Syntax highlighting of the object browser. * Most of the plugin's behavior is customizable. -- Jakson Aquino Federal University of Ceara - Brazil __ 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] zoo.read intraday data
On Mon, 25 Oct 2010, Immanuel wrote: Hello all, I'm trying to use zoo.read Just for the record: read.zoo(). but can't figure out how to deal with the time format. (example below) Yes, the problem is only the chron conversion (and not read.zoo). would be nice if someone could help. best regards, Immanuel --- L - Date,Time,Open,High,Low,Close,Up,Down 05.02.2001,00:30,421.20,421.20,421.20,421.20,11,0 05.02.2001,01:30,421.20,421.40,421.20,421.40,7,0 05.02.2001,02:00,421.30,421.30,421.30,421.30,0,5 05.02.2001,02:30,421.60,421.60,421.50,421.50,26,1 library(zoo) library(chron) f - function(x) chron(paste(x[,1]),paste(x[,2]), format = c(dates = D.M.Y, times = hh:mm)) I think that chron might require seconds. Hence you can add 00 seconds for all times and change the format accordingly, e.g., f - function(x) chron(paste(x[,1]), paste(x[,2], 00, sep = :), format = c(dates = d.m.y, times = h:m:s)) Then, the call below should work ok. hth, Z z - read.zoo(textConnection(L), index = 1:2, sep=,, header = TRUE, FUN = f) print(z) __ 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-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] zoo.read intraday data
Hey, work's like a charm. thanks __ 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] zoo.read intraday data
On Mon, Oct 25, 2010 at 9:02 AM, Immanuel mane.d...@googlemail.com wrote: Hello all, I'm trying to use zoo.read but can't figure out how to deal with the time format. (example below) would be nice if someone could help. best regards, Immanuel --- L - Date,Time,Open,High,Low,Close,Up,Down 05.02.2001,00:30,421.20,421.20,421.20,421.20,11,0 05.02.2001,01:30,421.20,421.40,421.20,421.40,7,0 05.02.2001,02:00,421.30,421.30,421.30,421.30,0,5 05.02.2001,02:30,421.60,421.60,421.50,421.50,26,1 library(zoo) library(chron) f - function(x) chron(paste(x[,1]),paste(x[,2]), format = c(dates = D.M.Y, times = hh:mm)) z - read.zoo(textConnection(L), index = 1:2, sep=,, header = TRUE, FUN = f) print(z) Here are a few more possibilities: # use chron appending seconds and index = list(1, 2) f - function(d, t, format = c(m.d.y, h:m:s)) { chron(d, paste(t, 00, sep = :), format = format) } z - read.zoo(textConnection(L), index = list(1, 2), sep=,, header = TRUE, FUN = f) # use as.chron and index = list(1, 2) f2 - function(d, t, format = %d.%m.%Y %H:%M) { as.chron(paste(d, t), format = format) } z2 - read.zoo(textConnection(L), index = list(1, 2), sep=,, header = TRUE, FUN = f) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] best predictive model for mixed catagorical/continuous variables
I would expect that there will be interactions between variables eg. if the vegetation is grassland then the vegetation height variable will mediate the interaction, if the vegetation is arable then crop type will be more significant. Would it be possible to use GLM or GAM models for this type of predictive modelling? The answer is probably. I would recommend getting a copy of: Mixed Effects Models and Extensions in Ecology with R (Statistics for Biology and Health) by Alain F. Zuur, Elena N. Ieno, Neil Walker, and Anatoly A. Saveliev Springer, 2009) It covers things very nicely and gives specific R code. Rob __ 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] Optimize parameters of ODE Problem which is solved numeric
Hi Michael, You do not need a numerical solver for this. This is a linear system of ODEs and it admits closed form solutions. The solution is given as: Y(t) = c_1 * v_1 * exp(k_1 * t) + ... + c_4 * v_4 * exp(k_4 * t) where k_1, ..., k_4 are the eigenvalues (can be real or complex) and v_1, ..., v_4 are the eigenvectors (each is a vector of length 4) of the 4x4 coefficient matrix . You can get the constants c_1, ..., c_4 by solving for the initial condition. However, your specification of the coefficient matrix is incorrect. You can cannot have the same coefficients in all the equations. Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Michael S. Sent: Saturday, October 23, 2010 8:06 PM To: r-help@r-project.org Subject: [R] Optimize parameters of ODE Problem which is solved numeric Hi, I have a data-matrix: PID sato hrs fim health 214 3 4.376430 6.582958 5 193 6 4.361825 3.138525 6 8441 6 4.205771 3.835886 7 7525 6 4.284489 3.245139 6 6806 7 4.168926 2.821833 7 5682 7 1.788707 1.212653 7 5225 6 1.651463 1.436980 7 4845 6 1.692710 1.267359 4 4552 5 1.686448 1.220539 6 4282 6 1.579868 1.086296 6 754416 2.978580 1.338100 7 I want to solve the following system of ode (ord. differential equations) numerically (f.e. with euler) dm1/dt - a*m1+b*m2+d*m3+e*m4 dm2/dt - a*m1+b*m2+d*m3+e*m4 dm3/dt - a*m1+b*m2+d*m3+e*m4 dm4/dt - a*m1+b*m2+d*m3+e*m4 with following initial values: m1- PID$sato[1] m2- PID$hrs[1] m3- PID$fim[1] m4- PID$health[1] a,b,d,e are free coeffient. The parameters a,b,d,e are not fix. My goal is to find the optimal parameters dependent on the error of the numerical solution compared to the registered values of PID. I would like to use instead of fix parameters, intervals. And then, through a minimizing function (minimal error) evaluate the optimal parameters. In order to have a first try, I picked fix parameters. a=0.1 b=0.22 d= -0.3 e= -0.4 #parameter vector parameter - c(a,b,d,e) ### Initial Values of the ODE AWPs - function(PID){ m1- PID$sato[1] m2- PID$hrs[1] m3- PID$fim[1] m4- PID$health[1] return(c(m1,m2,m3,m4)) } AWP - AWPs(PID) ## before using ode from Package deSolve SWB - function (t, AWP, parameter) { ### it didn't save the names of the variables, thats why this strange ### lines (but inimportant) m1-AWP[1] m2-AWP[2] m3-AWP[3] m4-AWP[4] ### with(as.list(c(AWP,parameter)),{ # Rate of change dm1 - a*m1+b*m2+d*m3+e*m4 dm2 - a*m1+b*m2+d*m3+e*m4 dm3 - a*m1+b*m2+d*m3+e*m4 dm4 - a*m1+b*m2+d*m3+e*m4 return(list(c(dm1, dm2, dm3, dm4))) }) } ### Time of data times - seq(1996,2006, by=1) require(deSolve) ## instead of ode use also euler out - ode(y = AWP, times = times, func = SWB, parms = parameter) ### Calculating the errors of the solution into a matrix. Taking sum is ### easy. R1 - matrix(0,11,4) for (i in (1:11)){ for(j in (1:4)){ R1[i,j]-out[i,j+1]-PID[i,j] } } sum(R1) What I tried next was, with the package sets, to use the class of interval. require(sets) a1-interval(-2,2) ## Making 4-dimensional cuboit (carthesian product) a4-a^4 ## and trying: out - ode(y = AWP, times = times, func = SWB, parms = a4) But ode can not process, as it looks like, an interval object, since it is a list and not numeric. But I couldn't manage to make a4 or a1 numeric with as.numeric(a4). The results of out don't make much sense. MY QUESTIONS: 1. Is it possible to use an interval instead of fix variables for ode or euler? 2. Reading all of it, is there maybe a easier way to find the optimal parameters for a,b,d,e 3. Does somebody have an idea which function would minimize something like: min{g(x)-f(x)|x in [-2,2]} as you see g(x) is a bit complicated. Thanks for your help in advance. Michael -- GMX DSL Doppel-Flat ab 19,99 euro;/mtl.! Jetzt auch mit gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl __ 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-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] Contour Plot on a non Rectangular Grid
On Oct 25, 2010, at 3:41 AM, Lorenzo Isella wrote: On 10/25/2010 01:32 AM, David Winsemius wrote: You were advised to look at rms. Why have you dismissed this suggestion? Using your data setup below and packaging into a dataframe. require(rms) ddf - datadist(xysf - as.data.frame(xys)) olsfit - ols(V3~rcs(V1,3)+rcs(V2,3), data=xysf) bounds - perimeter(xysf$V1, xysf$V2) plot(xysf$V1, xysf$V2) #demonstrates the extent of the data bplot(Predict(olsfit, V1,V2), perim=bounds) # a levelplot is the default bplot(Predict(olsfit, V1,V2), perim=bounds, lfun=contourplot) bplot(Predict(olsfit, V1,V2), perim=bounds, lfun=contourplot, xlim=c(-2.5,2.5)) # to demonstrate that perimeter works # and as expected this shows very little variability d/t V1 olsfit # note that anova(olsfit) Analysis of Variance Response: V3 Factor d.f. Partial SS MS F P V1 2 0.01618738 8.093691e-03 19.47 .0001 Nonlinear 1 0.01618738 1.618738e-02 38.93 .0001 V2 2 470.67057254 2.353353e+02 566040.95 .0001 Nonlinear 1 470.67057254 4.706706e+02 1132081.91 .0001 TOTAL NONLINEAR 2 527.78127558 2.638906e+02 634723.80 .0001 REGRESSION 4 527.78127558 1.319453e+02 317361.90 .0001 ERROR 7663 3.18594315 4.157566e-04 # most the the regression SS is in the V2 variable # Q.E.D. Thanks David, But I am experiencing some problems with your snippet. When I run the code at the end of the email (saved as plot_circular.R), I get the following error source('plot_circular.R') Error in value.chk(at, which(name == n), NA, np, lim) : variable V1 does not have limits defined by datadist which you clearly do not have on your machine. Have I left out some bits of your code? Lorenzo require(rms) R - pi/2 n - 100 x - y - seq(-R,R, length=n) xys - c() temp - seq(3) for (i in seq(n)){ for (j in seq(n)) #check I am inside the circle if ((sqrt(x[i]^2+y[j]^2))=R){ temp[1] - x[i] temp[2] - y[j] temp[3] - abs(cos(y[j])) xys - rbind(xys,temp) } } ddf - datadist(xysf - as.data.frame(xys)) # Sorry. There was a single line omitted: options(datadist=ddf) olsfit - ols(V3~rcs(V1,3)+rcs(V2,3), data=xysf) bounds - perimeter(xysf$V1, xysf$V2) plot(xysf$V1, xysf$V2) #demonstrates the extent of the data bplot(Predict(olsfit, V1,V2), perim=bounds) # a levelplot is the default bplot(Predict(olsfit, V1,V2), perim=bounds, lfun=contourplot) bplot(Predict(olsfit, V1,V2), perim=bounds, lfun=contourplot, xlim=c(-2.5,2.5)) # to demonstrate that perimeter works If you do not need a statistical approach to the contour plot, then Jim Lemon's more recent suggestion this morning may be more economical. -- David. __ 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 to save R file into specific type
On Oct 25, 2010, at 1:07 AM, zhiji19 wrote: Hello everyone Can you please teach me how to save my homework as .R file? ?savehistory # at least on a Mac (If you wanted the whole console session with output, then it would be select-all, copy, paste into a text editor, save as a text file.) You can also save named functions with save() and then bring back in with load(). -- David. I write my code in RGui. When I tried to save my work, the RGui only allows me to save it as .RData. Is there any difference between .R and .RData? By the way, after I save my work as .RData, I cannot reopen it. when I open it, only one message comes out as following: ARGUMENT_ignored_. -- View this message in context: http://r.789695.n4.nabble.com/How-to-save-R-file-into-specific-type-tp3009879p3009879.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] Q reg connecting to existing dll
Hi, I am an R newbie and trying to migrate from VB to R. I downloaded data from Haver using an existing dll in VB. For e.g. I declared functions such as Private Declare Function DLXOpenDatabase Lib DLXAPI32 (ByVal DBName$) As Long And then used them as k = DLXOpenDatabase(W:/DLX/USECON) MsgBox (k) Gives me '0' showing connection established Now I am rying to migrate this code to R and was wondering what is the easiest way to call an external dll in R. During my research I found this link http://www.stats.uwo.ca/faculty/murdoch/software/compilingDLLs/existingD LL.html But it seems to be old with expired links to further help pages. Can any one guide me on how best to connect to external dll's from R and if there is any easier way than writing a wrapper dll ? Thanks Puneet -- This message w/attachments (message) is intended solely ...{{dropped:7}} __ 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] R-Fortran question (multiple subroutines)
Berwin A Turlach wrote: Remko Duursma wrote: [...] I.e, my code looks something like this: subroutine f(x,y,z) call g(x,y,z) end subroutine g(x,y,z) z = x*y end calling this from R shows that subroutine g is not called. The code compiled as executable works fine. There are no such limitations imposed by R. I'd suggest your diagnosis of the problem is wrong. If you can't spot the problem, please post a real example (simplified if possible, but not as much as the one above). Actually, it turns out that this example is simplified enough. :) I put this snippet into a file, compiled it via R CMD SHLIB, loaded it into R and then was very surprised about the result of .Fortran(f, x=1.1, y=2.2, z=0.0). Eventually it dawned to me, Remko needs to read the table in section 5.2 of Writing R Extensions. The simple fix in this case is to put a double precision x, y, z at the beginning of each subroutine. The default precision in FORTRAN is not double precision, that's why the code seems to work when compiled as stand alone but not when called from R. In general, I would recommend to start each subroutine with implicit none (o.k., I know that this is not standard FORTRAN77 but most compiler support that construct; the alternative, that would confrom with the FORTRAN77 standard, is to declare everything to be implicitly of type character and then let the fun begin) and then to explicitly declare all variables to be of the appropriate type. I alway look for a command line option for the fortran compiler to achieve the implicit none. gfortran has the option -fimplicit-none. I try to always use it. For R package building I start out with using the implicit-none option and comment it out in the makevars only in the final stage when R warns me about non standard options. Berend -- View this message in context: http://r.789695.n4.nabble.com/R-Fortran-question-multiple-subroutines-tp3009729p3010385.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] lowess() won't handle NAs
Dear Masters, I'm driving crazy with the lowess() function my intent is smoothing confidence intervals for predicted y values in a linear model lm() setting since in the predict() function there exists an option for predicting NA values, I instead encounter problems when I fit a missing values x variable to the predicted terms.,impossible task!!! I've been banging on my head all morning, I can't find a solution also using a loess() I can't get the function to keep the x missing values with the result that it automaticaly drop 'em, so that the smoothing looks like a mess in the plot I attach my scripts, a function that would automatize the process explained above #d = a data.frame with some Na #c1,c2 =column indexes regr.plot-function(d,c1,c2, method=c(spearman,pearson),titolo,xtag,ytag,livello){ test-cor.test(d[,c2],d[,c1],method=spearman) pval-round(test$p.val,4) corr-round(test$estimate,4) I-predict(lm(d[,c1]~d[,c2]),newdata=d,interval=confidence,level=livello) plot(d[,c2],d[,c1],xlab=as.character(xtag),ylab=as.character(ytag)) title(as.character(titolo),font=3) abline(lm(d[,c1]~d[,c2]),lwd=2,col=red) #lines(loess(I[,2]~d[,c2])#,data=d,control =loess.control(surface = direct) #,na.action=na.omit(d[,c2]) #,lty=2,lwd=2,col=blue) #lines(loess(I[,3]~d[,c2])#,data=d,control =loess.control(surface = direct) #,na.action=na.omit(d[,c2]) #,lty=2,lwd=2,col=blue) lines(lowess(d[,c2],I[,2]),lty=2,lwd=2,col=blue) lines(lowess(d[,c2],I[,3]),lty=2,lwd=2,col=blue) text(locator(1),as.expression(substitute(r==corr),list(corr=corr)), cex=1.5,font=3) if(pval==0){ text(locator(1),expression(p0.001), cex=1.5,font=3) }else{ text(locator(1),as.expression(substitute(p==pval),list(pval=pval)), cex=1.5,font=3) } } #THANK U 4 THE EVENTUAL ADVISE.!! Federico, Student of Statistics at Milano-Bicocca [[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] help on lme extraction
Dear R list, I need some help in extracting comparisons in the result of lme. I have a data set similar to the example data, Orthodont, using patient subject as a random effect and did something below: library(nlme) library(gregmisc) data(Orthodont) Orthodont$AgeGroup - gtools::quantcut(Orthodont$age) fm2 - lme(distance ~ AgeGroup + Sex + AgeGroup*Sex, data = Orthodont, random = ~1|Subject) fit.contrast(fm2, Sex, c(-1,1), conf=0.95) fit.contrast(fm2, AgeGroup, rbind(1 vs 2=c(-1,1,0,0), 2 vs 3=c(0,-1,1,0)), conf=0.95) But how can I compare different age groups among Male, Female or between Male and Female as illustrated below: ## among Male Male Female [1,] -1 0 [2,]1 0 [3,]0 0 [4,]0 0 ## among Female Male Female [1,]0 0 [2,]0 -1 [3,]0 0 [4,]0 1 ## between Male and Female Male Female [1,] -1 0 [2,]0 0 [3,]0 0 [4,]0 1 I'll greatly appreciate it if you may help! JP Jin Ph.D. Bioinformatics scientist Center for Bioinformatics UNC at Chapel Hill Chapel Hill, NC US [[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] Using R with Google Storage/Big Query and Prediction API
Dear List Google has new beta lists for storage, querying and prediction at http://code.google.com/apis/predict/docs/getting-started.html http://code.google.com/apis/predict/docs/getting-started.html http://code.google.com/apis/bigquery/docs/getting-started.html#intro http://code.google.com/apis/bigquery/docs/getting-started.html#introand http://code.google.com/apis/storage/ http://code.google.com/apis/storage/Most of these require interaction with CURL I know RCurl allows data interaction with http pages ( http://www.omegahat.org/RCurl/) Has anyone tried this with the new Google APIS- they are free as of now- and invitation list /beta Regards Ajay Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri [[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] non-stationary ar part in css
Hi I would like to use arima () to find the best arima model for y time series. The default in arima apparently is to use conditional sum of squares to find the starting values and then ML (as described on the help page). Now using the default may lead to error messages saying: non-stationary ar part in CSS. When changeing the default to ML only the minimization works. As far as I understand, arima doesn't require stationarity, but apparently CSS does. Can anyone tell me what exactly the css method does? And why is CSS-ML the default in R? Out of efficiency reasons? Because ML and ML-CSS gives the exact same estimates when applied to the same data. I tried to find out on google but I couldnt' find anything usefull or understandable to me as a non-statistician. Here some data that causes the error message: X-6.841067, 6.978443, 6.984755, 7.007225, 7.161198, 7.169790, 7.251534, 7.336429, 7.356600, 7.413271, 7.404165, 7.480869, 7.498686, 7.429809, 7.302747, 7.168251, 7.124798, 7.094881, 7.119132, 7.049250, 6.961049, 7.013442, 6.915243, 6.758036, 6.665078, 6.730523, 6.702005, 6.905522, 7.005191, 7.308986) model.examp-arima(X,order=c(7,0,0),include.mean=T)# gives an error model.examp-arima(X,order=c(7,0,0),include.mean=T,method=ML) # gives no error Any help on this would be most appreciated Many thanks fo the help best wishes Benedikt __ 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] structural equation modeling in sem, error, The model has negative degrees of freedom = -3, and The model is almost surely misspecified...
Dear Alex, Your problem doesn't have much to do with the sem package. The model that you're trying to estimate is grossly underidentified. The model has 9 parameters to estimate and there are only 3*4/2 = 6 covariances among the 3 observed variables, hence the -3 df. There are also no exogenous variables in the model, since you specified that dec is correlated with the structural disturbances for density and ALL-Jack1. Regards, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alex Anderson Sent: October-25-10 2:19 AM To: r-help@r-project.org Subject: [R] structural equation modeling in sem, error, The model has negative degrees of freedom = -3, and The model is almost surely misspecified... Hi all, I am attempting to learn my way through the sem package by constructing a simple structural model for some of my data on bird diversity, abundance, and primary productivity. I have constructed a covariance matrix between these variables as per the following: S_matrix = matrix(c( + 0.003083259, 0, 0, + 0.143870284, 89.7648490, 0, + 0.276950919, 81.3484101, 215.3570157 ), ncol = 3, byrow = T) rownames(S_matrix) = colnames(S_matrix) = c(dec_mean_EVI, density, ALL_Jack1) I then construct a model using a symbolic ram specification as follows tmodel - specify.model() dec_mean_EVI - density, gam1, NA density - ALL_Jack1, gam2, NA dec_mean_EVI - ALL_Jack1, gam3, NA dec_mean_EVI - dec_mean_EVI, ps1, NA density - density, ps2, NA ALL_Jack1 - ALL_Jack1, theta1, NA dec_mean_EVI - density, theta2, NA dec_mean_EVI - ALL_Jack1, theta2, NA density - ALL_Jack1, theta3, NA I then try to run the sem analysis using the matrix and model. sem_1 - sem(ram = tmodel, S = S_matrix, N = 88, fixed.x = c(dec_mean_EVI)) summary(sem_1) However, I only get the following error message: Error in sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : The model has negative degrees of freedom = -3 In addition: Warning message: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : The following variables have no variance or error-variance parameter (double-headed arrow): density, ALL_Jack1, dec_mean_EVI, density, density, ALL_Jack1 The model is almost surely misspecified; check also for missing covariances. It must be obvious to those experienced with sem, but I can't yet see where I have gone wrong in constructing my matrix or model, any thoughts would be much appreciated. thanks in advance, Alex __ 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-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] lowess() won't handle NAs
Try using the loess() function instead - it has an na.action parameter that should be able to handle your problem. -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly [[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] Mixed-effects model for overdispersed count data?
Hi, I have to analyse the number of provisioning trips to nestlings according to a number of biological and environmental factors. I was thinking of building a mixed-effects model with species and nestid as random effects, using a Poisson distribution, but the data are overdispersed (variance/mean = 5). I then thought of using a mixed-effects model with negative binomial distribution, but I have 2 problems: 1- The only package building mixed models with neg. bin. distribution I found is the package glmmADMB but I have a hard time understanding the output. Anyone knows of a R package with an output that gives p values? 2- Two people I asked advice to told me that I should use either a mixed-effect model with a Poisson distribution (the random effects will take care of the overdispersion) OR a glm using neg. bin. distribution but not both at the same time, which would be unnecessary. Any advice is welcome! Thank you Marie-Helene Hachey M.Sc. student Universite Laval, Quebec __ 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] 140 packages in R Commander!!
Hi John Its not the download I mind - it's a one shot thing- Could you think of integrating the help across plugins- that can help. For example I really want to know which plugin would use snow and foreach if at all Ajay Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri On Mon, Oct 25, 2010 at 4:54 AM, John Fox j...@mcmaster.ca wrote: Dear Ajay, This is a consequence of installing the dependencies (including suggested packages, etc.) of the Rcmdr package, their dependencies, and so on recursively. The alternative would be for the Rcmdr package to specify its direct dependencies via depends rather than suggests, but then these dependencies would be loaded whenever the Rcmdr is loaded. If you have a better idea, I'm certainly open to it, since many, probably most, of the packages that get installed aren't really needed by the Rcmdr or by the packages on which it directly depends. The whole business takes about 10 minutes on my not-all-that-fast Internet connection and occupies about 250 MB (considerably less than 10 US cents at today's hard-disk prices), which doesn't seem terrible to me. Best, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ajay Ohri Sent: October-24-10 12:47 PM To: R-help@r-project.org Subject: [R] 140 packages in R Commander!! Dear List I just downloaded and installed R 2.12.0 and then installed R Commander . First it got RCmdr and Car, and then suggested for other packages for utilizing the full functionality- I clicked yes! I got 140 packages installed!!! Cran Mirror was UCLA... Here is the list. Is this intentional- I can see some packages like snow and multicore which are desirable but quite optional.(see list below) Regards Ajay 'slam' 'fBasics' 'bitops' 'Rglpk' 'snowFT' 'rlecuyer' 'rsprng' 'nws' 'tweedie' 'gtools' 'gdata' 'caTools' 'Ecdat' 'ergm' 'latentnet' 'degreenet' 'shapes' 'snow' 'RColorBrewer' 'statmod' 'cubature' 'kinship' 'gam' 'tripack' 'akima' 'logspline' 'gplots' 'maxLik' 'miscTools' 'sem' 'rgdal' 'network' 'numDeriv' 'statnet' 'rgenoud' 'hexbin' 'ellipse' 'gclus' 'mlbench' 'randomForest' 'SparseM' 'Formula' 'ineq' 'mlogit' 'np' 'plm' 'pscl' 'quantreg' 'ROCR' 'sampleSelection' 'scatterplot3d' 'systemfit' 'truncreg' 'urca' 'oz' 'fUtilities' 'fEcofin' 'RUnit' 'quadprog' 'iterators' 'locfit' 'maps' 'rcom' 'rscproxy' 'sp' 'VGAM' 'MCMCpack' 'sna' 'gee' 'anchors' 'survey' 'ape' 'flexmix' 'rmeta' 'mlmRev' 'MEMSS' 'coda' 'party' 'ipred' 'modeltools' 'e1071' 'AER' 'bdsmatrix' 'DAAG' 'fCalendar' 'fSeries' 'fts' 'its' 'timeDate' 'timeSeries' 'tis' 'tseries' 'xts' 'foreach' 'TSA' 'RSQLite' 'tkrplot' 'sgeostat' 'mapproj' 'tcltk2' 'R2wd' 'png' 'tree' 'VIM' 'mitools' 'Zelig' 'HSAUR' 'mvtnorm' 'lme4' 'robustbase' 'mboost' 'coin' 'xtable' 'sandwich' 'coxme' 'zoo' 'strucchange' 'dynlm' 'biglm' 'chron' 'acepack' 'TeachingDemos' 'Design' 'mice' 'subselect' 'kernlab' 'vcd' 'rgl' 'relimp' 'multcomp' 'lmtest' 'leaps' 'Hmisc' 'effects' 'colorspace' 'aplpack' 'abind' 'RODBC' car Rcmdr Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri On Sun, Oct 24, 2010 at 9:27 PM, Marcelo Lima mlim...@gmail.com wrote: Hi all, I generated a covariance matrix and visualized as a 2D contour plot (x,y, covariance matrix), I would like to extract from the matrix the values ( in x and y) that auto-correlate which I will plot as an normal (x,y(being the values that auto-corelate to a certain x and y values in my original matrix). Any suggestions? Cheers, Marcelo -- Marcelo Andrade de Lima UNIFESP - Universidade Federal de Sco Paulo Departamento de Bioqummica Disciplina de Biologia Molecular Rua Trjs de Maio 100, 4 andar - Vila Clementino, 04044-020 Lab +55 11 55764438 R.1188 Cell +55 11 92725274 ml...@unifesp.br [[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]] [[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] 140 packages in R Commander!!
Dear Ajay, Each of the Rcmdr plug-ins is an R package with its own dependencies, which you can check on CRAN. Since dependencies can have dependencies, etc., you'd have to be careful in drawing conclusions. I'm not sure what the help system has to do with it. Best, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: Ajay Ohri [mailto:ohri2...@gmail.com] Sent: October-25-10 11:17 AM To: John Fox Cc: R-help@r-project.org Subject: Re: [R] 140 packages in R Commander!! Hi John Its not the download I mind - it's a one shot thing- Could you think of integrating the help across plugins- that can help. For example I really want to know which plugin would use snow and foreach if at all Ajay Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri On Mon, Oct 25, 2010 at 4:54 AM, John Fox j...@mcmaster.ca wrote: Dear Ajay, This is a consequence of installing the dependencies (including suggested packages, etc.) of the Rcmdr package, their dependencies, and so on recursively. The alternative would be for the Rcmdr package to specify its direct dependencies via depends rather than suggests, but then these dependencies would be loaded whenever the Rcmdr is loaded. If you have a better idea, I'm certainly open to it, since many, probably most, of the packages that get installed aren't really needed by the Rcmdr or by the packages on which it directly depends. The whole business takes about 10 minutes on my not-all-that-fast Internet connection and occupies about 250 MB (considerably less than 10 US cents at today's hard-disk prices), which doesn't seem terrible to me. Best, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Ajay Ohri Sent: October-24-10 12:47 PM To: R-help@r-project.org Subject: [R] 140 packages in R Commander!! Dear List I just downloaded and installed R 2.12.0 and then installed R Commander . First it got RCmdr and Car, and then suggested for other packages for utilizing the full functionality- I clicked yes! I got 140 packages installed!!! Cran Mirror was UCLA... Here is the list. Is this intentional- I can see some packages like snow and multicore which are desirable but quite optional.(see list below) Regards Ajay 'slam' 'fBasics' 'bitops' 'Rglpk' 'snowFT' 'rlecuyer' 'rsprng' 'nws' 'tweedie' 'gtools' 'gdata' 'caTools' 'Ecdat' 'ergm' 'latentnet' 'degreenet' 'shapes' 'snow' 'RColorBrewer' 'statmod' 'cubature' 'kinship' 'gam' 'tripack' 'akima' 'logspline' 'gplots' 'maxLik' 'miscTools' 'sem' 'rgdal' 'network' 'numDeriv' 'statnet' 'rgenoud' 'hexbin' 'ellipse' 'gclus' 'mlbench' 'randomForest' 'SparseM' 'Formula' 'ineq' 'mlogit' 'np' 'plm' 'pscl' 'quantreg' 'ROCR' 'sampleSelection' 'scatterplot3d' 'systemfit' 'truncreg' 'urca' 'oz' 'fUtilities' 'fEcofin' 'RUnit' 'quadprog' 'iterators' 'locfit' 'maps' 'rcom' 'rscproxy' 'sp' 'VGAM' 'MCMCpack' 'sna' 'gee' 'anchors' 'survey' 'ape' 'flexmix' 'rmeta' 'mlmRev' 'MEMSS' 'coda' 'party' 'ipred' 'modeltools' 'e1071' 'AER' 'bdsmatrix' 'DAAG' 'fCalendar' 'fSeries' 'fts' 'its' 'timeDate' 'timeSeries' 'tis' 'tseries' 'xts' 'foreach' 'TSA' 'RSQLite' 'tkrplot' 'sgeostat' 'mapproj' 'tcltk2' 'R2wd' 'png' 'tree' 'VIM' 'mitools' 'Zelig' 'HSAUR' 'mvtnorm' 'lme4' 'robustbase' 'mboost' 'coin' 'xtable' 'sandwich' 'coxme' 'zoo' 'strucchange' 'dynlm' 'biglm' 'chron' 'acepack' 'TeachingDemos' 'Design' 'mice' 'subselect' 'kernlab' 'vcd' 'rgl' 'relimp' 'multcomp' 'lmtest' 'leaps' 'Hmisc' 'effects' 'colorspace' 'aplpack' 'abind' 'RODBC' car Rcmdr Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri On Sun, Oct 24, 2010 at 9:27 PM, Marcelo Lima mlim...@gmail.com wrote: Hi all, I generated a covariance matrix and visualized as a 2D contour plot (x,y, covariance matrix), I would like to extract from the
[R] extracting characteristics of datasets from data()
I can use data() to find the available datasets in a package, but I'd like to extract and display some additional information for each dataset than what is provided by data(), e.g., class() and dim() for datasets for which these are available. I'm stuck on using using lapply properly with objects, rather than the names of objects that I get from data() Example: DS - data(package=vcdExtra) DS$results[,c(Item, Title)] Item Title [1,] AbortionAbortion Opinion Data [2,] BartlettBartlett data on plum root cuttings [3,] Caesar Risk Factors for Infection in Caesarian Births [4,] Cancer Survival of Breast Cancer Patients [5,] Detergent Detergent preference data [6,] DykeSources of knowledge of cancer [7,] GSS General Social Survey-- Sex and Party affiliation [8,] Gilby Clothing and Intelligence Rating of Children [9,] Heart Sex, Occupation and Heart Disease [10,] Heckman Labour Force Participation of Married Women 1967-1971 [11,] HoytMinnesota High School Graduates [12,] ICU Death in the ICU [13,] JobSat Cross-classification of job satisfaction by income [14,] Mental Mental impariment and parents SES [15,] MobilitySocial Mobility data [16,] TV TV Viewing Data [17,] Vietnam Student Opinion About the War in Vietnam [18,] Yamaguchi87 Occupational Mobility in Three Countries unlist(lapply(as.list(DS$results[,c(Item) ]), FUN=class)) [1] character character character character character character character [8] character character character character character character character [15] character character character character Wanted: something like the results of doing class(Abortion) [1] table dim(Abortion) [1] 2 2 2 class(Mental) [1] data.frame dim(Mental) [1] 24 3 for all datasets in Item, giving a display like Item class dim Title Abortion table 2x2x2 Abortion Opinion Data Mentaldata.frame 24x2Mental impariment and parents SES -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ 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] zoo.read intraday data
Thanks, by now I ran already into the next problem, while trying to convert the zoo to an xts object. Somehow the timestamps get lost, no idea why. I did read through the vignettes, but got confused by all this, chron, as.POSIXct, zoo and xts stuff. with your example I got: Error in .subset(x, j) : invalid subscript type 'list' best regards - # TODO: Add comment # # Author: flyingimmi ### L - Date,Time,Open,High,Low,Close,Up,Down 05.02.2001,00:30,421.20,421.20,421.20,421.20,11,0 05.02.2001,01:30,421.20,421.40,421.20,421.40,7,0 06.02.2001,02:00,421.30,421.30,421.30,421.30,0,5 05.02.2001,02:30,421.60,421.60,421.50,421.50,26,1 library(zoo) library(chron) f - function(x) chron(paste(x[,1]), paste(x[,2], 00, sep = :), format = c(dates = d.m.y, times = h:m:s)) # z - read.zoo(myfile.csv, index = 1:2, sep=,, header = TRUE, FUN = f) z - read.zoo(textConnection(L), index = 1:2, sep=,, header = TRUE, FUN = f) intradayData - xts(z, time(z)) print(z) print(intradayData) --- output: Open High Low Close Up Down (05.02.01 00:30:00) 421.2 421.2 421.2 421.2 110 (05.02.01 01:30:00) 421.2 421.4 421.2 421.4 70 (05.02.01 02:30:00) 421.6 421.6 421.5 421.5 261 (06.02.01 02:00:00) 421.3 421.3 421.3 421.3 05 Open High Low Close Up Down NA 421.2 421.2 421.2 421.2 110 NA 421.2 421.4 421.2 421.4 70 NA 421.6 421.6 421.5 421.5 261 NA 421.3 421.3 421.3 421.3 05 On 10/25/2010 03:47 PM, Gabor Grothendieck wrote: On Mon, Oct 25, 2010 at 9:02 AM, Immanuel mane.d...@googlemail.com wrote: Hello all, I'm trying to use zoo.read but can't figure out how to deal with the time format. (example below) would be nice if someone could help. best regards, Immanuel --- L - Date,Time,Open,High,Low,Close,Up,Down 05.02.2001,00:30,421.20,421.20,421.20,421.20,11,0 05.02.2001,01:30,421.20,421.40,421.20,421.40,7,0 05.02.2001,02:00,421.30,421.30,421.30,421.30,0,5 05.02.2001,02:30,421.60,421.60,421.50,421.50,26,1 library(zoo) library(chron) f - function(x) chron(paste(x[,1]),paste(x[,2]), format = c(dates = D.M.Y, times = hh:mm)) z - read.zoo(textConnection(L), index = 1:2, sep=,, header = TRUE, FUN = f) print(z) Here are a few more possibilities: # use chron appending seconds and index = list(1, 2) f - function(d, t, format = c(m.d.y, h:m:s)) { chron(d, paste(t, 00, sep = :), format = format) } z - read.zoo(textConnection(L), index = list(1, 2), sep=,, header = TRUE, FUN = f) # use as.chron and index = list(1, 2) f2 - function(d, t, format = %d.%m.%Y %H:%M) { as.chron(paste(d, t), format = format) } z2 - read.zoo(textConnection(L), index = list(1, 2), sep=,, header = TRUE, FUN = f) __ 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] Mixed-effects model for overdispersed count data?
Marie-Hélène Hachey marie_helene48 at hotmail.com writes: Hi, I have to analyse the number of provisioning trips to nestlings according to a number of biological and environmental factors. I was thinking of building a mixed-effects model with species and nestid as random effects, using a Poisson distribution, but the data are overdispersed (variance/mean = 5). I then thought of using a mixed-effects model with negative binomial distribution, but I have 2 problems: 1- The only package building mixed models with neg. bin. distribution I found is the package glmmADMB but I have a hard time understanding the output. Anyone knows of a R package with an output that gives p values? 2- Two people I asked advice to told me that I should use either a mixed-effect model with a Poisson distribution (the random effects will take care of the overdispersion) OR a glm using neg. bin. distribution but not both at the same time, which would be unnecessary. Several pieces of advice: * this question is probably most appropriate for r-sig-mixed-models (or perhaps r-sig-ecology) * glmmADMB is admittedly a bit scratchy at the moment, but you may not find a package that gives much easier-to-understand output -- almost all packages will give output in terms of fixed effect coefficients, standard errors, and variances/covariances/standard deviations of random effects. * you might want to consider Poisson-lognormal models instead, which allow for overdispersion and are a bit easier to fit in the context of mixed models, by defining an individual-level random effect: see e.g. Elston, D. A., R. Moss, T. Boulinier, C. Arrowsmith, and X. Lambin. 2001. Analysis of Aggregation, a Worked Example: Numbers of Ticks on Red Grouse Chicks. Parasitology 122, no. 05: 563-569. doi:10.1017/S0031182001007740. http://journals.cambridge.org/action/displayAbstract?fromPage=onlineaid=82701. Such models can be fitted in (at least) MCMCglmm and recent versions of glmer. * p values will be tricky indeed. sorry about that. * as to the advice about using either mixed models or NB models but not both -- that's an empirical question. It may indeed be the case that one or the other takes care of the overdispersion, but you won't know until you try. It is certainly possible to have overdispersion even within a species/nestid combination. I would suggest http://glmm.wikidot.com/faq as a starting point for further reading ... good luck __ 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] zoo.read intraday data
On Mon, Oct 25, 2010 at 11:44 AM, Immanuel mane.d...@googlemail.com wrote: Thanks, by now I ran already into the next problem, while trying to convert the zoo to an xts object. Somehow the timestamps get lost, no idea why. I did read through the vignettes, but got confused by all this, chron, as.POSIXct, zoo and xts stuff. with your example I got: Error in .subset(x, j) : invalid subscript type 'list' best regards - # TODO: Add comment # # Author: flyingimmi ### L - Date,Time,Open,High,Low,Close,Up,Down 05.02.2001,00:30,421.20,421.20,421.20,421.20,11,0 05.02.2001,01:30,421.20,421.40,421.20,421.40,7,0 06.02.2001,02:00,421.30,421.30,421.30,421.30,0,5 05.02.2001,02:30,421.60,421.60,421.50,421.50,26,1 library(zoo) library(chron) f - function(x) chron(paste(x[,1]), paste(x[,2], 00, sep = :), format = c(dates = d.m.y, times = h:m:s)) # z - read.zoo(myfile.csv, index = 1:2, sep=,, header = TRUE, FUN = f) z - read.zoo(textConnection(L), index = 1:2, sep=,, header = TRUE, FUN = f) intradayData - xts(z, time(z)) print(z) print(intradayData) --- output: Open High Low Close Up Down (05.02.01 00:30:00) 421.2 421.2 421.2 421.2 11 0 (05.02.01 01:30:00) 421.2 421.4 421.2 421.4 7 0 (05.02.01 02:30:00) 421.6 421.6 421.5 421.5 26 1 (06.02.01 02:00:00) 421.3 421.3 421.3 421.3 0 5 Open High Low Close Up Down NA 421.2 421.2 421.2 421.2 11 0 NA 421.2 421.4 421.2 421.4 7 0 NA 421.6 421.6 421.5 421.5 26 1 NA 421.3 421.3 421.3 421.3 0 5 I don't think xts supports chron. Try using POSIXct instead: f3 - function(...) as.POSIXct(paste(...), format = %d.%m.%Y %H:%M) z3 - read.zoo(textConnection(L), index = list(1, 2), sep=,, header = TRUE, FUN = f3) as.xts(z3) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] building lme call via call()
dear all, I would like to get the lme call without fitting the relevant model. library(nlme) data(Orthodont) fm1 - lme(distance ~ age, random=list(Subject=~age),data = Orthodont) To get fm1$call without fitting the model I use call(): my.cc-call(lme.formula, fixed= distance ~ age, random = list(Subject = ~age)) However the two calls are not the same (apart from the data argument I am not interested in), as call() *does* evaluate the arguments: my.cc$random $Subject ~age fm1$call$random list(Subject = ~age) How is it possible to get the right call (similar to the one from fm1$call) by means of call()? thanks, vito -- Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Università di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 23895240 fax: 091 485726/485612 http://dssm.unipa.it/vmuggeo __ 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] extracting characteristics of datasets from data()
Michael writes: I can use data() to find the available datasets in a package, but I'd like to extract and display some additional information for each dataset than what is provided by data(), e.g., class() and dim() for datasets for which these are available. ... for all datasets in Item, giving a display like Item class dim Title Abortion table 2x2x2 Abortion Opinion Data Mentaldata.frame 24x2Mental impariment and parents SES This seems to work on your example: require('vcdExtra') ds - as.data.frame(data(package=vcdExtra)$results[,c('Item','Title')], stringsAsFactors=FALSE) ds$dim - lapply(ds$Item, function(x) { paste(dim(get(x)), collapse='x') } ) ds$class - lapply(ds$Item, function(x) { class(get(x)) } ) ds - ds[c('Item','class','dim','Title')] Thanks for the fun exercise. I've just started looking at the various 'apply-oid' functions, having spent much of my time with aggregate() and perhaps having my imagination stunted. cur -- Curt Seeliger, Data Ranger Raytheon Information Services - Contractor to ORD seeliger.c...@epa.gov 541/754-4638 [[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] finding the year of a date
I know that I can use as.yearmon in the package zoo to find the year and the month of a date. I can use as. yearqtr to find the year and the quarter. But how can one find just the year of a date? Thanks a lot! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] finding the year of a date
Try this: format(Sys.Date(), %Y) On Mon, Oct 25, 2010 at 2:38 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: I know that I can use as.yearmon in the package zoo to find the year and the month of a date. I can use as. yearqtr to find the year and the quarter. But how can one find just the year of a date? Thanks a lot! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] finding the year of a date
On Mon, Oct 25, 2010 at 12:38 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: I know that I can use as.yearmon in the package zoo to find the year and the month of a date. I can use as. yearqtr to find the year and the quarter. But how can one find just the year of a date? Thanks a lot! Here are three ways. The first uses the fact that the year is the whole number part of a yearmon object. library(zoo) d - Sys.Date() floor(as.numeric(as.yearmon(d))) [1] 2010 as.numeric(format(d, %Y)) [1] 2010 as.POSIXlt(d)$year + 1900 [1] 2010 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question on passing the subset argument to an lm wrapper
On Sun, 24 Oct 2010, Erik Iverson wrote: Hello, How would you go about handling the following situation? This is on R 2.12.0 on Ubuntu 32-bit. I have a wrapper function to lm. I want to pass in a subset argument. First, I just thought I'd use The subset arg needs to be unevaluated until lm() - or whatever function - is called in your function. The canonical advice for this kind of question about passing unevaluated args is to study the first lines of the function lm noting what it does with objects cl - match.call() and mf - match.call( expand.dots = FALSE ). Something like this might be what you want: testlm2 - function(formula, ...) { mc - match.call() mc[[1]] - as.name('lm') eval(mc) } testlm2(bmi ~ age, data= df1, subset = age 50) HTH, Chuck ## make example reproducible set.seed(123) df1 - data.frame(age = rnorm(100, 50, 10), bmi = rnorm(100, 30, sd = 2)) ## create a wrapper using ... testlm - function(formula, ...) { lm(formula, data = df1, ...) } testlm(bmi ~ age, subset = age 50) Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in I found some other examples of this error message, but couldn't piece together how it fits in with this example. Next, I tried specifying a subset argument. testlm2 - function(formula, subset) { lm(formula, data = df1, subset = subset) } testlm2(bmi ~ age, subset = age 50) Error in xj[i] : invalid subscript type 'closure' I also don't understand this one. Any pointers on if I'm just missing the easy solution to do what I want? Any explanations as to the above behavior (I know it has to do with model.frame, but not sure how) would also be greatly appreciated! Thanks! --Erik __ 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. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ 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] Question on passing the subset argument to an lm wrapper
As workaround you can try this: testlm - function(formula, ...) { args - list(formula, data = df1, ...) do.call(lm, args) } testlm(bmi ~ age, subset = df1$age 50) On Mon, Oct 25, 2010 at 2:16 AM, Erik Iverson er...@ccbr.umn.edu wrote: Hello, How would you go about handling the following situation? This is on R 2.12.0 on Ubuntu 32-bit. I have a wrapper function to lm. I want to pass in a subset argument. First, I just thought I'd use ## make example reproducible set.seed(123) df1 - data.frame(age = rnorm(100, 50, 10), bmi = rnorm(100, 30, sd = 2)) ## create a wrapper using ... testlm - function(formula, ...) { lm(formula, data = df1, ...) } testlm(bmi ~ age, subset = age 50) Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in I found some other examples of this error message, but couldn't piece together how it fits in with this example. Next, I tried specifying a subset argument. testlm2 - function(formula, subset) { lm(formula, data = df1, subset = subset) } testlm2(bmi ~ age, subset = age 50) Error in xj[i] : invalid subscript type 'closure' I also don't understand this one. Any pointers on if I'm just missing the easy solution to do what I want? Any explanations as to the above behavior (I know it has to do with model.frame, but not sure how) would also be greatly appreciated! Thanks! --Erik __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] dataframe, transform, strsplit
Hi, I have a dataframe that has a column of vectors that I need to extract off the character string before the first '.' character and put it into a separate column. I thought I could use 'strsplit' for it within 'transform', but I can't seem to get the right invocation. Here is a sample dataframe that has what I have, what I want, and what I get. Can someone tell me how to get what is in the 'want' column from the 'have' column programatically? tia, Matt df - data.frame(have=c(a.b.c, d.e.f, g.h.i), want=c(a,d,g)) df.xform - transform(df, get=strsplit(as.character(have), split=., fixed=TRUE)[[1]][1]) df.xform [[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] Hausman Test
Hi, I'm trying to conduct a Hausman test to choose between FE estimators and RE estimators. When I run the code, I get an error: Error in solve.default(dvcov) : system is computationally singular: reciprocal condition number = 3.7981e-22 Can someone please help me with this problem? ~ Amrita [[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] dataframe, transform, strsplit
try this: df have want 1 a.b.ca 2 d.e.fd 3 g.h.ig df$get - gsub(^([^.]+).*, \\1, df$have) df have want get 1 a.b.ca a 2 d.e.fd d 3 g.h.ig g On Mon, Oct 25, 2010 at 12:53 PM, Matthew Pettis matthew.pet...@gmail.com wrote: Hi, I have a dataframe that has a column of vectors that I need to extract off the character string before the first '.' character and put it into a separate column. I thought I could use 'strsplit' for it within 'transform', but I can't seem to get the right invocation. Here is a sample dataframe that has what I have, what I want, and what I get. Can someone tell me how to get what is in the 'want' column from the 'have' column programatically? tia, Matt df - data.frame(have=c(a.b.c, d.e.f, g.h.i), want=c(a,d,g)) df.xform - transform(df, get=strsplit(as.character(have), split=., fixed=TRUE)[[1]][1]) df.xform [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] dataframe, transform, strsplit
On Mon, Oct 25, 2010 at 12:53 PM, Matthew Pettis matthew.pet...@gmail.com wrote: Hi, I have a dataframe that has a column of vectors that I need to extract off the character string before the first '.' character and put it into a separate column. I thought I could use 'strsplit' for it within 'transform', but I can't seem to get the right invocation. Here is a sample dataframe that has what I have, what I want, and what I get. Can someone tell me how to get what is in the 'want' column from the 'have' column programatically? tia, Matt df - data.frame(have=c(a.b.c, d.e.f, g.h.i), want=c(a,d,g)) df.xform - transform(df, get=strsplit(as.character(have), split=., fixed=TRUE)[[1]][1]) df.xform Try replacing the dot [.] and everything thereafter .* with nothing like this: transform(df, want = sub([.].*, , have)) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dataframe, transform, strsplit
Thanks Gabor and Jim, Both solutions worked equally well for me (now I have an embarrassment of riches for a solution :-) ). Now that my main problem is solved, I am happy, but I was wondering if anyone would care to comment as to why my 'strsplit' solution doesn't behave the way I think it should... Thank you both again, Matt On Mon, Oct 25, 2010 at 12:09 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Mon, Oct 25, 2010 at 12:53 PM, Matthew Pettis matthew.pet...@gmail.com wrote: Hi, I have a dataframe that has a column of vectors that I need to extract off the character string before the first '.' character and put it into a separate column. I thought I could use 'strsplit' for it within 'transform', but I can't seem to get the right invocation. Here is a sample dataframe that has what I have, what I want, and what I get. Can someone tell me how to get what is in the 'want' column from the 'have' column programatically? tia, Matt df - data.frame(have=c(a.b.c, d.e.f, g.h.i), want=c(a,d,g)) df.xform - transform(df, get=strsplit(as.character(have), split=., fixed=TRUE)[[1]][1]) df.xform Try replacing the dot [.] and everything thereafter .* with nothing like this: transform(df, want = sub([.].*, , have)) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com -- Seven Deadly Sins (Gandhi): - Wealth without work - Politics without principle - Pleasure without conscience - Commerce without morality - Science without humanity- Worship without sacrifice - Knowledge without character [[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] CRAN vs R-Forge
What's the difference between the packages you get from CRAN and R-Forge? Are the packages you get from CRAN fully developed and R-Forge work-in-progress? Regards, Jason [[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] dataframe, transform, strsplit
On Mon, Oct 25, 2010 at 1:20 PM, Matthew Pettis matthew.pet...@gmail.com wrote: Thanks Gabor and Jim, Both solutions worked equally well for me (now I have an embarrassment of riches for a solution :-) ). Now that my main problem is solved, I am happy, but I was wondering if anyone would care to comment as to why my 'strsplit' solution doesn't behave the way I think it should... Thank you both again, Matt On Mon, Oct 25, 2010 at 12:09 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Mon, Oct 25, 2010 at 12:53 PM, Matthew Pettis matthew.pet...@gmail.com wrote: Hi, I have a dataframe that has a column of vectors that I need to extract off the character string before the first '.' character and put it into a separate column. I thought I could use 'strsplit' for it within 'transform', but I can't seem to get the right invocation. Here is a sample dataframe that has what I have, what I want, and what I get. Can someone tell me how to get what is in the 'want' column from the 'have' column programatically? 1. split = . is a regular expression which means every character is a split character, not just dot. 2. Even if this is corrected picking off [[1]] means picking off the first element which would be c(a, b, c) whereas we want the first element of each component of the result, not the first element overall. A corrected version using the same approach looks like this: transform(df, want = sapply(strsplit(as.character(have), ., fixed = TRUE), [, 1)) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] extracting characteristics of datasets from data()
Try this: data(list = DS$results[,'Item'], package = 'vcdExtra', envir = ne - new.env()) cbind(do.call(rbind, eapply(ne, function(x)data.frame(class = class(x), dim = paste(dim(x), collapse = 'x', Title = DS$results[,'Title']) On Mon, Oct 25, 2010 at 1:45 PM, Michael Friendly frien...@yorku.ca wrote: I can use data() to find the available datasets in a package, but I'd like to extract and display some additional information for each dataset than what is provided by data(), e.g., class() and dim() for datasets for which these are available. I'm stuck on using using lapply properly with objects, rather than the names of objects that I get from data() Example: DS - data(package=vcdExtra) DS$results[,c(Item, Title)] Item Title [1,] AbortionAbortion Opinion Data [2,] BartlettBartlett data on plum root cuttings [3,] Caesar Risk Factors for Infection in Caesarian Births [4,] Cancer Survival of Breast Cancer Patients [5,] Detergent Detergent preference data [6,] DykeSources of knowledge of cancer [7,] GSS General Social Survey-- Sex and Party affiliation [8,] Gilby Clothing and Intelligence Rating of Children [9,] Heart Sex, Occupation and Heart Disease [10,] Heckman Labour Force Participation of Married Women 1967-1971 [11,] HoytMinnesota High School Graduates [12,] ICU Death in the ICU [13,] JobSat Cross-classification of job satisfaction by income [14,] Mental Mental impariment and parents SES [15,] MobilitySocial Mobility data [16,] TV TV Viewing Data [17,] Vietnam Student Opinion About the War in Vietnam [18,] Yamaguchi87 Occupational Mobility in Three Countries unlist(lapply(as.list(DS$results[,c(Item) ]), FUN=class)) [1] character character character character character character character [8] character character character character character character character [15] character character character character Wanted: something like the results of doing class(Abortion) [1] table dim(Abortion) [1] 2 2 2 class(Mental) [1] data.frame dim(Mental) [1] 24 3 for all datasets in Item, giving a display like Item class dim Title Abortion table 2x2x2 Abortion Opinion Data Mentaldata.frame 24x2Mental impariment and parents SES -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] CRAN vs R-Forge
Hi, On Mon, Oct 25, 2010 at 1:29 PM, Jason Kwok jayk...@gmail.com wrote: What's the difference between the packages you get from CRAN and R-Forge? Are the packages you get from CRAN fully developed and R-Forge work-in-progress? You pretty much got it right. R-forge provides an ecosystem to help develop your packages: (i) a source control management system (ii) bug tracking (iii) forums/mailing lists (iv) etc. Developers might choose to put release candidate/beta/other versions of their libraries there to facilitate testing, etc. As you suspected, CRAN is simply a place to put the *release* versions of packages. Once a milestone in development has been reached for a project on r-forge, I guess the devs using r-forge could then choose to send a specific version over to CRAN. -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ 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] finding the year of a date
Thank you very much! Dimitri On Mon, Oct 25, 2010 at 12:46 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Mon, Oct 25, 2010 at 12:38 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: I know that I can use as.yearmon in the package zoo to find the year and the month of a date. I can use as. yearqtr to find the year and the quarter. But how can one find just the year of a date? Thanks a lot! Here are three ways. The first uses the fact that the year is the whole number part of a yearmon object. library(zoo) d - Sys.Date() floor(as.numeric(as.yearmon(d))) [1] 2010 as.numeric(format(d, %Y)) [1] 2010 as.POSIXlt(d)$year + 1900 [1] 2010 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com -- Dimitri Liakhovitski Ninah Consulting www.ninah.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] building lme call via call()
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Vito Muggeo (UniPa) Sent: Monday, October 25, 2010 9:16 AM To: r-h...@stat.math.ethz.ch Subject: [R] building lme call via call() dear all, I would like to get the lme call without fitting the relevant model. library(nlme) data(Orthodont) fm1 - lme(distance ~ age, random=list(Subject=~age),data = Orthodont) To get fm1$call without fitting the model I use call(): my.cc-call(lme.formula, fixed= distance ~ age, random = list(Subject = ~age)) However the two calls are not the same (apart from the data argument I am not interested in), as call() *does* evaluate the arguments: my.cc$random $Subject ~age You can use quote() to avoid the evaluations. E.g., better.cc - call(lme.formula, + fixed=quote(distance~age), + data=quote(Orthodont), + random=quote(list(Subject=~age))) identical(better.cc, fm1$call) [1] TRUE Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com fm1$call$random list(Subject = ~age) How is it possible to get the right call (similar to the one from fm1$call) by means of call()? thanks, vito -- Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Università di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 23895240 fax: 091 485726/485612 http://dssm.unipa.it/vmuggeo __ 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-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] Mixed-effects model for overdispersed count data?
According to the documentation for glmmADMB if you fit your model with a statment like fit =glmm.admb(y~Base*trt+Age+Visit, ... data=epil2,family=nbinom) and that the parameter estimates are in fit$b while their estimated standard deviations are in fit$stdbeta so presumably p values can be constructed from the quotient fit$b/fit$stdbeta by assuming a t distribution with (somehow) the correct degrees of freedom. __ 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] Conditional looping over a set of variables in R
Adrienne, there's one glitch when I implement your solution below. When the loop encounters a case with no data at all (that is, all 140 item responses are missing), it aborts and prints this error message: ERROR: argument is of length zero. I wonder if there's a logical condition I could add that would enable R to skip these empty cases and continue executing on the next case that contains data. Thanks, Dave David S. Herzberg, Ph.D. Vice President, Research and Development Western Psychological Services 12031 Wilshire Blvd. Los Angeles, CA 90025-1251 Phone: (310)478-2061 x144 FAX: (310)478-7838 email: dav...@wpspublish.com From: wootten.adrie...@gmail.com [mailto:wootten.adrie...@gmail.com] On Behalf Of Adrienne Wootten Sent: Friday, October 22, 2010 9:09 AM To: David Herzberg Cc: r-help@r-project.org Subject: Re: [R] Conditional looping over a set of variables in R David, here I'm referring to your data as testmat, a matrix of 140 columns and 1500 rows, but the same or similar notation can be applied to data frames in R. If I understand correctly, you are looking for the first response (column) where you got a value of 1. I'm assuming also that since your missing values are characters then your two numeric values are also characters. keeping all this in mind, try something like this. first = c() # your extra variable which will eventually contain the first correct response for each case for(i in 1:nrow(testmat)){ c = 1 while( c=ncol(testmat) | testmat[i,c] != 1 ){ if( testmat[i,c] == 1){ first[i] = c break # will exit the while loop once it finds the first correct answer, and then jump to the next case } else { c=c+1 # procede to the next column if not } } } Hope this helps you out a bit. Adrienne Wootten NCSU On Fri, Oct 22, 2010 at 11:33 AM, David Herzberg dav...@wpspublish.commailto:dav...@wpspublish.com wrote: Here's the problem I'm trying to solve in R: I have a data frame that consists of about 1500 cases (rows) of data from kids who took a test of listening comprehension. The columns are their scores (1 = correct, 0 = incorrect, . = missing) on 140 test items. The items are numbered sequentially and are ordered by increasing difficulty as you go from left to right across the columns. I want R to go through the data and find the first correct response for each case. Because of basal and ceiling rules, many cases have missing data on many items before the first correct response appears. For each case, I want R to evaluate the item responses sequentially starting with item 1. If the score is 0 or missing, proceed to the next item and evaluate it. If the score is 1, stop the operation for that case, record the item number of that first correct response in a new variable, proceed to the next case, and restart the operation. In SPSS, this operation would be carried out with LOOP, VECTOR, and DO IF, as follows (assuming the data set is already loaded): * DECLARE A NEW VARIABLE TO HOLD THE ITEM NUMBER OF THE FIRST CORRECT RESPONSE, SET IT EQUAL TO 0. numeric LCfirst1. comp LCfirst1 = 0 * DECLARE A VECTOR TO HOLD THE 140 ITEM RESPONSE VARIABLES. vector x=LC1a_score to LC140a_score. * SET UP A LOOP THAT WILL RUN FROM 1 TO 140, AS LONG AS LCfirst1 = 0. #i IS AN INDEX VARIABLE THAT INCREASES BY 1 EACH TIME THE LOOP RUNS. loop #i=1 to 140 if (LCfirst1 = 0). * SET UP A CONDITIONAL TRANSFORMATION THAT IS EVALUATED FOR EACH ELEMENT OF THE VECTOR. THUS, WHEN #i = 1, THE EXPRESSION EVALUATES THE FIRST ELEMENT OF THE VECTOR (THAT IS, THE FIRST OF THE 140 ITEM RESPONSES). AS THE LOOP RUNS AND #i INCREASES, SUBSEQUENT VECTOR ELELMENTS ARE EVALUATED. THE do if STATEMENT RETAINS CONTROL AND KEEPS LOOPING THROUGH THE VECTOR UNTIL A '1' IS ENCOUNTERED. + do if x(#i) = 1. * WHEN A '1' IS ENCOUNTERED, CONTROL PASSES TO THE NEXT STATEMENT, WHICH RECODES THE VALUE OF THAT VECTOR ELEMENT TO '99'. + comp x(#i) = 99. * AND THEN CONTROL PASSES TO THE NEXT STATEMENT, WHICH RECODES THE VALUE OF LCfirst1 TO THE CURRENT INDEX VALUE, THUS CAPTURING THE ITEM NUMBER OF THE FIRST CORRECT RESPONSE FOR THAT CASE. CHANGING THE VALUE OF LCfirst1 ALSO CAUSE S THE LOOP TO STOP EXECUTING FOR THAT CASE, AND THE PROGRAM MOVES TO THE NEXT CASE AND RESTARTS THE LOOP. + comp LCfirst1 = #i. + end if. end loop. exe. After several hours of trying to translate this procedure to R, I'm stumped. I played around with creating a list to hold the item responses variables (analogous to 'vector' in SPSS), but when I tried to use the list in an R procedure, I kept getting a warning along the lines of 'the list contains 1 element, only the first element will be used'. So perhaps a list is not the appropriate class to 'hold' these variables? It seems that some nested arrangement of 'for' 'while' and/or 'lapply' will allow me to recreate the operation described above? How do I set up the indexing operation analogous to 'loop #i' in SPSS? Any help is appreciated, and I'm happy
Re: [R] Chron object in time series plot
I would like to thank you all for the help given so far! I have the following object of the class 'zoo' temp_mean_plot[31:35] 2008-02-13 2008-02-14 2008-02-15 2008-02-18 2008-02-19 14.86834 14.89609 14.89358 14.87610 14.87652 The sample runs from Jan 2008 to July 2010. How can I specify to plot for example Jan08, Jul08, Jan09 etc? I've seen some example as in example(plot.zoo) but I cant get exactly how to replicate it for my purpose. Any help will be highly appreciated again. Marco -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3012629.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem with setRepositories
When I call setRepositories() I get an error Error in aa[aa == ] - repos[new][aa == ] : NAs are not allowed in subscripted assignments Does anyone know how to fix this? Thanks, John Internet Email Confidentiality Footer Privileged/Confidential Information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and notify the sender by reply email. Please advise immediately if you or your employer do not consent to Internet email for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of The Shaw Group Inc. or its subsidiaries shall be understood as neither given nor endorsed by it. __ The Shaw Group Inc. http://www.shawgrp.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] question in using nlme and lme4 for unbalanced data
Hello: I have an two factorial random block design. It's a ecology experiment. My two factors are, guild removal and enfa removal. Both are two levels, 0 (no removal), 1 (removal). I have 5 blocks. But within each block, it's unbalanced at plot level because I have 5 plots instead of 4 in each block. Within each block, I have 1 plot with only guild removal, 1 plot with only enfa removal, 1 plot for control with no removal, 2 plots for both guild and enfa removal. I am looking at how these treatment affect the enfa mortality rate. I decide to use mixed model to treat block as random effect. So I try both nlme and lme4. But I don't know whether they take the unbalanced data properly. So my question is, does lme in nlme and lmer in lme4 take unbalanced data? How do I know it's analysis in a proper way? Here is my code and the result for each method. I first try nlme library(nlme) m=lme(enfa_mortality~guild_removal*enfa_removal,random=~1|block,data=com_summer) It gave me the result as following Linear mixed-effects model fit by REML Data: com_summer AIC BIC logLik 8.552254 14.81939 1.723873 Random effects: Formula: ~1 | block (Intercept) Residual StdDev: 9.722548e-07 0.1880945 Fixed effects: enfa_mortality ~ guild_removal * enfa_removal Value Std.Error DF t-value p-value (Intercept) 0.450 0.0841184 17 5.349603 0.0001 guild_removal -0.100 0.1189614 17 -0.840609 0.4122 enfa_removal -0.368 0.1189614 17 -3.093441 0.0066 guild_removal:enfa_removal 0.197 0.1573711 17 1.251818 0.2276 Correlation: (Intr) gld_rm enf_rm guild_removal -0.707 enfa_removal -0.707 0.500 guild_removal:enfa_removal 0.535 -0.756 -0.756 Standardized Within-Group Residuals: Min Q1Med Q3Max -1.7650706 -0.7017751 0.1594943 0.7974717 1.9139320 Number of Observations: 25 Number of Groups: 5 I kind of heard the P value does not matter that much in the mixed model. Is there any other way I can tell whether the treatment has a significant effect or not? I then try lme4, it give similar result, but won't tell me the p value. library(lme4) m-lmer(enfa_mortality ~ guild_removal*enfa_removal +(1|block), data=com_summer) here is the result Linear mixed model fit by REML Formula: enfa_mortality ~ guild_removal * enfa_removal + (1 | block) Data: com_summer AIC BIC logLik deviance REMLdev 8.552 15.87 1.724 -16.95 -3.448 Random effects: Groups NameVariance Std.Dev. block(Intercept) 0.00 0.0 Residual 0.035380 0.18809 Number of obs: 25, groups: block, 5 Fixed effects: Estimate Std. Error t value (Intercept) 0.450000.08412 5.350 guild_removal -0.10.11896 -0.841 enfa_removal -0.368000.11896 -3.093 guild_removal:enfa_removal 0.197000.15737 1.252 Correlation of Fixed Effects: (Intr) gld_rm enf_rm guild_remvl -0.707 enfa_removl -0.707 0.500 gld_rmvl:n_ 0.535 -0.756 -0.756 I really appreciate any suggestion! Thank you! -- Chi Yuan Graduate Student Department of Ecology and Evolutionary Biology University of Arizona Room 106 Bioscience West lab phone: 520-621-1889 Email:cy...@email.arizona.edu Website: http://www.u.arizona.edu/~cyuan/ __ 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] problem with setRepositories
On 25/10/2010 3:09 PM, Carson, John wrote: When I call setRepositories() I get an error Error in aa[aa == ]- repos[new][aa == ] : NAs are not allowed in subscripted assignments Does anyone know how to fix this? What version of R are you using? What does getOption(repos) give? Duncan Murdoch __ 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] Chron object in time series plot
On Mon, Oct 25, 2010 at 3:01 PM, Manta mantin...@libero.it wrote: I would like to thank you all for the help given so far! I have the following object of the class 'zoo' temp_mean_plot[31:35] 2008-02-13 2008-02-14 2008-02-15 2008-02-18 2008-02-19 14.86834 14.89609 14.89358 14.87610 14.87652 The sample runs from Jan 2008 to July 2010. How can I specify to plot for example Jan08, Jul08, Jan09 etc? I've seen some example as in example(plot.zoo) but I cant get exactly how to replicate it for my purpose. Any help will be highly appreciated again. Assuming that you are looking for a single plot that shows the last point in each January and the last point in each July and no other point then the following creates a test series, z, and aggregates it down to a monthly series, picks off the January and July months and plots: library(zoo) # test data z - zooreg(1:1000, start = as.Date(2000-01-01)) zym - aggregate(z, as.yearmon, function(x) tail(x, 1)) mon - as.numeric(format(time(zym), %m)) zjj - zym[mon %% 6 == 1, ] plot(zjj, type = o); grid() -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.