[R] Dataframe subset - why doesn't this work?
data(mtcars) mtcars[rownames(mtcars)!=Valiant,] # fails mtcars[list(rownames(mtcars))!=Valiant,] # runs but I am not getting the expected result With the latter statement, I expected all rows except the one where the name is Valiant. I must have got something simple wrong; what is it? Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading Text Files with RODBC
To be fair, RODBC is just an interface to ODBC, and this is not an ODBC support forum. In my experience, ODBC works alright when used to connect to a SQL database, but is pretty flaky when used to connect to Excel or CSV files. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Nutter, Benjamin nutt...@ccf.org wrote: Ah, yes. If you can't find the answer to your question, ask a different question! sqldf does, indeed, do what I want. Thank you Benjamin Nutter | Biostatistician | Quantitative Health Sciences Cleveland Clinic | 9500 Euclid Ave. | Cleveland, OH 44195 | (216) 445-1365 -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Thursday, February 16, 2012 1:15 PM To: Nutter, Benjamin Cc: r-help@r-project.org Subject: Re: [R] Reading Text Files with RODBC On Thu, Feb 16, 2012 at 10:12 AM, Nutter, Benjamin nutt...@ccf.org wrote: I'm thoroughly stumped. I've been playing with RODBC and wanted to see if I could retrieve data from text files using this package as well (for the most part, this is an intellectual exercise, but occasionally I do get data files large enough in CSV format RODBC could be helpful) . I set up a DNS called Text Files and then ran the following code in R library(RODBC) mtg - odbcConnect(Text Files) sqlTables(mtg) TABLE_CAT TABLE_SCHEM TABLE_NAME TABLE_TYPE REMARKS 1 C:\\USERS\\NUTTERB NA Core2012.txt TABLE NA 2 C:\\USERS\\NUTTERB NA MTGCards.csv TABLE NA sqlFetch(mtg, MTGCards.csv) Error in odbcTableExists(channel, sqtable) : 'MTGCards.csv': table not found on channel MTGCards.csv is an export from an MS Access database, and I'm able to get it out of Access, and I'm also able to connect to our Oracle databases. So I'm not sure what it is I'm not getting about reading the text files. If anyone has done this successfully and has any pointers, I'd appreciate it. So far I've not been able to solve it with documentation from RODBC, RStudio (I get the same error messages when I use the RGui), or Microsoft ODBC drivers. This isn't precisely what you are asking for but if the idea is to apply an sql statement to a csv file then read.csv.sql in the sqldf package can apply an sql statement to a csv file reading the result into R. If you omit the sql statement then it reads it all in. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com === Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2010). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ 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] Creating XML using apply
Undoubtedly. However, it probably won't affect the time it takes to finish by very much. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. arunkumar akpbond...@gmail.com wrote: Hi My data looks like this data is a vector data=var1 var2 var3 100 120 130 i want to put it in an XML xmlOutput=NULL xmlOutput- newXMLNode(results) for( i in 1 : length(data)) { newXMLNode(variable,attrs=c(name =names(data)[i] ), value = data[i]), parent = xmlOutput) } is it possible to use apply here If there more variables it takes long time to create XML - Thanks in Advance Arun -- View this message in context: http://r.789695.n4.nabble.com/Creating-XML-using-apply-tp4396480p4396480.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.
Re: [R] RODBC sqlSave / append problem (windows XP, R 2.13.2)
Hi MJ, Thanks alot for this. I will try and revert.  Taby An idea not coupled with action will never get any bigger than the brain cell it occupied. Arnold Glasgow .. Attempt something large enough that failure is guaranteedâ¦unless God steps in! From: matthew-c.john...@ubs.com matthew-c.john...@ubs.com Cc: r-help@r-project.org Sent: Friday, February 17, 2012 12:48 AM Subject: RE: [R] RODBC sqlSave / append problem (windows XP, R 2.13.2) Hi Taby,  i could not work out how to add to a table, so what i did was to kill the old one and write a new one --  here is a snippet of my code:  # delete the old table sqlDrop(con, sqtable=__mytable__) # note this will hang if the table cannot be found  # insert the new table sqlSave(con,as.data.frame(__myDF__),tablename=__mytable__,rownames=T,fast=T) odbcClose(con) #Close connection to DB  best regards  mj Sent: 16 February 2012 23:29 To: Johnson, Matthew-C Cc: R help Subject: Re: [R] RODBC sqlSave / append problem (windows XP, R 2.13.2) Hi Mj, did you get a solution for this? I am having the same error  Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, : missing columns in 'data' I would appreciate if you can share the solution with me. Kind regards, Taby From: mattjo matthew-c.john...@ubs.com To: r-help@r-project.org Sent: Monday, December 5, 2011 1:25 AM Subject: [R] RODBC sqlSave / append problem (windows XP, R 2.13.2) Dear All, Using RODBC I have read in a (429 x 11) dataframe from Access, and would like to append two columns of transformed data (429 x 2) to the original table (thereby making it a 429 x 13 table). I would ideally like this to be the same name etc as the original table in Access. I have used the following command: R sqlSave(con,as.data.frame(SA_data),tablename=Const_mats_8301_t1,rownam es=T,fast=T, append=T) And get the error: Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, : missing columns in 'data' Thanks in advance, mj Visit our website at http://www.ubs.com This message contains confidential information and is in...{{dropped:26}} __ 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. Visit our website at http://www.ubs.com This message contains confidential information and is in...{{dropped:25}} __ 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 subset - why doesn't this work?
Hi Ajay, In the first case, you need == instead of = : R mtcars[ rownames(mtcars) == Valiant, ] mpg cyl disp hp drat wt qsec vs am gear carb Valiant 18.1 6 225 105 2.76 3.46 20.22 1 031 For the second case, R mtcars[rownames(mtcars) != Valiant,] will do it. See also ?subset. HTH, Jorge.- On Fri, Feb 17, 2012 at 3:02 AM, Ajay Askoolum wrote: data(mtcars) mtcars[rownames(mtcars)!=Valiant,] # fails mtcars[list(rownames(mtcars))!=Valiant,] # runs but I am not getting the expected result With the latter statement, I expected all rows except the one where the name is Valiant. I must have got something simple wrong; what is it? Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] QQ plot
Hello, I am having two data set original and predicted. I want to dind QQ-plot fot it. I tried in following manner : qq(original~predicted) and error was : Error in qq.formula(o ~ p) : y must have exactly 2 levels There is an option qtype which dosent make any difference. What is the correct way for plotting QQ-plot or am I missing something. -- Amar Kumar Nandan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to get r-squared for a predefined curve or function with other data points
it's that easy, eh? thank you for your input, it's much appreciated. i will have a look at nlmer as well. markus On Thu, Feb 16, 2012 at 23:17, David Winsemius [via R] ml-node+s789695n4395634...@n4.nabble.com wrote: On Feb 16, 2012, at 11:43 AM, protoplast wrote: hello mailing list! i still consider myself an R beginner, so please bear with me if my questions seems strange. i'm in the field of biology, and have done consecutive hydraulic conductivity measurements in three parallels (Sample), resulting in three sets of conductivity values (PLC for percent loss of conductivity, relative to 100%) at multiple pressures (MPa). --- Sample MPaPLC 1 -0.34983240.00 1 -1.2414770 15.207821 1 -1.7993249 23.819995 1 -3.0162866 33.598570 1 -3.5184321 46.376933 1 -3.9899791 67.532226 1 -4.2731145 89.735541 1 -4.7597244 99.836239 2 -0.27540360.00 2 -1.2912619 12.476132 2 -1.5128974 13.543273 ... --- since each sample is a statistical unit, i have fitted each sample- subset to a sigmoid curve: --- plot( NA, NA, main=, xlim=c(-20,0), ylim=c(0,100), xlab = water potential [MPa], ylab = percent loss of conductivity [%], xaxp = c(0,-20,4), yaxp = c(0,100,5), tck = 0.02, mgp = c(1.5,0.1,0), ) for(i in 1:3){ x - subset(curvedata,Group == i)$MPa y - subset(curvedata,Group == i)$PLC name - subset(curvedata,Group == i)$Sample points(x,y) vlc - nls(y ~ 100/(1+exp(a*(x-b))), start=c(a=1, b=-3), data=list(x,y)) curve(100/(1+exp(coef(vlc)[1]*(x-coef(vlc)[2]))), col=1, add = TRUE) Rsquared - 1 - var(residuals(vlc))/var(y) summarizeall[i ,Run] - i summarizeall[i ,Sample] - name[1] summarizeall[i ,a] - coef(vlc)[1] summarizeall[i ,b] - coef(vlc)[2] summarizeall[i ,R2] - Rsquared listnow - data.frame(list(Run = c(i),Sample = c(name[1]), a = c(coef(vlc)[1]), b = c(coef(vlc)[2]), R2 = c(Rsquared))) print(listnow) i - i+1 } --- ...and get three slightly different curves with three different estimatinos of fit (r², Rsquared). --- summarizeall Sample a bR2 1 1 1.388352 -3.277755 0.9379886 2 2 1.87 -3.363075 0.9327164 3 3 1.736857 -2.743972 0.9882998 average Var n a b R2 1 Mean 3 1.6417389 -3.1282673 NA 2 SE . 0.1279981 0.1937197 NA --- by averaging parameters a and b of the curve, i create a mean curve that is added to the plot (red curve in the attached image). http://r.789695.n4.nabble.com/file/n4394609/conductivity-curve.gif --- meana - average[1,a] meanb - average[1,b] curve(), col=2, lwd=2, add = TRUE) --- and now here's my problem: i'd like to calculate R squared for all points on that mean curve. since i have to average the curve parameters, i loose the curve's residuals that are stored in my variable vlc (the result of the nls function) for every sample. just fitting one curve to all the data points is not good enough. So just calculate them? # pseudo-code: residual= actual - predicted gresid - curvedata$PLC - 100/(1+exp(meana*(curvedata$MPa-meanb)) If you are convinced that your formula for R^2 makes sense and this practice is generally accepted in your domain, then you can apply it across the whole dataset. I would have thought that a single regression model built with nlmer might have been more statistically sound. (But this is a bit outside my domain of comfort for giving advice.) an extensive google search over several days hasn't gotten me anywhere, but maybe someone here can help me? is there an efficient way to calculate r squared for a predefined function with unrelated data points? (unrelated as in not used directly for fitting) thanks in advance markus David Winsemius, MD West Hartford, CT __ [hidden email] http://user/SendEmail.jtp?type=nodenode=4395634i=0mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/how-to-get-r-squared-for-a-predefined-curve-or-function-with-other-data-points-tp4394609p4395634.html To unsubscribe from how to get r-squared for a predefined curve or function with other data points, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4394609code=bm9sZi5tYXJrdXNAZ21haWwuY29tfDQzOTQ2MDl8LTE0MDUwOTcyOTk= .
Re: [R] QQ plot
On 17/02/12 21:32, nandan amar wrote: Hello, I am having two data set original and predicted. I want to dind QQ-plot fot it. I tried in following manner : qq(original~predicted) and error was : Error in qq.formula(o ~ p) : y must have exactly 2 levels There is an option qtype which dosent make any difference. What is the correct way for plotting QQ-plot or am I missing something. To start with, you are missing telling us that the function qq() is from the *lattice* package. Secondly you are missing reading the error message. What does it *say*? Think about it. It says that (rather strangely, it seems to me) that the left hand side of the formula must be a factor with two levels. Obviously then you must combine your observations into a single vector and create a factor indicating to which of the two samples each entry of that vector belongs. Something like: y - c(original,predicted) f - factor(rep(c(o,p),c(length(original),length(predicted require(lattice) print(qq(f ~ y)) Alternatively you could save hassle and use base graphics: qqplot(original,predicted) cheers, Rolf Turner __ 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] Different cp values in rpart() using plotcp() and printcp()
hi, I have a question regarding cp values in rpart(). When I use plotcp() I get a figure with cp values on the x-axsis, but then I use printcp() the cp values in that list are different from the values in the figure by plotcp(). Does someone know why? Silje [[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] import .csv file into R
Hi Michael and Rui, thanks a lot for the tips. It worked with both your suggestions! I also found out, that this problem only exists if I put header=T. Thanks again! Marion If you don't need to refer to colnames you should be fine. If you do need to subset by colnames, you can still do it with `[`, but you'll have trouble if you want to use the $ trick, unless you use back-ticks. Don't worry about these things if they aren't troubling you now though. Michael 2012/2/16 Rui Barradas rui1...@sapo.pt Hello, I read a .csv file into R with the following command: A-read.csv2(file=Mappe3.csv) It worked fine, except that I would like to get rid of the points between the words and get spaces instead like I have got in the .csv file. Try gsub('\\.', ' ', A) (And see ?regexpr and ?gsub) Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/import-csv-file-into-R-tp4394533p4394573.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] Error message in gamm. Problem with temporal correlation structure
HELLO ALL, I AM GETTING AN ERROR MESSAGE WHEN TRYING TO RUN A GAMM MODEL LIKE THE ONE BELOW. I AM USING R VERSION 2.14.1 (2011-12-22) AND MGCV 1.7-12. M1 -gamm(DepVar ~ Treatment + s(Year, by =Treatment), random=list(Block=~1), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Treatment, p = 1, q = 0)) THIS IS THE ERROR MESSAGE Error in `*tmp*`[[k]] : attempt to select less than one element I have 312 observations. I get the error when I introduce the correlation structure in the model. I have the same problem even if I use /corAR1() /or I set bs=âcrâ. I also tried to increase the number of iterations using the control option, but I find the same problem. Is there any other way in which I could include the correlation structure? I would appreciate any suggestions thanks! eva [[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] QQ plot
Thanks a lot Turner. Latter I also tried following : oo-quantile(original, probs = seq(0, 1, 0.01), type = 8) pp-quantile(predicted, probs = seq(0, 1, 0.01), type = 8) plot(oo,pp) But plot for above and following (as you suggested) are not same. What may be the error ? Thanks. On Fri, Feb 17, 2012 at 3:01 PM, Rolf Turner rolf.tur...@xtra.co.nz wrote: On 17/02/12 21:32, nandan amar wrote: Hello, I am having two data set original and predicted. I want to dind QQ-plot fot it. I tried in following manner : qq(original~predicted) and error was : Error in qq.formula(o ~ p) : y must have exactly 2 levels There is an option qtype which dosent make any difference. What is the correct way for plotting QQ-plot or am I missing something. To start with, you are missing telling us that the function qq() is from the *lattice* package. Secondly you are missing reading the error message. What does it *say*? Think about it. It says that (rather strangely, it seems to me) that the left hand side of the formula must be a factor with two levels. Obviously then you must combine your observations into a single vector and create a factor indicating to which of the two samples each entry of that vector belongs. Something like: y - c(original,predicted) f - factor(rep(c(o,p),c(**length(original),length(**predicted require(lattice) print(qq(f ~ y)) Alternatively you could save hassle and use base graphics: qqplot(original,predicted) cheers, Rolf Turner -- Amar Kumar Nandan Karnataka, India, 560100 â:+91-9019054471 â:nandan.a...@gmail.com http://aknandan.co.nr [[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] Plotting monthly maps from yearly data
Thank you Michael -- View this message in context: http://r.789695.n4.nabble.com/Plotting-monthly-maps-from-yearly-data-tp4391704p4396787.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] Plotting issue
I have two different datasets 1) is in monthly format (obs) 2) yearly format (model) in obs I have 84 files ( 2003:2009)for different months in model I have 4 different files which has yearly data (2005:2008) So for calculating my requirement I need these both data sets. The sample calculations are as follows file_o-list.files(path=' ', pattern=0.2.text) # total number of files are 80 for ( i in 1:file_o){ #get data here I get Lat_o- Lon_o - time_o- gas_o- } file_t list.files(path=' ', pattern=fg.nc) for (j in 1:file_t){ #get data here I get Lat_t- Lon_t - time_t- gas_t- } nobs- length(Lat_o) for (k in 1:nobs){ # here it does some calculation and get some value which is gas_new } now I would like to plot this data for every month according to my observation data plotting## year - 2005:2008 month- (jan,Feb,March,..Dec) for ( y in year) for (m in month) here I use Sp plot and plot map } } what I would like to do is I want to plot data according to my observations taken ( its in month) but when I run my codes it plots same file from2005:2008 but it suppose to plot 48 different files for different months. I got stuck here, I am quit new in R. it would be very nice it somebody can tell me how to fix this problem. Uday -- View this message in context: http://r.789695.n4.nabble.com/Plotting-issue-tp4396832p4396832.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] Error message in gamm. Problem with temporal correlation structure
eva, I can't manage to replicate this by simulation. Is there any chance you could send me the data off-list, and I can take a look (if so I'll only use the data for the purpose of finding out what's wrong, of course). best, Simon On 17/02/12 09:35, HERNANDEZ PLAZA, MARIA EVA wrote: HELLO ALL, I AM GETTING AN ERROR MESSAGE WHEN TRYING TO RUN A GAMM MODEL LIKE THE ONE BELOW. I AM USING R VERSION 2.14.1 (2011-12-22) AND MGCV 1.7-12. M1-gamm(DepVar ~ Treatment + s(Year, by =Treatment), random=list(Block=~1), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Treatment, p = 1, q = 0)) THIS IS THE ERROR MESSAGE Error in `*tmp*`[[k]] : attempt to select less than one element I have 312 observations. I get the error when I introduce the correlation structure in the model. I have the same problem even if I use /corAR1() /or I set bs=�cr�. I also tried to increase the number of iterations using the control option, but I find the same problem. Is there any other way in which I could include the correlation structure? I would appreciate any suggestions thanks! eva [[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. -- Simon Wood, Mathematical Science, University of Bath BA2 7AY UK +44 (0)1225 386603 http://people.bath.ac.uk/sw283 __ 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] (subscript) logical subscript too long in using apply
Dear ALL I have this function in R: func_LN - function(data){ med_ge - matrix(c(rep(NA,nrow(data)*ncol(data))), nrow = nrow(data), ncol=ncol(data), byrow=TRUE) T - matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) Tdiff- matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) T1- c(rep(NA,ncol(data))) T0- c(rep(NA,ncol(data))) cov_rank-matrix(c(rep(NA,ncol(data)*ncol(data))), nrow = ncol(data), ncol = ncol(data) , byrow=TRUE) med - c(rep(NA,ncol(data))) mean_ge - c(rep(NA,ncol(data))) n-c(NA,2) if (ncol(data)1){ for(m_j in 1:ncol(data)){ med[m_j]-median(data[,m_j])} for(m_j in 1:ncol(data)) for(m_i in 1:nrow(data)) { if(data[m_i,m_j]med[m_j]) med_ge[m_i,m_j]=0 else med_ge[m_i,m_j]=1 } y=c(1,1,1,1,1,1,0,0,0,0) n-c(sum(y == 1),sum(y==0)) touse3 - y==1 T1- apply(med_ge[touse3,], 2, mean) T0- apply(med_ge[!touse3,], 2, mean) T=rbind(T1,T0) Tbar=colMeans(T) Tdiff=T-Tbar cov_rank=cov(med_ge) inv_cov_rank=ginv(cov_rank) LN=0 for(m_i in 1:length(n)) { LN - LN+((Tdiff[m_i,]%*%inv_cov_rank)%*%t(Tdiff)[,m_i])*n[m_i] } return(LN) }} func_LN(data) Now, I want to try this function on subgroups of data. So I used apply result - apply(gs , 1 , function(z) func_LN(data[which(z==1),])) but I saw this error: Error in apply(med_ge[touse3, ], 2, mean) : (subscript) logical subscript too long I will appreciate if you help me. PS:the elements of gs are 1 0r 0. dim(data)=24*2665 dim(gs)=107*2665 Soheila [[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] Load packages from source
Hi all, I'm developing an R package and I'd like to load it easly while developing, debugging and testing. I would like to load it without having to install it. Installing it causes me some problems for debugging it, as the code file it is executing it not the one I'm editing. I've seen the function sourceDirectory from R.utils package which works quite fine for me, but would be just perfect to be able to load the package as it would be installed (handling dependences, namespaces and all this stuff). Thanks in advance! David [[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] (subscript) logical subscript too long in using apply
On Fri, Feb 17, 2012 at 12:44:44PM +0100, Soheila Khodakarim wrote: Dear ALL I have this function in R: func_LN - function(data){ med_ge - matrix(c(rep(NA,nrow(data)*ncol(data))), nrow = nrow(data), ncol=ncol(data), byrow=TRUE) T - matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) Tdiff- matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) T1- c(rep(NA,ncol(data))) T0- c(rep(NA,ncol(data))) cov_rank-matrix(c(rep(NA,ncol(data)*ncol(data))), nrow = ncol(data), ncol = ncol(data) , byrow=TRUE) med - c(rep(NA,ncol(data))) mean_ge - c(rep(NA,ncol(data))) n-c(NA,2) if (ncol(data)1){ for(m_j in 1:ncol(data)){ med[m_j]-median(data[,m_j])} for(m_j in 1:ncol(data)) for(m_i in 1:nrow(data)) { if(data[m_i,m_j]med[m_j]) med_ge[m_i,m_j]=0 else med_ge[m_i,m_j]=1 } y=c(1,1,1,1,1,1,0,0,0,0) n-c(sum(y == 1),sum(y==0)) touse3 - y==1 T1- apply(med_ge[touse3,], 2, mean) T0- apply(med_ge[!touse3,], 2, mean) T=rbind(T1,T0) Tbar=colMeans(T) Tdiff=T-Tbar cov_rank=cov(med_ge) inv_cov_rank=ginv(cov_rank) LN=0 for(m_i in 1:length(n)) { LN - LN+((Tdiff[m_i,]%*%inv_cov_rank)%*%t(Tdiff)[,m_i])*n[m_i] } return(LN) }} func_LN(data) Now, I want to try this function on subgroups of data. So I used apply result - apply(gs , 1 , function(z) func_LN(data[which(z==1),])) but I saw this error: Error in apply(med_ge[touse3, ], 2, mean) : (subscript) logical subscript too long I will appreciate if you help me. PS:the elements of gs are 1 0r 0. dim(data)=24*2665 dim(gs)=107*2665 Hi. Without a reproducible example, it is hard to determine the problem. You can try options(error=utils::recover) to get more information on the values of the variables when the error occurs. However, i am not sure, why you use data[which(z==1),] and not data[,which(z==1)]. The reason is that the function apply(gs , 1 , func) applies func to the rows of gs. These rows have length 2665, which is equal to the number of columns of data. So, i would expect to use z to select columns, not rows of data. Can you comment on this? Petr Savicky. __ 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] Control number of assets in resulting portfolio with optimizations using package fPortfolio
Alex, You may find an answer to your question by searching the R-SIG-Finance archives (via rseek.org). If not, you may want to consider asking your question on the R-SIG-Finance list. Best, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com R/Finance 2012: Applied Finance with R www.RinFinance.com On Fri, Feb 17, 2012 at 12:53 AM, Enrico Schumann enricoschum...@yahoo.de wrote: Hi Alex, I cannot say how to implement such constraints with fPortfolio, but in general you can use heuristics to solve such problems. An example for selecting a number of assets from a larger universe is given in a vignette of the NMOF package (of which I am the author) and in the code examples on http://nmof.net (even though they do not exactly cover your problem). Regards, Enrico Am 15.02.2012 20:18, schrieb Alexander Erbse: Dear All, I am using package fPortfolio to run minimum variance portfolio optimizations in R. I already know how to set portfolioSpecs, portfolio objects and constraints. Unfortunately I am not able to set the following type of constraints. I have a timeSeries object with returns data for roughly 1.5k assets for 261 subperiods (workingdays) and want to compute the global minimum variance portfolio, considering following constraints: - Leverage = 1 (fully invested) - the lower / upper weights constraints (can be done by box constraints) for individual assets are e.g. +0,01 / +0,04 - and the problematic part: the minimum weights level for each asset is +0,01 OR zero (in order to control outcome portfolio size) � Initially, considering that the minimum weight constraint is +0,01 for each of the 1.500 assets and the sum of weights constraint (leverage) equals 1 would raise an infeasible problem for the optimizer. Given my additional restriction that the minimum weight for any asset to get into the portfolio should be at least 0,01 would solve the target conflict in between minimum asset weights and the leverage of 1. The iteration path of the optimizer should consider something like this: ifelse(min(weight,0,01)0,01,0,weight) �during the optimization. (iteratively) Is there any way to implement that sort of that constraint besides the upper / lower weight constraints (box constraints) in order to control for decent portfolio sizes? Thx 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. -- Enrico Schumann Lucerne, Switzerland http://nmof.net/ __ 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] (subscript) logical subscript too long in using apply
Hi apply probably does not understand you function. I do not want to go too deeply into it but I noticed few issues in it. See inline Dear ALL I have this function in R: func_LN - function(data){ med_ge - matrix(c(rep(NA,nrow(data)*ncol(data))), nrow = nrow(data), ncol=ncol(data), byrow=TRUE) T - matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) Tdiff- matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) T1- c(rep(NA,ncol(data))) T0- c(rep(NA,ncol(data))) cov_rank-matrix(c(rep(NA,ncol(data)*ncol(data))), nrow = ncol(data), ncol = ncol(data) , byrow=TRUE) med - c(rep(NA,ncol(data))) mean_ge - c(rep(NA,ncol(data))) n-c(NA,2) if (ncol(data)1){ for(m_j in 1:ncol(data)){ med[m_j]-median(data[,m_j])} this shall be the same as med - apply(data, 2, median) for(m_j in 1:ncol(data)) for(m_i in 1:nrow(data)) { if(data[m_i,m_j]med[m_j]) med_ge[m_i,m_j]=0 else med_ge[m_i,m_j]=1 } AFAIK this shall be same as med_ge-(sweep(dat, 2, med)=0)*1 y=c(1,1,1,1,1,1,0,0,0,0) n-c(sum(y == 1),sum(y==0)) touse3 - y==1 T1- apply(med_ge[touse3,], 2, mean) T0- apply(med_ge[!touse3,], 2, mean) T=rbind(T1,T0) Tbar=colMeans(T) Tdiff=T-Tbar cov_rank=cov(med_ge) inv_cov_rank=ginv(cov_rank) LN=0 for(m_i in 1:length(n)) { LN - LN+((Tdiff[m_i,]%*%inv_cov_rank)%*%t(Tdiff)[,m_i])*n[m_i] } return(LN) }} func_LN(data) Now, I want to try this function on subgroups of data. So I used apply result - apply(gs , 1 , function(z) func_LN(data[which(z==1),])) but I saw this error: Error in apply(med_ge[touse3, ], 2, mean) : (subscript) logical subscript too long The rest is quite complicated for me so I do not dig into it. The obvious source of error is apply(med_ge[touse3, ], 2, mean) which tells you that touse3 is longer than number of med_ge rows. The error message probably could not be more precise. Regards Petr I will appreciate if you help me. PS:the elements of gs are 1 0r 0. dim(data)=24*2665 dim(gs)=107*2665 Soheila [[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] ACM Software Copyright and License Agreement
peter dalgaard pdalgd at gmail.com writes: On Feb 16, 2012, at 12:31 , Hans W Borchers wrote: I have often seen the use of routines from the ACM Collected Algorithms, i.e. netlib.org/toms/≥ (CALGO, or Trans. On Math. Software, TOMS), in Open Source programs, maybe also in some R packages --- and sometimes these programs are distributed under the GPL license, sometimes under proprietary licenses, e.g. in Scilab. The use of these CALGO programs is subject to the ACM Software Copyright and License Agreement www.acm.org/publications/policies/softwarecrnotice which includes the following paragraph: **Commercial Use** Any User wishing to make a commercial use of the Software must contact ACM at permissions at acm.org to arrange an appropriate license. Commercial use includes (1) integrating or incorporating all or part of the source code into a product for sale or license by, or on behalf of, User to third parties, (2) distribution of the binary or source code to third parties for use with a commercial product sold or licensed by, or on behalf of, User. I assume that this license extension is not compatible with GPL, but may be wrong here. So my question is: Can software from the ACM Collected Algorithms be distributed under a GPL-compatible licence, and how to formulate and where to put such a license extension. One needs to tread _really_ carefully with these items. You plain can't claim that the ACM license is compatible with the GPL; it just isn't. However, there are cases where software has been placed in the Public Domain in addition to being published by an ACM Journal. E.g., the NSWC (Naval Surface Warfare Center) library is in the Public Domain even though some of its routines have been published in TOMS. And how can I be sure that these algorithms have been rightly placed on the NSWC library page under a license different from its original ACM license? I am inclined to be quite suspicious about that. Best, Hans Werner However, I am not a lawyer, etc... -pd __ 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] ACM Software Copyright and License Agreement
On Feb 17, 2012, at 13:42 , Hans W Borchers wrote: peter dalgaard pdalgd at gmail.com writes: On Feb 16, 2012, at 12:31 , Hans W Borchers wrote: I have often seen the use of routines from the ACM Collected Algorithms, i.e. netlib.org/toms/≥ (CALGO, or Trans. On Math. Software, TOMS), in Open Source programs, maybe also in some R packages --- and sometimes these programs are distributed under the GPL license, sometimes under proprietary licenses, e.g. in Scilab. The use of these CALGO programs is subject to the ACM Software Copyright and License Agreement www.acm.org/publications/policies/softwarecrnotice which includes the following paragraph: **Commercial Use** Any User wishing to make a commercial use of the Software must contact ACM at permissions at acm.org to arrange an appropriate license. Commercial use includes (1) integrating or incorporating all or part of the source code into a product for sale or license by, or on behalf of, User to third parties, (2) distribution of the binary or source code to third parties for use with a commercial product sold or licensed by, or on behalf of, User. I assume that this license extension is not compatible with GPL, but may be wrong here. So my question is: Can software from the ACM Collected Algorithms be distributed under a GPL-compatible licence, and how to formulate and where to put such a license extension. One needs to tread _really_ carefully with these items. You plain can't claim that the ACM license is compatible with the GPL; it just isn't. However, there are cases where software has been placed in the Public Domain in addition to being published by an ACM Journal. E.g., the NSWC (Naval Surface Warfare Center) library is in the Public Domain even though some of its routines have been published in TOMS. And how can I be sure that these algorithms have been rightly placed on the NSWC library page under a license different from its original ACM license? I am inclined to be quite suspicious about that. Well, in the case I was thinking of, the code was developed by US government officials working for the US government, and as such not subjected to US Copyright. Also, the NSWC manual clearly says: Since the beginning of the development of the library, no proprietary or otherwise restricted codes have been permitted in the library. (e.g., http://www.ualberta.ca/CNS/RESEARCH/Software/NumericalNSWC/nsws.pdf) Best, Hans Werner However, I am not a lawyer, etc... -pd __ 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. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@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] How to change the order of columns in a data frame?
Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel [[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] help with ancestral.pars in phangorn package
mredfar marhat at gmail.com writes: Hello, I'm struggling with understanding the output on the ancestral.pars() command from the phangorn package, I'm new to doing phylogenetic analyses using R. I used it on nucleotide data, and it works fine, I'm just not sure how to read the output. The output is phyDat class, and outputs a matrix for each node/leaf in the tree. I figured out that the matrix columns represent the four nucleotide states a, c, g, t, but what I'm unclear about is what the rows represent, and what do the row names mean, the seem to be powers of 2, (1,2,4,8) etc, do these represent reconstruction uncertainties?? Also if you have any advice on how to extract a change list from this ancestral.pars output, (ie a list of character changes at each variable site in the sequence and in which nodes/organisms) I would be very thankful. Maha I would strongly recommend that you forward this question to the r-sig-phylo at r-project.org mailing list, where there are many more people who can answer questions about phylogenetic analysis in R. It's a very friendly list. I was going to suggest you read vignette(Ancestral), which is mentioned in ?ancestral.par, but it actually doesn't contain the information you're interested in. good luck, Ben Bolker __ 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] lmer - error message
Sean Godwin sean.godwin at gmail.com writes: Hi all, I am fairly new to mixed effects models and lmer, so bear with me. Here is a subset of my data, which includes a binary variable (lake (TOM or JAN)), one other fixed factor (Age) and a random factor (Year). lake FishID Age Increment Year 1 TOM 1 1 0.304 2007 2 TOM 1 2 0.148 2008 3 TOM 1 3 0.119 2009 4 TOM 1 4 0.053 2010 5 JAN 2 1 0.352 2009 6 JAN 2 2 0.118 2010 The model I'm trying to fit is: m1 - lmer(Increment ~ 0 + Age + Age*lake + (1|Year) + (1|Year:Age) + (1|FishID),lakedata) The error message I get is: *Error in mer_finalize(ans) : Downdated X'X is not positive definite, 27.* * * From reading up on the subject, I think my problem is that I can't incorporate the 'lake' variable in a fixed-effect interaction because it is only has one binary observation. But I don't know what to do to be able to fit this model. Any help would be greatly appreciated! -Sean In principle you should be able to fit this model, but the error message is telling you that there are numeric problems -- it may just be that your data are a little too sparse in some direction. A few suggestions: * try centering Age, or re-introducing the intercept, to see if you can get something to work. * You _might_ try the development version of lme4 (lme4Eigen, on r-forge) * plot your data to see if you see anything odd about the data * perhaps try making Year a fixed effect -- 4 levels is fairly small for a random effect * Ask further questions on the r-sig-mixed-models mailing list. Ben Bolker __ 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 change the order of columns in a data frame?
fakedata - data.frame(A=c(0,0,0), X2=c(2,2,2), X1=c(1,1,1), X3=c(3,3,3)) fakedata A X2 X1 X3 1 0 2 1 3 2 0 2 1 3 3 0 2 1 3 pos - colnames(fakedata)[2:ncol(fakedata)] pos - c(1, 1+as.numeric(gsub(X, , pos))) fakedata[, pos] A X1 X2 X3 1 0 1 2 3 2 0 1 2 3 3 0 1 2 3 Sarah 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel -- 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.
Re: [R] How to change the order of columns in a data frame?
pos2 - pos1[, c(X, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20)] 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel [[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 Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How can I tabulate time series data (in RStudio or any other R editor)?
On Feb 16, 2012, at 8:32 PM, jpm miao wrote: Hello, I have a question on how to tabulate the time series data. I use RStudio, but if can be done in any other R editor, it should work in RStudio as well. Most people have given up on using R's time series class and have moved over to using the zoo-class. There are no real dates in time series objects. Things that look like dates in printed output are calculated on the fly. The data is really just a vector and the dates are contained in the attributes of the object. a1-11:22 a1ts-ts(a1, frequency=4, start=c(1978,1)) a1ts Qtr1 Qtr2 Qtr3 Qtr4 1978 11 12 13 14 1979 15 16 17 18 1980 19 20 21 22 If I click the variable a1ts on the workspace, I see structure(11:22, .Tsp = c(1978, 1980.75, 4), class = ts) If I coerce the variable to become a matrix, a1tsm-as.matrix(a1ts) and click the variable a1tsm, I see the vector in a tabular form and can paste it into Excel , but I don't see the dates at all V1 1 11 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 20 11 21 12 22 How could I see both the dates and the data in a tabular form? Not really a full answer but this will generate a time-series object of times although they are not really any of the usual R time or date classes. time(a2ts) Qtr1Qtr2Qtr3Qtr4 1979 1979.00 1979.25 1979.50 1979.75 1980 1980.00 1980.25 1980.50 1980.75 1981 1981.00 1981.25 1981.50 1981.75 1982 1982.00 1982.25 1982.50 1982.75 The second question is that if I have another data sequence, how can I combine the two and see both data in a tabular form? a2-101:116 a2ts-ts(a2, frequency=4, start=c(1979,1)) a2ts Qtr1 Qtr2 Qtr3 Qtr4 1979 101 102 103 104 1980 105 106 107 108 1981 109 110 111 112 1982 113 114 115 116 You can't. The data in a time series is a vector, not a dataframe or a matrix. If you want the data to be a more full-featured data object then use zoo-classed objects which allow matrices and allow real dates or times. install.packages(zoo) Thank you, Miao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ 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 change the order of columns in a data frame?
On Fri, Feb 17, 2012 at 02:26:52PM +0100, Joel Fürstenberg-Hägg wrote: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Hi. Try the following. For simplicity, i assume the first column to be X0, but this is not necessary. Example data a - sort(paste(A, 0:19, sep=)) names(a) - sort(paste(X, 0:19, sep=)) pos - data.frame(rbind(a)) pos X0 X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X3 X4 X5 X6 X7 X8 X9 a A0 A1 A10 A11 A12 A13 A14 A15 A16 A17 A18 A19 A2 A3 A4 A5 A6 A7 A8 A9 The reordering: columnNames - colnames(pos) ind - as.integer(substr(columnNames, 2, nchar(columnNames))) pos[, order(ind)] X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 a A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 A17 A18 A19 Hope this helps. Petr Savicky. __ 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 change the order of columns in a data frame?
It does not work when using more variables, and my data frames usually contains about thousand columns... Best, Joel fakedata - data.frame(A=c(0,0,0), X1=c(1,1,1), X6=c(6,6,6), X7=c(7,7,7), X3=c(3,3,3), X4=c(4,4,4), X9=c(9,9,9), X2=c(2,2,2), X8=c(8,8,8), X5=c(5,5,5)) fakedata A X1 X6 X7 X3 X4 X9 X2 X8 X5 1 0 1 6 7 3 4 9 2 8 5 2 0 1 6 7 3 4 9 2 8 5 3 0 1 6 7 3 4 9 2 8 5 pos - colnames(fakedata)[2:ncol(fakedata)] pos [1] X1 X6 X7 X3 X4 X9 X2 X8 X5 pos - c(1, 1+as.numeric(gsub(X, , pos))) pos [1] 1 2 7 8 4 5 10 3 9 6 fakedata[, pos] A X1 X9 X2 X7 X3 X5 X6 X8 X4 1 0 1 9 2 7 3 5 6 8 4 2 0 1 9 2 7 3 5 6 8 4 3 0 1 9 2 7 3 5 6 8 4 Sarah Goslee sarah.gos...@gmail.com 17-02-2012 14:36 fakedata - data.frame(A=c(0,0,0), X2=c(2,2,2), X1=c(1,1,1), X3=c(3,3,3)) fakedata A X2 X1 X3 1 0 2 1 3 2 0 2 1 3 3 0 2 1 3 pos - colnames(fakedata)[2:ncol(fakedata)] pos - c(1, 1+as.numeric(gsub(X, , pos))) fakedata[, pos] A X1 X2 X3 1 0 1 2 3 2 0 1 2 3 3 0 1 2 3 Sarah 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel -- Sarah Goslee http://www.functionaldiversity.org [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to change the order of columns in a data frame?
@Alfredo The X is removed, but the reordering does not work: colnames(df)[1] - Mass columnNames - colnames(df) colnames(df) [1] Mass X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 colnames(df) - gsub(X,,colnames(df)) colnames(df) [1] Mass 110 11 12 13 14 15 16 17 18 19 220 34567 89 df - df[,colnames(df)] colnames(df) [1] Mass 110 11 12 13 14 15 16 17 18 19 220 34567 89 Best, Joel Alfredo Alessandrini caveneb...@gmail.com 17-02-2012 14:40 Hi Joel, to replace the colnames: colnames(dataframe - )gsub(X,,colnames(dataframe)) to order by colnames: dataframe - dataframe[,colnames(dataframe)] Alfredo 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to change the order of columns in a data frame?
@ Jim That would work for just a few columns, but I will have around 1000 of them so I need something more generic. best, Joel jim holtman jholt...@gmail.com 17-02-2012 14:44 pos2 - pos1[, c(X, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20)] 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel [[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 Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to change the order of columns in a data frame?
Sorry, it should be: fakedata[, order(pos)] A X1 X2 X3 X4 X5 X6 X7 X8 X9 1 0 1 2 3 4 5 6 7 8 9 2 0 1 2 3 4 5 6 7 8 9 3 0 1 2 3 4 5 6 7 8 9 Using order also ensures that non-sequential column ids will work: fakedata - data.frame(A=c(0,0,0), X1=c(1,1,1), X6=c(6,6,6), X7=c(7,7,7), X3=c(3,3,3), X4=c(4,4,4), X9=c(9,9,9), X2=c(2,2,2), X8=c(8,8,8)) pos - colnames(fakedata)[2:ncol(fakedata)] pos - c(1, 1+as.numeric(gsub(X, , pos))) fakedata A X1 X6 X7 X3 X4 X9 X2 X8 1 0 1 6 7 3 4 9 2 8 2 0 1 6 7 3 4 9 2 8 3 0 1 6 7 3 4 9 2 8 fakedata[, order(pos)] A X1 X2 X3 X4 X6 X7 X8 X9 1 0 1 2 3 4 6 7 8 9 2 0 1 2 3 4 6 7 8 9 3 0 1 2 3 4 6 7 8 9 Sarah 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: It does not work when using more variables, and my data frames usually contains about thousand columns... Best, Joel fakedata - data.frame(A=c(0,0,0), X1=c(1,1,1), X6=c(6,6,6), X7=c(7,7,7), X3=c(3,3,3), X4=c(4,4,4), X9=c(9,9,9), X2=c(2,2,2), X8=c(8,8,8), X5=c(5,5,5)) fakedata A X1 X6 X7 X3 X4 X9 X2 X8 X5 1 0 1 6 7 3 4 9 2 8 5 2 0 1 6 7 3 4 9 2 8 5 3 0 1 6 7 3 4 9 2 8 5 pos - colnames(fakedata)[2:ncol(fakedata)] pos [1] X1 X6 X7 X3 X4 X9 X2 X8 X5 pos - c(1, 1+as.numeric(gsub(X, , pos))) pos [1] 1 2 7 8 4 5 10 3 9 6 fakedata[, pos] A X1 X9 X2 X7 X3 X5 X6 X8 X4 1 0 1 9 2 7 3 5 6 8 4 2 0 1 9 2 7 3 5 6 8 4 3 0 1 9 2 7 3 5 6 8 4 Sarah Goslee sarah.gos...@gmail.com 17-02-2012 14:36 fakedata - data.frame(A=c(0,0,0), X2=c(2,2,2), X1=c(1,1,1), X3=c(3,3,3)) fakedata A X2 X1 X3 1 0 2 1 3 2 0 2 1 3 3 0 2 1 3 pos - colnames(fakedata)[2:ncol(fakedata)] pos - c(1, 1+as.numeric(gsub(X, , pos))) fakedata[, pos] A X1 X2 X3 1 0 1 2 3 2 0 1 2 3 3 0 1 2 3 Sarah 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel -- Sarah Goslee http://www.functionaldiversity.org -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com 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.
Re: [R] How to change the order of columns in a data frame?
Thank you Sarah, now it works!! Sarah Goslee sarah.gos...@gmail.com 17-02-2012 15:13 Sorry, it should be: fakedata[, order(pos)] A X1 X2 X3 X4 X5 X6 X7 X8 X9 1 0 1 2 3 4 5 6 7 8 9 2 0 1 2 3 4 5 6 7 8 9 3 0 1 2 3 4 5 6 7 8 9 Using order also ensures that non-sequential column ids will work: fakedata - data.frame(A=c(0,0,0), X1=c(1,1,1), X6=c(6,6,6), X7=c(7,7,7), X3=c(3,3,3), X4=c(4,4,4), X9=c(9,9,9), X2=c(2,2,2), X8=c(8,8,8)) pos - colnames(fakedata)[2:ncol(fakedata)] pos - c(1, 1+as.numeric(gsub(X, , pos))) fakedata A X1 X6 X7 X3 X4 X9 X2 X8 1 0 1 6 7 3 4 9 2 8 2 0 1 6 7 3 4 9 2 8 3 0 1 6 7 3 4 9 2 8 fakedata[, order(pos)] A X1 X2 X3 X4 X6 X7 X8 X9 1 0 1 2 3 4 6 7 8 9 2 0 1 2 3 4 6 7 8 9 3 0 1 2 3 4 6 7 8 9 Sarah 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: It does not work when using more variables, and my data frames usually contains about thousand columns... Best, Joel fakedata - data.frame(A=c(0,0,0), X1=c(1,1,1), X6=c(6,6,6), X7=c(7,7,7), X3=c(3,3,3), X4=c(4,4,4), X9=c(9,9,9), X2=c(2,2,2), X8=c(8,8,8), X5=c(5,5,5)) fakedata A X1 X6 X7 X3 X4 X9 X2 X8 X5 1 0 1 6 7 3 4 9 2 8 5 2 0 1 6 7 3 4 9 2 8 5 3 0 1 6 7 3 4 9 2 8 5 pos - colnames(fakedata)[2:ncol(fakedata)] pos [1] X1 X6 X7 X3 X4 X9 X2 X8 X5 pos - c(1, 1+as.numeric(gsub(X, , pos))) pos [1] 1 2 7 8 4 5 10 3 9 6 fakedata[, pos] A X1 X9 X2 X7 X3 X5 X6 X8 X4 1 0 1 9 2 7 3 5 6 8 4 2 0 1 9 2 7 3 5 6 8 4 3 0 1 9 2 7 3 5 6 8 4 Sarah Goslee sarah.gos...@gmail.com 17-02-2012 14:36 fakedata - data.frame(A=c(0,0,0), X2=c(2,2,2), X1=c(1,1,1), X3=c(3,3,3)) fakedata A X2 X1 X3 1 0 2 1 3 2 0 2 1 3 3 0 2 1 3 pos - colnames(fakedata)[2:ncol(fakedata)] pos - c(1, 1+as.numeric(gsub(X, , pos))) fakedata[, pos] A X1 X2 X3 1 0 1 2 3 2 0 1 2 3 3 0 1 2 3 Sarah 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk: Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel -- Sarah Goslee http://www.functionaldiversity.org -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[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] stepwise selection for conditional logistic regression
stepAIC works for an object of clogit. Weidong Gu On Fri, Feb 17, 2012 at 2:10 AM, Subha P. T. subha_...@yahoo.com wrote: Hi, Is there any function available to do stepwise selection of variables in Conditional(matched) logistic regression( clogit)? step, stepwise etc are failing in case of conditional logistic regression. Please help. Thanks P.T. Subha [[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] Error message in gamm. Problem with temporal correlation structure
eva, The problem is that the random effects and correlation structure that you have specified don't meet the restrictions required by lme (which gamm calls). You can see this by trying M0 -lme(H ~ Tillage , random=list(Block=~1), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Tillage, p = 1, q = 0)) which will fail because you have multiple observations of Year for each level of Tillage, and because the random effect and correlation formulae are incompatible. The multiple years problem could perhaps be solved by corARMA(form =~ Year|Tillage/Block, p = 1, q = 0) if that makes modelling sense? A couple of possible fixes are then... M1 -gamm(H ~ Tillage + s(Year, by =Tillage), random=list(Tillage=~1,Block=~1), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Tillage/Block, p = 1, q = 0)) or, if you really don't want that r.e. structure, then M2 -gamm(H ~ Tillage + s(Year, by =Tillage)+s(Block,bs=re), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Tillage/Block, p = 1, q = 0)) [I've assumed that the mapping between this message and the data you sent off list is DepVar=H, Treatment=Tillage] best, Simon On 17/02/12 09:35, HERNANDEZ PLAZA, MARIA EVA wrote: HELLO ALL, I AM GETTING AN ERROR MESSAGE WHEN TRYING TO RUN A GAMM MODEL LIKE THE ONE BELOW. I AM USING R VERSION 2.14.1 (2011-12-22) AND MGCV 1.7-12. M1-gamm(DepVar ~ Treatment + s(Year, by =Treatment), random=list(Block=~1), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Treatment, p = 1, q = 0)) THIS IS THE ERROR MESSAGE Error in `*tmp*`[[k]] : attempt to select less than one element I have 312 observations. I get the error when I introduce the correlation structure in the model. I have the same problem even if I use /corAR1() /or I set bs=�cr�. I also tried to increase the number of iterations using the control option, but I find the same problem. Is there any other way in which I could include the correlation structure? I would appreciate any suggestions thanks! eva [[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. -- Simon Wood, Mathematical Science, University of Bath BA2 7AY UK +44 (0)1225 386603 http://people.bath.ac.uk/sw283 __ 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 subset - why doesn't this work?
Hi Ajay, Like Jorge, I can't seem to reproduce the behavior you are worried about. mtcars[rownames(mtcars) != Valiant,] returns a 31x11 data.frame as expected. When you say it fails, what error message / result are you seeing? Michael On Fri, Feb 17, 2012 at 3:27 AM, Jorge I Velez jorgeivanve...@gmail.com wrote: Hi Ajay, In the first case, you need == instead of = : R mtcars[ rownames(mtcars) == Valiant, ] mpg cyl disp hp drat wt qsec vs am gear carb Valiant 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1 For the second case, R mtcars[rownames(mtcars) != Valiant,] will do it. See also ?subset. HTH, Jorge.- On Fri, Feb 17, 2012 at 3:02 AM, Ajay Askoolum wrote: data(mtcars) mtcars[rownames(mtcars)!=Valiant,] # fails mtcars[list(rownames(mtcars))!=Valiant,] # runs but I am not getting the expected result With the latter statement, I expected all rows except the one where the name is Valiant. I must have got something simple wrong; what is it? Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Load packages from source
On 17/02/2012 7:01 AM, David Cassany wrote: Hi all, I'm developing an R package and I'd like to load it easly while developing, debugging and testing. I would like to load it without having to install it. Installing it causes me some problems for debugging it, as the code file it is executing it not the one I'm editing. You can tell R to keep debugging information when it installs a package by setting the environment variable R_KEEP_PKG_SOURCE=yes or by a command line option to R CMD INSTALL (see the help via --help). It still won't be the same code file because it never is: but it will have references to it, and include formatting and comments. I've seen the function sourceDirectory from R.utils package which works quite fine for me, but would be just perfect to be able to load the package as it would be installed (handling dependences, namespaces and all this stuff). As far as I know there's nothing intermediate between sourceDirectory and installing a package, other than setting options when installing that can skip parts of the operation. 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.
[R] Standard errors from predict.gam versus predict.lm
I've got a small problem. I have some observational data (environmental samples: abiotic explanatory variable and biological response) to which I've fitted both a multiple linear regression model and also a gam (mgcv) using smooths for each term. The gam clearly fits far better than the lm model based on AIC (difference in AIC ~ 8), in addition the adjusted R squared for the gam is clearly better. I then want to make some plots of predicted values from both models with confidence intervals. So I can get my predictions usng predict(my.model(se.fit=TRUE)) My problem is that this results in the prediction se's (and consequent CI's for the mean prediction) being much wider for the gam than for the linear model. This seems rather counter-intuitive given that the gam appears to fit better, and hence I will find it hard to explain my choice of a gam model in a journal article, despite clear non-linearity. It's not so easy for me to post my own example. The following code gives a flavour, clearly in this instance the gam will fit MUCH better because it is the generating model. Even in this case, most gam se's line above the 1:1 line. In my example, with some observational data, the difference between linear and gam fit is not so pronounced but the gam still clearly fits better than linear, but all gam se's are WAY above their linear equivalents when used to predict for representative new data in order to present results as interaction plots. cheers Mike require(mgcv) require(MASS) dat - gamSim(1,n=200,dist=normal,scale=2) summary(b - gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)) summary(a - lm(y~x0 + x1 + x2 + x3,data=dat)) se.result - data.frame(linear.se=predict(a, se.fit=TRUE)$se.fit, gam.se=predict(b, se.fit=TRUE)$se.fit) with(se.result, eqscplot(linear.se, gam.se)) abline(a=0, b=1) -- This message (and any attachments) is for the recipient ...{{dropped:8}} __ 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] Plotting issue
Thank you for trying to improve your question, but it's still impossible to help: the problem is almost certainly in this block of code: plotting## year - 2005:2008 month- (jan,Feb,March,..Dec) for ( y in year) for (m in month) here I use Sp plot and plot map } } but given that the plotting code isn't here, it's hard to say what's wrong with it. If I had to guess, I'd suggest three possibilities: i) If you are getting the last plot consistently, it could be that you are overwriting your plot (you never said what device you are using or how you plan to deal with 48 plots) ii) You are referring to year and month in your loop, rather than y and m. iii) There are braces missing (there certainly are some from your code) so you aren't actually getting a real loop. Try to reread what I said about minimal reproducible examples in the other thread. Michael On Fri, Feb 17, 2012 at 5:08 AM, uday uday_143...@hotmail.com wrote: I have two different datasets 1) is in monthly format (obs) 2) yearly format (model) in obs I have 84 files ( 2003:2009)for different months in model I have 4 different files which has yearly data (2005:2008) So for calculating my requirement I need these both data sets. The sample calculations are as follows file_o-list.files(path=' ', pattern=0.2.text) # total number of files are 80 for ( i in 1:file_o){ #get data here I get Lat_o- Lon_o - time_o- gas_o- } file_t list.files(path=' ', pattern=fg.nc) for (j in 1:file_t){ #get data here I get Lat_t- Lon_t - time_t- gas_t- } nobs- length(Lat_o) for (k in 1:nobs){ # here it does some calculation and get some value which is gas_new } now I would like to plot this data for every month according to my observation data plotting## year - 2005:2008 month- (jan,Feb,March,..Dec) for ( y in year) for (m in month) here I use Sp plot and plot map } } what I would like to do is I want to plot data according to my observations taken ( its in month) but when I run my codes it plots same file from2005:2008 but it suppose to plot 48 different files for different months. I got stuck here, I am quit new in R. it would be very nice it somebody can tell me how to fix this problem. Uday -- View this message in context: http://r.789695.n4.nabble.com/Plotting-issue-tp4396832p4396832.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.
Re: [R] stepwise selection for conditional logistic regression
On Feb 17, 2012, at 2:10 AM, Subha P. T. wrote: Hi, Is there any function available to do stepwise selection of variables in Conditional(matched) logistic regression( clogit)? step, stepwise etc are failing in case of conditional logistic regression. Failing is open to a variety of interpretation. Can you offer an example and describe what you mean or quote an error message? I tested the advice in this posting from C. Berry with the example in ? clogit and got appropriate results: http://finzi.psych.upenn.edu/Rhelp10/2010-January/226165.html Please help. Stepwise procedures are supported somewhat grudgingly on r-help. You ought to read some of the critical comments about stepwise procedures in the Archives: http://search.r-project.org/cgi-bin/namazu.cgi?query=stepwise+significancemax=100result=normalsort=scoreidxname=functionsidxname=Rhelp08idxname=Rhelp10idxname=Rhelp02 Another search strategy might be stepwise Harrell. -- David Winsemius, MD West Hartford, CT __ 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] Standard errors from predict.gam versus predict.lm
Mike, Isn't this just an example of the wrong model giving a spurious impression of precision? or more accurately, precision at the expense of accuracy? Here's a linear model example of the same thing... set.seed(1) n - 400 x - runif(n)-.5 y - 2+ x*.2+ x^2 + rnorm(n)*.5 m1 - lm(y~1) m2 - lm(y~x+I(x^2)) mean(predict(m1,se=TRUE)$se.fit) #[1] 0.02641367 mean(predict(m2,se=TRUE)$se.fit) #[1] 0.04363921 ... so the wrong model (m1, a constant) gives much lower se than the correct model (m2, a quadratic). best, Simon On 17/02/12 14:57, Dunbar, Michael J. wrote: I've got a small problem. I have some observational data (environmental samples: abiotic explanatory variable and biological response) to which I've fitted both a multiple linear regression model and also a gam (mgcv) using smooths for each term. The gam clearly fits far better than the lm model based on AIC (difference in AIC ~ 8), in addition the adjusted R squared for the gam is clearly better. I then want to make some plots of predicted values from both models with confidence intervals. So I can get my predictions usng predict(my.model(se.fit=TRUE)) My problem is that this results in the prediction se's (and consequent CI's for the mean prediction) being much wider for the gam than for the linear model. This seems rather counter-intuitive given that the gam appears to fit better, and hence I will find it hard to explain my choice of a gam model in a journal article, despite clear non-linearity. It's not so easy for me to post my own example. The following code gives a flavour, clearly in this instance the gam will fit MUCH better because it is the generating model. Even in this case, most gam se's line above the 1:1 line. In my example, with some observational data, the difference between linear and gam fit is not so pronounced but the gam still clearly fits better than linear, but all gam se's are WAY above their linear equivalents when used to predict for representative new data in order to present results as interaction plots. cheers Mike require(mgcv) require(MASS) dat- gamSim(1,n=200,dist=normal,scale=2) summary(b- gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat)) summary(a- lm(y~x0 + x1 + x2 + x3,data=dat)) se.result- data.frame(linear.se=predict(a, se.fit=TRUE)$se.fit, gam.se=predict(b, se.fit=TRUE)$se.fit) with(se.result, eqscplot(linear.se, gam.se)) abline(a=0, b=1) -- Simon Wood, Mathematical Science, University of Bath BA2 7AY UK +44 (0)1225 386603 http://people.bath.ac.uk/sw283 __ 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] stepwise selection for conditional logistic regression
Also, when you're doing reading through David's suggestions: On Fri, Feb 17, 2012 at 10:41 AM, David Winsemius dwinsem...@comcast.net wrote: [snip] Stepwise procedures are supported somewhat grudgingly on r-help. You ought to read some of the critical comments about stepwise procedures in the Archives: http://search.r-project.org/cgi-bin/namazu.cgi?query=stepwise+significancemax=100result=normalsort=scoreidxname=functionsidxname=Rhelp08idxname=Rhelp10idxname=Rhelp02 Another search strategy might be stepwise Harrell. Just keep in the back of your mind somewhere that the glmnet library can fit GLMs via penalized maximum likelihood [and] ... Fits linear, logistic and multinomial, poisson, and Cox regression models (taken from `?glmnet`) over a grid of lambda params for you. HTH, -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] lmer - error message
I think my problem is that I can't incorporate the 'lake' variable in a fixed-effect interaction because it is only has one binary observation. But I don't know what to do to be able to fit this model. Any help would be greatly appreciated! -Sean In principle you should be able to fit this model, but the error message is telling you that there are numeric problems -- it may just be that your data are a little too sparse in some direction. Yes. Consider the collinearity between Age and Year, i.e. for a given cohort (mos or all captured by fishID ?) they are essentially the same variable with different units. So I would suspect the problem is you are over fitting those. A few suggestions: * try centering Age, or re-introducing the intercept, to see if you can get something to work. * You _might_ try the development version of lme4 (lme4Eigen, on r-forge) * plot your data to see if you see anything odd about the data * perhaps try making Year a fixed effect -- 4 levels is fairly small for a random effect * Ask further questions on the r-sig-mixed-models mailing list. Ben Bolker Add one more to those: make sure your random effects are indeed crossed. If they are nested (without knowing anything about your data, just given their names that's a possibility), you could try nlme::lme. Elai __ 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] QR codes can be generated with R-cran?
Srs. QR codes (barcode) can be generated with R-cran?, there is a package that allows it. Watch for your answers. Agustín M. Carpe Diem! [[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] Neighbour List to Matrix
Hi everybody!I'm a new user of R. I've been having a look to sotored mails in list, but I've been not able to find one suiting to my need. The issue is I have a neighbour list in a TXT file, just as lists generated by social network softwares (f.i. Pajek), where you get Field1, Field2, Value. In my case, list follow the next way:ID1 IDP2SUMVAL1 56 0.0659358951900 0.044110185114090.19631419734 0.071320388383 0.0162695643529 0.0113592393883 0.01224253331242 0.01655892443 0.00430702447 0.004699821416 0.00473511257 0.010324926516 0.0112505045498 0.0097098585502 0.0047757495508 0.031411560 The question is, how can I convert this list into a matrix? I think is good to know that list contain more than 60 rows with around 14000 nodes (participants). If it's possible I would like to know all necessary stetps to do this. This is: load the TXT file, create the matrix through data contained in it, and finally to export to CSV or TXT file. Any idea or suggestion will be wellcome!Thank you very much in advance.AJ [[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] basic help: graph multivariate analysis.
Hey guys, I'd really appreciate any help. I have a multivariate analysis done, the output of which is: GraphData -read.table(eigen.coa) GraphData V1 V2 V3 V4 1 1 0.371970 0.8552 0.8552 2 2 0.061785 0.1420 0.9972 3 3 0.001211 0.0028 1. 4 4 0.00 0. 1. summary(GraphData) V1 V2 V3 V4 Min. :1.00 Min. :0.000 Min. :0. Min. :0.8552 1st Qu.:1.75 1st Qu.:0.0009082 1st Qu.:0.0021 1st Qu.:0.9617 Median :2.50 Median :0.0314980 Median :0.0724 Median :0.9986 Mean :2.50 Mean :0.1087415 Mean :0.2500 Mean :0.9631 3rd Qu.:3.25 3rd Qu.:0.1393312 3rd Qu.:0.3203 3rd Qu.:1. Max. :4.00 Max. :0.3719700 Max. :0.8552 Max. :1. (I'm sorry if that is not the right format, please let me know if its not) I want to plot these multivariate results on a graph. i have read through various pdf's (e.g. using r for data analysis and graphics and simple R) but i'm still stuck. Could anyone help explain the commands needed to turn the above data into any sort of graphical form? Any help is appreciated. Aoife -- View this message in context: http://r.789695.n4.nabble.com/basic-help-graph-multivariate-analysis-tp4397477p4397477.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] How to change the order of columns in a data frame?
Hi Joel, to replace the colnames: colnames(dataframe - )gsub(X,,colnames(dataframe)) to order by colnames: dataframe - dataframe[,colnames(dataframe)] Alfredo 2012/2/17 Joel Fürstenberg-Hägg jo...@life.ku.dk Dear all, I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below. colnames(pos1) [1] X X1 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X2 X20 X3 X4 X5 X6 X7 X8 X9 pos1[1:5,1:5] X X1 X10 X11 X12 1 100.5 7949.469 18509.064 8484.969 17401.056 2 101.5 3080.058 7794.691 3211.323 8211.058 3 102.5 1854.347 4347.571 1783.846 4827.338 4 103.5 2064.441 8421.746 2012.536 8363.785 5 104.5 9650.402 26637.926 10730.647 27053.421 I am trying to first change the first column name to something without an X and save as a vector. I would then remove the X from each position use the vector for renaming the columns. Then the column 2-n could be ordered, I hope... colnames(pos)[1] - Mass columnNames - colnames(pos) Does any of you have an idea how to do this, or perhaps there is a smoother solution? Would it be easier to solve it if the contents of the first column were extracted and used as row names instead? Best regards, Joel [[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] Where command in ctree (party)
Hi, I'm running into the same issue. I run is.factor() on training data and validation data. All returned false. -- View this message in context: http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p4397640.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] editing import data, strings
Regards. I'm a beginner in programing, so I have a basic question for you. If someone could help me please.. I want to create a function, which will be able to export files from excel. I tried with a - read.csv(file, sep =,, as.is = TRUE, row.names = 1, header = TRUE), .. but instead of numbers, it gives me strings for example: 299,311. I can handle this string for example: b - 299,311 as.numeric(gsub(,, , b)) 299311 Now, I´m interested how to inport it from that file,. I tried with a - read.csv(file, sep =,, as.is = TRUE, row.names = 1, header = TRUE) a - gsub(,, , a) a - as.numeric(a) But it doesn't work. I used search engine on forum, but didn't find any function that I could help with. I would be very gratefull if someone could help me. Gaja -- View this message in context: http://r.789695.n4.nabble.com/editing-import-data-strings-tp4397899p4397899.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] Where command in ctree (party)
i run class(). Both have the same class. -- View this message in context: http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p4397693.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] basic help: graph multivariate analysis.
There are lots of multivariate graphs.perhaps browsing this gallery will give you some idea of what you want (example code is provided): http://addictedtor.free.fr/graphiques/ This blog also does a nice job of introducing some graphs with the ggplot2 package: https://learnr.wordpress.com/ Michael On Fri, Feb 17, 2012 at 9:58 AM, aoife aoife.m.dohe...@gmail.com wrote: Hey guys, I'd really appreciate any help. I have a multivariate analysis done, the output of which is: GraphData -read.table(eigen.coa) GraphData V1 V2 V3 V4 1 1 0.371970 0.8552 0.8552 2 2 0.061785 0.1420 0.9972 3 3 0.001211 0.0028 1. 4 4 0.00 0. 1. summary(GraphData) V1 V2 V3 V4 Min. :1.00 Min. :0.000 Min. :0. Min. :0.8552 1st Qu.:1.75 1st Qu.:0.0009082 1st Qu.:0.0021 1st Qu.:0.9617 Median :2.50 Median :0.0314980 Median :0.0724 Median :0.9986 Mean :2.50 Mean :0.1087415 Mean :0.2500 Mean :0.9631 3rd Qu.:3.25 3rd Qu.:0.1393312 3rd Qu.:0.3203 3rd Qu.:1. Max. :4.00 Max. :0.3719700 Max. :0.8552 Max. :1. (I'm sorry if that is not the right format, please let me know if its not) I want to plot these multivariate results on a graph. i have read through various pdf's (e.g. using r for data analysis and graphics and simple R) but i'm still stuck. Could anyone help explain the commands needed to turn the above data into any sort of graphical form? Any help is appreciated. Aoife -- View this message in context: http://r.789695.n4.nabble.com/basic-help-graph-multivariate-analysis-tp4397477p4397477.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.
Re: [R] Error message in gamm. Problem with temporal correlation structure
Thank you Simon, that works well. I had tried previously m1 -gamm(H ~ Tillage + s(Year, by =Tillage), random=list(Block=~ Tillage), na.action=na.omit, data =mydata, correlation = corARMA(form =~ Year|Tillage/Block, p = 1, q = 0)) and that gave me convergence problems. Thank you! eva Quoting Simon Wood: eva, The problem is that the random effects and correlation structure that you have specified don't meet the restrictions required by lme (which gamm calls). You can see this by trying M0 -lme(H ~ Tillage , random=list(Block=~1), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Tillage, p = 1, q = 0)) which will fail because you have multiple observations of Year for each level of Tillage, and because the random effect and correlation formulae are incompatible. The multiple years problem could perhaps be solved by corARMA(form =~ Year|Tillage/Block, p = 1, q = 0) if that makes modelling sense? A couple of possible fixes are then... M1 -gamm(H ~ Tillage + s(Year, by =Tillage), random=list(Tillage=~1,Block=~1), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Tillage/Block, p = 1, q = 0)) or, if you really don't want that r.e. structure, then M2 -gamm(H ~ Tillage + s(Year, by =Tillage)+s(Block,bs=re), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Tillage/Block, p = 1, q = 0)) [I've assumed that the mapping between this message and the data you sent off list is DepVar=H, Treatment=Tillage] best, Simon On 17/02/12 09:35, HERNANDEZ PLAZA, MARIA EVA wrote: HELLO ALL, I AM GETTING AN ERROR MESSAGE WHEN TRYING TO RUN A GAMM MODEL LIKE THE ONE BELOW. I AM USING R VERSION 2.14.1 (2011-12-22) AND MGCV 1.7-12. M1-gamm(DepVar ~ Treatment + s(Year, by =Treatment), random=list(Block=~1), na.action=na.omit, data = mydata, correlation = corARMA(form =~ Year|Treatment, p = 1, q = 0)) THIS IS THE ERROR MESSAGE Error in `*tmp*`[[k]] : attempt to select less than one element I have 312 observations. I get the error when I introduce the correlation structure in the model. I have the same problem even if I use /corAR1() /or I set bs=ââ¬ï¿¾crââ¬ï¿¾. I also tried to increase the number of iterations using the control option, but I find the same problem. Is there any other way in which I could include the correlation structure? I would appreciate any suggestions thanks! eva [[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. -- Simon Wood, Mathematical Science, University of Bath BA2 7AY UK +44 (0)1225 386603 http://people.bath.ac.uk/sw283 [[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] Hoe to resample matrices to test for the robustness of their correlation
Hello I have several populations where I have morphology and diet for each individual. I am interested in the correlation between diet and morphological distances. However the number of individuals in each population ranges from 22 to 80 individuals. I have looked at the correlation diet-morphology for each population and (not surprisingly) the correlation coefficientis is highly correlated with the number of individuals per population. I would like to resample (without replacement) the populations with 60-80 individuals and get random samplings of 30 individuals (1000 times). I would like to get a correlation coefficient distribution against which to test the original value of the correlation. I guess it is possible do this, however I have never written a script in R and I am not familiar with resampling techniques at all. Any help with coding will be greatly appreciated Thank you -- View this message in context: http://r.789695.n4.nabble.com/Hoe-to-resample-matrices-to-test-for-the-robustness-of-their-correlation-tp4397915p4397915.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] editing import data, strings
If you know all your data should be numeric, you could perhaps try something like this: apply(a, 2, function(x) as.numeric(gsub( , , x))) but it can't be tested without your actual data. (Look at dput() for the best way to send data by email) Michael On Fri, Feb 17, 2012 at 12:24 PM, gaja gajahor...@hotmail.com wrote: Regards. I'm a beginner in programing, so I have a basic question for you. If someone could help me please.. I want to create a function, which will be able to export files from excel. I tried with a - read.csv(file, sep =,, as.is = TRUE, row.names = 1, header = TRUE), .. but instead of numbers, it gives me strings for example: 299,311. I can handle this string for example: b - 299,311 as.numeric(gsub(,, , b)) 299311 Now, I´m interested how to inport it from that file,. I tried with a - read.csv(file, sep =,, as.is = TRUE, row.names = 1, header = TRUE) a - gsub(,, , a) a - as.numeric(a) But it doesn't work. I used search engine on forum, but didn't find any function that I could help with. I would be very gratefull if someone could help me. Gaja -- View this message in context: http://r.789695.n4.nabble.com/editing-import-data-strings-tp4397899p4397899.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.
Re: [R] Different cp values in rpart() using plotcp() and printcp()
On 17.02.2012 11:18, silje skår wrote: hi, I have a question regarding cp values in rpart(). When I use plotcp() I get a figure with cp values on the x-axsis, but then I use printcp() the cp values in that list are different from the values in the figure by plotcp(). Does someone know why? printcp() gives the minimal cp for which the pruning happens. plotcp() plots against the geometric mean (see the help pages!) Uwe ligges Silje [[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] editing import data, strings
At least post the first 10 lines of the file so that we can see what it is. It may be that some of the data is enclosed in quotes, but it is hard to tell without seeing the actual data. On Fri, Feb 17, 2012 at 12:24 PM, gaja gajahor...@hotmail.com wrote: Regards. I'm a beginner in programing, so I have a basic question for you. If someone could help me please.. I want to create a function, which will be able to export files from excel. I tried with a - read.csv(file, sep =,, as.is = TRUE, row.names = 1, header = TRUE), .. but instead of numbers, it gives me strings for example: 299,311. I can handle this string for example: b - 299,311 as.numeric(gsub(,, , b)) 299311 Now, I´m interested how to inport it from that file,. I tried with a - read.csv(file, sep =,, as.is = TRUE, row.names = 1, header = TRUE) a - gsub(,, , a) a - as.numeric(a) But it doesn't work. I used search engine on forum, but didn't find any function that I could help with. I would be very gratefull if someone could help me. Gaja -- View this message in context: http://r.789695.n4.nabble.com/editing-import-data-strings-tp4397899p4397899.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] Neighbour List to Matrix
You might want to post a better example of what your data looks like. In the email, it is hard to tell how to split the data into rows that can be read with three fields since it looks like the data is composed of pairs of numbers. On Fri, Feb 17, 2012 at 7:42 AM, A J anxu...@hotmail.com wrote: Hi everybody!I'm a new user of R. I've been having a look to sotored mails in list, but I've been not able to find one suiting to my need. The issue is I have a neighbour list in a TXT file, just as lists generated by social network softwares (f.i. Pajek), where you get Field1, Field2, Value. In my case, list follow the next way:ID1 IDP2 SUMVAL1 56 0.0659358951 900 0.0441101851 1409 0.1963141973 4 0.0713203883 83 0.0162695643 529 0.0113592393 883 0.0122425333 1242 0.0165589244 3 0.0043070244 7 0.0046998214 16 0.0047351125 7 0.0103249265 16 0.0112505045 498 0.0097098585 502 0.0047757495 508 0.031411560 The question is, how can I convert this list into a matrix? I think is good to know that list contain more than 60 rows with around 14000 nodes (participants). If it's possible I would like to know all necessary stetps to do this. This is: load the TXT file, create the matrix through data contained in it, and finally to export to CSV or TXT file. Any idea or suggestion will be wellcome!Thank you very much in advance.AJ [[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 Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] Neighbour List to Matrix
Sorry too much. I was convinced it was able to view well. So, the structure of my data set is something like this: ID1 IDP2 SUMVAL 1 56 0.0659358951 900 0.0441101851 1409 0.1963141973 4 0.0713203883 83 0.0162695643 529 0.0113592393 883 0.0122425333 1242 0.0165589244 3 0.0043070244 7 0.0046998214 16 0.0047351125 7 0.0103249265 16 0.0112505045 498 0.0097098585 502 0.0047757495 508 0.031411560... Summarizing: I have all data recorded in a TXT file, and I would like, after loading in R, transform this list into a matrix (complete matrix, not half) in order to export to CSV or TXT finally.Thank you very much for everything. Best, AJ Date: Fri, 17 Feb 2012 13:12:55 -0500 Subject: Re: [R] Neighbour List to Matrix From: jholt...@gmail.com To: anxu...@hotmail.com CC: r-help@r-project.org You might want to post a better example of what your data looks like. In the email, it is hard to tell how to split the data into rows that can be read with three fields since it looks like the data is composed of pairs of numbers. [[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] Neighbour List to Matrix
Is this what you are after: x - read.table(text = ID1 IDP2 SUMVAL + 1 56 0.065935895 + 1 900 0.044110185 + 1 1409 0.196314197 + 3 4 0.071320388 + 3 83 0.016269564 + 3 529 0.011359239 + 3 883 0.012242533 + 3 1242 0.016558924 + 4 3 0.004307024 + 4 7 0.004699821 + 4 16 0.004735112 + 5 7 0.010324926 + 5 16 0.011250504 + 5 498 0.009709858 + 5 502 0.004775749 + 5 508 0.031411560, header = TRUE) str(x) # dataframe 'data.frame': 16 obs. of 3 variables: $ ID1 : int 1 1 1 3 3 3 3 3 4 4 ... $ IDP2 : int 56 900 1409 4 83 529 883 1242 3 7 ... $ SUMVAL: num 0.0659 0.0441 0.1963 0.0713 0.0163 ... x.m - as.matrix(x) str(x.m) # matrix num [1:16, 1:3] 1 1 1 3 3 3 3 3 4 4 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:3] ID1 IDP2 SUMVAL head(x.m) ID1 IDP2 SUMVAL [1,] 1 56 0.06593589 [2,] 1 900 0.04411019 [3,] 1 1409 0.19631420 [4,] 34 0.07132039 [5,] 3 83 0.01626956 [6,] 3 529 0.01135924 At this point you could use 'wrtie.csv' to create a CSV file. On Fri, Feb 17, 2012 at 1:42 PM, A J anxu...@hotmail.com wrote: Sorry too much. I was convinced it was able to view well. So, the structure of my data set is something like this: ID1 IDP2 SUMVAL 1 56 0.065935895 1 900 0.044110185 1 1409 0.196314197 3 4 0.071320388 3 83 0.016269564 3 529 0.011359239 3 883 0.012242533 3 1242 0.016558924 4 3 0.004307024 4 7 0.004699821 4 16 0.004735112 5 7 0.010324926 5 16 0.011250504 5 498 0.009709858 5 502 0.004775749 5 508 0.031411560 ... Summarizing: I have all data recorded in a TXT file, and I would like, after loading in R, transform this list into a matrix (complete matrix, not half) in order to export to CSV or TXT finally. Thank you very much for everything. Best, AJ Date: Fri, 17 Feb 2012 13:12:55 -0500 Subject: Re: [R] Neighbour List to Matrix From: jholt...@gmail.com To: anxu...@hotmail.com CC: r-help@r-project.org You might want to post a better example of what your data looks like. In the email, it is hard to tell how to split the data into rows that can be read with three fields since it looks like the data is composed of pairs of numbers. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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] Where command in ctree (party)
On Fri, 17 Feb 2012, josephw wrote: i run class(). Both have the same class. Without a reproducible example it is hard to say what is going on here. All columns of the learning and the test data need to have (a) the same name, (b) the same class, (c) the same levels in case they are factors. -- View this message in context: http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p4397693.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] Job posting for programmer with database skills
NYC-based equity asset management company is seeking a junior-level programmer with R, VBA, and MS-SQL skills. HTML skill is a plus. This permanent, full-time position will involve working on projects and improving our daily processes. Finance knowledge is helpful, but not necessary. We are an equal opportunity employer with a generous benefits package. Immediate opening. Please forward resume and salary requirements to tom.rawli...@rothschild.com. *** This message is for the named person's use only. It may\...{{dropped:14}} __ 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] editing import data, strings
Thanx for posting. :) I'm posting a link to excel file, same as I want import to table. Its dl link, don't be mad, hehe http://spreadsheets.google.com/pub?key=phAwcNAVuyj0XOoBL_n5tAQoutput=csv Thanx,G. ps: @Michael Weylandt; Thanx for your code,... I tried to used it, but unsucsesfully. I really don't know what the x stands for. I hope I will be able to solve this problem. Gaja -- View this message in context: http://r.789695.n4.nabble.com/editing-import-data-strings-tp4397899p4398120.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] Where command in ctree (party)
I was able to narrow down to a column that has different types using featurefields-c(7, 17, 19, 20, 22, 33, 35, 36, 38, 44:132) flag - rep(0, ncol(data)) for (i in featurefields) { flag[i] - class(data[,i]) != class(validdata[,i]) } It is an integer class in the training data but is numeric in the validation data even though unique(valid[,88]) shows 0 and 1. -Original Message- From: Achim Zeileis [mailto:achim.zeil...@uibk.ac.at] Sent: Friday, February 17, 2012 10:51 AM To: Joseph Wang Cc: r-help@r-project.org Subject: Re: [R] Where command in ctree (party) On Fri, 17 Feb 2012, josephw wrote: i run class(). Both have the same class. Without a reproducible example it is hard to say what is going on here. All columns of the learning and the test data need to have (a) the same name, (b) the same class, (c) the same levels in case they are factors. -- View this message in context: http://r.789695.n4.nabble.com/Where-command-in-ctree-party-tp3264187p4 397693.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.
Re: [R] Neighbour List to Matrix
I don't know why data are not well shown... I have attached a PDF file to this message with the structure of the begining list and the final matrix one. I think I have no explain the issue in a right way. Sorry for the inconveniences. The last thing I want is to disturb with technical questions... Best, AJ Date: Fri, 17 Feb 2012 13:49:40 -0500 Subject: Re: [R] Neighbour List to Matrix From: jholt...@gmail.com To: anxu...@hotmail.com CC: r-help@r-project.org Is this what you are after: x - read.table(text = ID1 IDP2 SUMVAL + 1 56 0.065935895 + 1 900 0.044110185 + 1 1409 0.196314197 + 3 4 0.071320388 + 3 83 0.016269564 + 3 529 0.011359239 + 3 883 0.012242533 + 3 1242 0.016558924 + 4 3 0.004307024 + 4 7 0.004699821 + 4 16 0.004735112 + 5 7 0.010324926 + 5 16 0.011250504 + 5 498 0.009709858 + 5 502 0.004775749 + 5 508 0.031411560, header = TRUE) str(x) # dataframe 'data.frame': 16 obs. of 3 variables: $ ID1 : int 1 1 1 3 3 3 3 3 4 4 ... $ IDP2 : int 56 900 1409 4 83 529 883 1242 3 7 ... $ SUMVAL: num 0.0659 0.0441 0.1963 0.0713 0.0163 ... x.m - as.matrix(x) str(x.m) # matrix num [1:16, 1:3] 1 1 1 3 3 3 3 3 4 4 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:3] ID1 IDP2 SUMVAL head(x.m) ID1 IDP2 SUMVAL [1,] 1 56 0.06593589 [2,] 1 900 0.04411019 [3,] 1 1409 0.19631420 [4,] 34 0.07132039 [5,] 3 83 0.01626956 [6,] 3 529 0.01135924 At this point you could use 'wrtie.csv' to create a CSV file. On Fri, Feb 17, 2012 at 1:42 PM, A J anxu...@hotmail.com wrote: Sorry too much. I was convinced it was able to view well. So, the structure of my data set is something like this: ID1 IDP2 SUMVAL 1 56 0.065935895 1 900 0.044110185 1 1409 0.196314197 3 4 0.071320388 3 83 0.016269564 3 529 0.011359239 3 883 0.012242533 3 1242 0.016558924 4 3 0.004307024 4 7 0.004699821 4 16 0.004735112 5 7 0.010324926 5 16 0.011250504 5 498 0.009709858 5 502 0.004775749 5 508 0.031411560 ... Summarizing: I have all data recorded in a TXT file, and I would like, after loading in R, transform this list into a matrix (complete matrix, not half) in order to export to CSV or TXT finally. Thank you very much for everything. Best, AJ Date: Fri, 17 Feb 2012 13:12:55 -0500 Subject: Re: [R] Neighbour List to Matrix From: jholt...@gmail.com To: anxu...@hotmail.com CC: r-help@r-project.org You might want to post a better example of what your data looks like. In the email, it is hard to tell how to split the data into rows that can be read with three fields since it looks like the data is composed of pairs of numbers. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. sample.pdf Description: Adobe PDF document __ 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] covariance
can any one please tell me how can I Compute the covariance matrix of (Y) which is 5 variables .. without using a built-in function?? 2) how (cov) works ( I need to get the details for this function ??? -- View this message in context: http://r.789695.n4.nabble.com/covariance-tp4398242p4398242.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] covariance
Yes, the function is based on the idea that you have two random variables, X and Y and the covariance is then computed as Cov(x,y) = E[(X - E(X)) (Y - E(Y))] Where E[.] is the expectation operator. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ali2006 Sent: Friday, February 17, 2012 2:37 PM To: r-help@r-project.org Subject: [R] covariance can any one please tell me how can I Compute the covariance matrix of (Y) which is 5 variables .. without using a built-in function?? 2) how (cov) works ( I need to get the details for this function ??? -- View this message in context: http://r.789695.n4.nabble.com/covariance- tp4398242p4398242.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.
Re: [R] Neighbour List to Matrix
On Feb 17, 2012, at 2:19 PM, A J wrote: I don't know why data are not well shown... I have attached a PDF file to this message with the structure of the begining list and the final matrix one. You should have attached the sample.txt file. I think I have no explain the issue in a right way. Sorry for the inconveniences. The last thing I want is to disturb with technical questions... Best, AJ nbrs - read.table(text=ID1 IDP2 SUMVAL 1 2 0.065 1 3 0.044 3 1 0.071 3 4 0.016 3 5 0.011 4 3 0.004 4 7 0.004 4 9 0.004 5 4 0.010 5 6 0.011 5 8 0.009 5 9 0.004, header=TRUE) mnbrs - matrix(NA, ncol=max(c(nbrs$ID1, nbrs$IDP2)), nrow=max(c(nbrs$ID1, nbrs$IDP2))) mnbrs[as.matrix(nbrs[,1:2]) ]- nbrs$SUMVAL mnbrs # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,]NA 0.065 0.044NANANANANANA [2,]NANANANANANANANANA [3,] 0.071NANA 0.016 0.011NANANANA [4,]NANA 0.004NANANA 0.004NA 0.004 [5,]NANANA 0.010NA 0.011NA 0.009 0.004 [6,]NANANANANANANANANA [7,]NANANANANANANANANA [8,]NANANANANANANANANA [9,]NANANANANANANANANA \\\ ' Then type: ?write.matrix David Winsemius, MD West Hartford, CT __ 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] covariance
This sounds remarkably like homework. You can address your own issue using the built-in help system and R's capability to allow you to view source code for functions, but we can't help you do your assignments. Sarah On Fri, Feb 17, 2012 at 2:36 PM, Ali2006 nasser-d2...@hotmail.com wrote: can any one please tell me how can I Compute the covariance matrix of (Y) which is 5 variables .. without using a built-in function?? 2) how (cov) works ( I need to get the details for this function ??? -- 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] convert zoo object to standard R object so I can plot and output to csv file
Another newbie question I got the 1 minute spine interpolation and 15 mean aggregation working with many thanks to Gabor Grothendieck using Zoo functions. I got a tip from Hasan Diwan to look at xts but it seemed I would make better progress using code from Gabor. Now I'm having trouble plotting this zoo object. I'm thinking I want a function to split the zoo object back to a regular R object with x time values and y values so I can plot using plot functions I'm familiar with. What is the vector name that has the values (e.g. the first value is 432.2189) I also got the 15 minute aggregation mean working - I'm happy about that also. In addition next I'll want to write out a csv. file of the 15min block aggregated mean data. Here is the trial data and code I used so far. Lines - 10/11/2011 23:30:01 432.22 10/11/2011 23:31:17 432.32 10/11/2011 23:35:00 432.32 10/11/2011 23:36:18 432.22 10/11/2011 23:37:18 432.72 10/11/2011 23:39:19 432.23 10/11/2011 23:40:02 432.23 10/11/2011 23:45:00 432.23 10/11/2011 23:45:20 429.75 10/11/2011 23:46:20 429.65 10/11/2011 23:50:00 429.65 10/11/2011 23:51:22 429.75 10/11/2011 23:55:01 429.75 10/11/2011 23:56:23 429.55 10/12/2011 0:00:07 429.55 10/12/2011 0:01:24 429.95 10/12/2011 0:05:00 429.95 10/12/2011 0:06:25 429.85 10/12/2011 0:10:00 429.85 10/12/2011 0:11:26 428.85 10/12/2011 0:15:00 428.85 10/12/2011 0:20:03 428.85 10/12/2011 0:21:29 428.75 10/12/2011 0:25:01 428.75 10/12/2011 0:30:01 428.75 10/12/2011 0:31:31 428.75 library(zoo) library(chron) fmt - %m/%d/%Y %H:%M:%S toChron - function(d, t) as.chron(paste(d, t), format = fmt) z - read.zoo(text = Lines, index = 1:2, FUN = toChron) # 1 minute spline fit m1 - times(00:01:00) g - seq(trunc(start(z), m1), end(z), by = m1) na.spline(z, xout = g) # this did what I want but what is the vector name? # 15 minute aggregates m15 - times(00:15:00) ag15 - aggregate(z, trunc(time(z), m15), mean) the results of the na.spline(z, xout = g) function below (10/11/11 23:30:00) (10/11/11 23:31:00) (10/11/11 23:32:00) (10/11/11 23:33:00) (10/11/11 23:34:00) (10/11/11 23:35:00) 432.2189432.2950432.3869 432.4584432.4545432.3200 (10/11/11 23:36:00) (10/11/11 23:37:00) (10/11/11 23:38:00) (10/11/11 23:39:00) (10/11/11 23:40:00) (10/11/11 23:41:00) 432.1639432.5834432.7443 432.3624432.2095433.8208 (10/11/11 23:42:00) (10/11/11 23:43:00) (10/11/11 23:44:00) (10/11/11 23:45:00) (10/11/11 23:46:00) (10/11/11 23:47:00) 436.3606438.0969437.2974 432.2300428.9265430.6503 (10/11/11 23:48:00) (10/11/11 23:49:00) (10/11/11 23:50:00) (10/11/11 23:51:00) (10/11/11 23:52:00) (10/11/11 23:53:00) 430.8493430.2351429.6500 429.6715429.8502429.9054 (10/11/11 23:54:00) (10/11/11 23:55:00) (10/11/11 23:56:00) (10/11/11 23:57:00) (10/11/11 23:58:00) (10/11/11 23:59:00) 429.8623429.7522429.6074 429.4636429.3664429.3678 (10/12/11 00:00:00) (10/12/11 00:01:00) (10/12/11 00:02:00) (10/12/11 00:03:00) (10/12/11 00:04:00) (10/12/11 00:05:00) 429.5200429.8310430.0703 430.1312430.0707429.9500 (10/12/11 00:06:00) (10/12/11 00:07:00) (10/12/11 00:08:00) (10/12/11 00:09:00) (10/12/11 00:10:00) (10/12/11 00:11:00) 429.8495429.9134430.0879 430.1446429.8500429.1407 (10/12/11 00:12:00) (10/12/11 00:13:00) (10/12/11 00:14:00) (10/12/11 00:15:00) (10/12/11 00:16:00) (10/12/11 00:17:00) 428.6042428.4933428.6367 428.8500428.9834429.0264 (10/12/11 00:18:00) (10/12/11 00:19:00) (10/12/11 00:20:00) (10/12/11 00:21:00) (10/12/11 00:22:00) (10/12/11 00:23:00) 429.0031428.9376428.8542 428.7773428.7315428.7217 (10/12/11 00:24:00) (10/12/11 00:25:00) (10/12/11 00:26:00) (10/12/11 00:27:00) (10/12/11 00:28:00) (10/12/11 00:29:00) 428.7330428.7498428.7594 428.7615428.7588428.7541 (10/12/11 00:30:00) (10/12/11 00:31:00) 428.7500428.7491 the results from when I enter ag15 in the R command line - which looks correct (10/11/11 23:30:00) (10/11/11 23:45:00) (10/12/11 00:00:00) (10/12/11 00:15:00) (10/12/11 00:30:00) 432.3229430.0471429.6667 428.8000428.7500 -- View this message in context:
Re: [R] covariance
On Feb 17, 2012, at 2:36 PM, Ali2006 wrote: can any one please tell me how can I Compute the covariance matrix of (Y) which is 5 variables .. without using a built-in function?? 2) how (cov) works ( I need to get the details for this function ??? http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf -- David Winsemius, MD West Hartford, CT __ 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] convert zoo object to standard R object so I can plot and output to csv file
?write.zoo Perhaps with sep = , if you have multiple columns. Michael On Fri, Feb 17, 2012 at 2:56 PM, Henry hcco...@lbl.gov wrote: Another newbie question I got the 1 minute spine interpolation and 15 mean aggregation working with many thanks to Gabor Grothendieck using Zoo functions. I got a tip from Hasan Diwan to look at xts but it seemed I would make better progress using code from Gabor. Now I'm having trouble plotting this zoo object. I'm thinking I want a function to split the zoo object back to a regular R object with x time values and y values so I can plot using plot functions I'm familiar with. What is the vector name that has the values (e.g. the first value is 432.2189) I also got the 15 minute aggregation mean working - I'm happy about that also. In addition next I'll want to write out a csv. file of the 15min block aggregated mean data. Here is the trial data and code I used so far. Lines - 10/11/2011 23:30:01 432.22 10/11/2011 23:31:17 432.32 10/11/2011 23:35:00 432.32 10/11/2011 23:36:18 432.22 10/11/2011 23:37:18 432.72 10/11/2011 23:39:19 432.23 10/11/2011 23:40:02 432.23 10/11/2011 23:45:00 432.23 10/11/2011 23:45:20 429.75 10/11/2011 23:46:20 429.65 10/11/2011 23:50:00 429.65 10/11/2011 23:51:22 429.75 10/11/2011 23:55:01 429.75 10/11/2011 23:56:23 429.55 10/12/2011 0:00:07 429.55 10/12/2011 0:01:24 429.95 10/12/2011 0:05:00 429.95 10/12/2011 0:06:25 429.85 10/12/2011 0:10:00 429.85 10/12/2011 0:11:26 428.85 10/12/2011 0:15:00 428.85 10/12/2011 0:20:03 428.85 10/12/2011 0:21:29 428.75 10/12/2011 0:25:01 428.75 10/12/2011 0:30:01 428.75 10/12/2011 0:31:31 428.75 library(zoo) library(chron) fmt - %m/%d/%Y %H:%M:%S toChron - function(d, t) as.chron(paste(d, t), format = fmt) z - read.zoo(text = Lines, index = 1:2, FUN = toChron) # 1 minute spline fit m1 - times(00:01:00) g - seq(trunc(start(z), m1), end(z), by = m1) na.spline(z, xout = g) # this did what I want but what is the vector name? # 15 minute aggregates m15 - times(00:15:00) ag15 - aggregate(z, trunc(time(z), m15), mean) the results of the na.spline(z, xout = g) function below (10/11/11 23:30:00) (10/11/11 23:31:00) (10/11/11 23:32:00) (10/11/11 23:33:00) (10/11/11 23:34:00) (10/11/11 23:35:00) 432.2189 432.2950 432.3869 432.4584 432.4545 432.3200 (10/11/11 23:36:00) (10/11/11 23:37:00) (10/11/11 23:38:00) (10/11/11 23:39:00) (10/11/11 23:40:00) (10/11/11 23:41:00) 432.1639 432.5834 432.7443 432.3624 432.2095 433.8208 (10/11/11 23:42:00) (10/11/11 23:43:00) (10/11/11 23:44:00) (10/11/11 23:45:00) (10/11/11 23:46:00) (10/11/11 23:47:00) 436.3606 438.0969 437.2974 432.2300 428.9265 430.6503 (10/11/11 23:48:00) (10/11/11 23:49:00) (10/11/11 23:50:00) (10/11/11 23:51:00) (10/11/11 23:52:00) (10/11/11 23:53:00) 430.8493 430.2351 429.6500 429.6715 429.8502 429.9054 (10/11/11 23:54:00) (10/11/11 23:55:00) (10/11/11 23:56:00) (10/11/11 23:57:00) (10/11/11 23:58:00) (10/11/11 23:59:00) 429.8623 429.7522 429.6074 429.4636 429.3664 429.3678 (10/12/11 00:00:00) (10/12/11 00:01:00) (10/12/11 00:02:00) (10/12/11 00:03:00) (10/12/11 00:04:00) (10/12/11 00:05:00) 429.5200 429.8310 430.0703 430.1312 430.0707 429.9500 (10/12/11 00:06:00) (10/12/11 00:07:00) (10/12/11 00:08:00) (10/12/11 00:09:00) (10/12/11 00:10:00) (10/12/11 00:11:00) 429.8495 429.9134 430.0879 430.1446 429.8500 429.1407 (10/12/11 00:12:00) (10/12/11 00:13:00) (10/12/11 00:14:00) (10/12/11 00:15:00) (10/12/11 00:16:00) (10/12/11 00:17:00) 428.6042 428.4933 428.6367 428.8500 428.9834 429.0264 (10/12/11 00:18:00) (10/12/11 00:19:00) (10/12/11 00:20:00) (10/12/11 00:21:00) (10/12/11 00:22:00) (10/12/11 00:23:00) 429.0031 428.9376 428.8542 428.7773 428.7315 428.7217 (10/12/11 00:24:00) (10/12/11 00:25:00) (10/12/11 00:26:00) (10/12/11 00:27:00) (10/12/11 00:28:00) (10/12/11 00:29:00) 428.7330 428.7498 428.7594 428.7615 428.7588 428.7541 (10/12/11 00:30:00) (10/12/11 00:31:00) 428.7500 428.7491 the results from when I enter ag15 in the R command line - which looks correct (10/11/11 23:30:00) (10/11/11 23:45:00) (10/12/11 00:00:00) (10/12/11 00:15:00) (10/12/11 00:30:00) 432.3229 430.0471 429.6667 428.8000 428.7500 -- View this message in context:
[R] R's list data structure
Given dayOfWeekName-c(Mon,Tue,Wed,Thu,Fri,Sat,Sun); dayOfWeekOrdinal-c(1,2,3,4,5,6,0); dayOfWeekWorkDay-c(TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE); weekProfile-list(dow=dayOfWeekName,dowI=dayOfWeekOrdinal,dowW=dayOfWeekWorkDay) 1. How can I conditionally get dow, dowI, and dowW from weekProfile? If another 'arrangement' of this list object will make this task easier, please advise. 2. What is the point of the list object? I know that when mixed data types need to be held together, then the only option is to use the list data structure. If I were to hold recurring (Name, Salary, DateOfBirth) (i.e. character, integer and date values) in a list object, what would be the 'optimal' arrangement? Would that be as the components of weekProfile above? Or will this be better. Either: personalDetail- list(rbind(c(Name,Salary,DateOfBirth),c(Name,Salary,DateOfBirth))); Thanks for sharing your insight. [[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] R's list data structure
HI Ajay, On Fri, Feb 17, 2012 at 3:20 PM, Ajay Askoolum aa2e...@yahoo.co.uk wrote: Given dayOfWeekName-c(Mon,Tue,Wed,Thu,Fri,Sat,Sun); dayOfWeekOrdinal-c(1,2,3,4,5,6,0); dayOfWeekWorkDay-c(TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE); weekProfile-list(dow=dayOfWeekName,dowI=dayOfWeekOrdinal,dowW=dayOfWeekWorkDay) 1. How can I conditionally get dow, dowI, and dowW from weekProfile? If another 'arrangement' of this list object will make this task easier, please advise. 2. What is the point of the list object? I know that when mixed data types need to be held together, then the only option is to use the list data structure. In your particular case, where all list components are the same length and are associated with each other in order, a special type of list called a data frame is easier to work with. weekProfile- data.frame(dow=dayOfWeekName,dowI=dayOfWeekOrdinal,dowW=dayOfWeekWorkDay) weekProfile dow dowI dowW 1 Mon1 TRUE 2 Tue2 TRUE 3 Wed3 TRUE 4 Thu4 TRUE 5 Fri5 TRUE 6 Sat6 FALSE 7 Sun0 FALSE I'm not sure what kind of conditional you want, but this can easily be done with subset() or [ weekProfile[weekProfile$dowW ,] dow dowI dowW 1 Mon1 TRUE 2 Tue2 TRUE 3 Wed3 TRUE 4 Thu4 TRUE 5 Fri5 TRUE A regular list is excellent for holding diverse kinds of data, for example 10 lm() objects, or a series of data frames. In a list, the third element of component 1 may not have anything whatsoever to do with the third element of component 2. In a data frame, rows are related. If I were to hold recurring (Name, Salary, DateOfBirth) (i.e. character, integer and date values) in a list object, what would be the 'optimal' arrangement? Data frame. Would that be as the components of weekProfile above? Or will this be better. Either: personalDetail- list(rbind(c(Name,Salary,DateOfBirth),c(Name,Salary,DateOfBirth))); -- 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.
Re: [R] Dataframe subset - why doesn't this work?
Thank you Jorge Michael. I was being stupid - its the only explanation! The line I had been executing was mtcars[rownames==Valiant] # missing rownames argument but the line I quoted in my post was mtcars[rownames(mtcars) != Valiant,] # How could I write the correct line in the mailing list and not where it matters i.e in R? Thank you. [[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] R's list data structure
Hi Sarah, Thanks you for the clarifications; I had worked round the problem by switching to a data.frame. However, I am still unclear about 'list': as it exists, it must have a purpose. When is the use of the list data structure appropriate? [[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] R's list data structure
On Fri, Feb 17, 2012 at 3:37 PM, Ajay Askoolum aa2e...@yahoo.co.uk wrote: Hi Sarah, Thanks you for the clarifications; I had worked round the problem by switching to a data.frame. However, I am still unclear about 'list': as it exists, it must have a purpose. When is the use of the list data structure appropriate? I gave one example: storing lm() objects. Here's another: I'm doing a lot of spatial processing, and I read a single multispectral image into a list. Each list component is a SpatialGridDataFrame. That way each band from a single image is part of the same R object, and I can use lapply() to perform an operation on each band in turn. Using lists for things is a very Rish way of working, but it may take a while to get the hang of it. -- 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.
Re: [R] covariance
Thank, thats what I need, using the built-in help system and R's capability to allow you to view source code for functions, but how??? Date: Fri, 17 Feb 2012 14:55:10 -0500 Subject: Re: [R] covariance From: sarah.gos...@gmail.com To: nasser-d2...@hotmail.com CC: r-help@r-project.org This sounds remarkably like homework. You can address your own issue using the built-in help system and R's capability to allow you to view source code for functions, but we can't help you do your assignments. Sarah On Fri, Feb 17, 2012 at 2:36 PM, Ali2006 nasser-d2...@hotmail.com wrote: can any one please tell me how can I Compute the covariance matrix of (Y) which is 5 variables .. without using a built-in function?? 2) how (cov) works ( I need to get the details for this function ??? -- Sarah Goslee http://www.functionaldiversity.org [[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] covariance
could you help with example ?? -- View this message in context: http://r.789695.n4.nabble.com/covariance-tp4398242p4398470.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] covariance
On Fri, Feb 17, 2012 at 11:06:23PM +0300, Naser Albalwi wrote: Thank, thats what I need, using the built-in help system and R's capability to allow you to view source code for functions, but how??? Hi. First, type cov without quotation marks to R's prompt. The printed code calls .Internal(cov(...)), which means that the main part is done in C code. Then, it is probably the best to download R sources and unpack. The code for cov() is in the file R/src/main/cov.c. The call goes first to function do_cov(). Then you have to search a bit. The main part is computed in one of the functions cov_pairwise1(), cov_pairwise2(), cov_complete1(), or cov_complete2(). Probably, other members of the list may correct me, if this is not correct. Basic formulas for the covariance are at Wikipedia http://en.wikipedia.org/wiki/Covariance Hope this helps. Petr Savicky. __ 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] QQ plot
On 18/02/12 00:15, nandan amar wrote: Thanks a lot Turner. Latter I also tried following : oo-quantile(original, probs = seq(0, 1, 0.01), type = 8) pp-quantile(predicted, probs = seq(0, 1, 0.01), type = 8) plot(oo,pp) But plot for above and following (as you suggested) are not same. What may be the error ? The error is that you didn't look at the code of qqplot() to see what it's actually doing. (Type:qqplot without the quote marks.) It's not doing what you did, so naturally the results are different. I have not the time nor the inclination to think through the implications of what you did and what qqplot() does in respect of the information content of the two approaches. I suspect that they will usually, if not always, give *similar* results. cheers, Rolf Turner __ 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 for 64-bit R with 32-bit Access
This was my experience connecting remotely to an Oracle database with R 64 bit on Windows 7 64-bit. I already had a configuration for 32-bit R and 32-bit Oracle using RODBC that worked, but I wanted to only use R-64. Here was what I did that works: This was assuming an install to the root c:\ and windows in c:\windows Download and install (I did full administrator install): Oracle Client (x64) 11.2 ... http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-win64soft-094461.html (I called Orahome2) Open Oracle Net Manager in new installation (OraHome2) Go to Service Naming, should be empty, go to Edit, and Create Name connection name something different from the 32-bit version host name : the domain name or IP address Service name must still be the same as the 32-bit as before Keep default port 1521 Next go to C:\windows\system32\odbc32.exe (Oddly this is the 64-bit version) Run this and set up a new system DSN connection Call this whatever, but TNS Service ID must be the same as your connection named above Hit Test connection, should work. When running in R-64 bit RODBC package: I had to use the optional odbcConnect(“databasename”,uid=””,pass=””,believeNRows=FALSE) This worked for me! Cheers, Dana -- View this message in context: http://r.789695.n4.nabble.com/RODBC-for-64-bit-R-with-32-bit-Access-tp3093030p4398497.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] error with read.zoo, Error in xy.coords(x, y) : (list) object cannot be coerced to type 'double'
I'm now trying to read.zoo in a rather long txt file with two columns: date/time and value in kW e.g. 432.2189 The read.zoo function finally ran without errors but not sure it is correct. I took the header off, and put in commas and added a at the beginning and at the end. z=read.zoo(Kevin-0-comma-ITPower.txt,%m/%d/%Y %H:%M:%S,header=FALSE,sep=,,index.column=1) library(zoo) library(chron) # 1 minute spline fit m1 - times(00:01:00) g - seq(trunc(start(z), m1), end(z), by = m1) na.spline(z, xout = g) Error in xy.coords(x, y) : (list) object cannot be coerced to type 'double' What is causing the double error. Do I need to specify the types something like colClasses = c( character, double) Here is a paste of the beginning of the txt file (6510 lines) 10/11/2011 23:00:06,432.12 10/11/2011 23:02:09,432.42 10/11/2011 23:05:00,432.42 10/11/2011 23:07:10,432.12 10/11/2011 23:10:01,432.12 10/11/2011 23:12:12,432.22 10/11/2011 23:15:00,432.22 ... ... ... 10/31/2011 22:55:08,362.57 -- View this message in context: http://r.789695.n4.nabble.com/error-with-read-zoo-Error-in-xy-coords-x-y-list-object-cannot-be-coerced-to-type-double-tp4398709p4398709.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] Asking About packages rimage
Thanks a lot -- View this message in context: http://r.789695.n4.nabble.com/Asking-About-packages-rimage-tp4395719p4398726.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] Neighbour List to Matrix
I think is good to know that list contain more than 60 rows with around 14000 nodes (participants). ?read.table may be unreliable for large matrices and with 14/600 you'll end up with many NA's. You might do better with nbrs- scan('nbrs.txt',skip=1,what=list('integer','integer',double(0))) names(nbrs) - c('c1','c2','c3') xtabs(c3~c1+c2,nbrs,sparse=T) # returns 4 x 9 sparse Matrix of class dgCMatrix 1 2 3 4 5 6 7 8 9 1 . 0.065 0.044 . . . . . . 3 0.071 . . 0.016 0.011 . . . . 4 . . 0.004 . . . 0.004 . 0.004 5 . . . 0.010 . 0.011 . 0.009 0.004 Cheers __ 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] editing import data, strings
Is this what you want to do: this will remove the commas and convert to numeric x - read.csv(C:\\jph\\indicatorgapminderpopulation.csv + , as.is = TRUE + , check.names = FALSE + ) # convert to numeric column 2+ for (i in 2:ncol(x)){ + x[, i] - as.numeric(gsub(,, , x[, i])) + } str(x) 'data.frame': 259 obs. of 233 variables: $ Total population: chr Abkhazia Afghanistan Akrotiri and Dhekelia Albania ... $ 1700: num NA NA NA 30 175 ... $ 1730: num NA NA NA NA NA NA NA NA NA NA ... $ 1750: num NA NA NA NA NA NA NA NA NA NA ... $ 1785: num NA NA NA NA NA NA NA NA NA NA ... $ 1786: num NA NA NA NA NA NA NA NA NA NA ... $ 1787: num NA NA NA NA NA NA NA NA NA NA ... $ 1788: num NA NA NA NA NA NA NA NA NA NA ... $ 1789: num NA NA NA NA NA NA NA NA NA NA ... $ 1790: num NA NA NA NA NA NA NA NA NA NA ... $ 1791: num NA NA NA NA NA NA NA NA NA NA ... $ 1792: num NA NA NA NA NA NA NA NA NA NA ... $ 1793: num NA NA NA NA NA NA NA NA NA NA ... $ 1794: num NA NA NA NA NA NA NA NA NA NA ... $ 1795: num NA NA NA NA NA NA NA NA NA NA ... $ 1796: num NA NA NA NA NA NA NA NA NA NA ... $ 1797: num NA NA NA NA NA NA NA NA NA NA ... $ 1798: num NA NA NA NA NA NA NA NA NA NA ... $ 1799: num NA NA NA NA NA NA NA NA NA NA ... $ 1800: num NA 328 3710 410445 2503218 ... $ 1801: num NA NA NA NA NA NA NA NA NA NA ... On Fri, Feb 17, 2012 at 1:43 PM, gaja gajahor...@hotmail.com wrote: Thanx for posting. :) I'm posting a link to excel file, same as I want import to table. Its dl link, don't be mad, hehe http://spreadsheets.google.com/pub?key=phAwcNAVuyj0XOoBL_n5tAQoutput=csv Thanx,G. ps: @Michael Weylandt; Thanx for your code,... I tried to used it, but unsucsesfully. I really don't know what the x stands for. I hope I will be able to solve this problem. Gaja -- View this message in context: http://r.789695.n4.nabble.com/editing-import-data-strings-tp4397899p4398120.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ 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's list data structure
FWIW: Lists are a fundamental, universal, recursive data structure. All other data structures (i.e. r.e. sets) can be represented as lists. Indeed, one of the earliest high level (non-machine instructions) computer languages, McCarthy's LISP = List Processing, is based on lists. R was designed to be LISP-like (= a functional programming language) in some fundamentals ways. So it is no surprise that lists are widely used within R. Cheers, Bert On Fri, Feb 17, 2012 at 12:37 PM, Ajay Askoolum aa2e...@yahoo.co.uk wrote: Hi Sarah, Thanks you for the clarifications; I had worked round the problem by switching to a data.frame. However, I am still unclear about 'list': as it exists, it must have a purpose. When is the use of the list data structure appropriate? [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ 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] editing import data, strings
Try this: setClass(myClass) setAs(character, myClass, function(from)as.numeric(gsub(,, , from))) d - read.table(clipboard, sep = ,, check.names = FALSE, quote = '', header = TRUE, fill = TRUE, colClasses = c('character', rep('myClass', 232))) On Fri, Feb 17, 2012 at 3:24 PM, gaja gajahor...@hotmail.com wrote: Regards. I'm a beginner in programing, so I have a basic question for you. If someone could help me please.. I want to create a function, which will be able to export files from excel. I tried with a - read.csv(file, sep =,, as.is = TRUE, row.names = 1, header = TRUE), .. but instead of numbers, it gives me strings for example: 299,311. I can handle this string for example: b - 299,311 as.numeric(gsub(,, , b)) 299311 Now, I´m interested how to inport it from that file,. I tried with a - read.csv(file, sep =,, as.is = TRUE, row.names = 1, header = TRUE) a - gsub(,, , a) a - as.numeric(a) But it doesn't work. I used search engine on forum, but didn't find any function that I could help with. I would be very gratefull if someone could help me. Gaja -- View this message in context: http://r.789695.n4.nabble.com/editing-import-data-strings-tp4397899p4397899.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. -- 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] still need read.zoo command help
The problem now is it looks like my read.zoo isn't working. Sorry for sort of double posting. Someone please assist if you have time with my read.zoo command line. my data is as just below this line, a time stamp and a real number with a comma sep. 10/11/2011 23:00:06,432.12 z=read.zoo(Kevin-0-comma-ITPower.txt, format=%m/%d/%Y %H:%M:%S, tz=, FUN=NULL, regular=FALSE, header=FALSE, sep=,, index.column=1) library(zoo) library(chron) #this code from Gabor Grothendieck - thanks # 15 minute aggregate averages m15 - times(00:15:00) ag15 - aggregate(z, trunc(time(z), m15), mean) write.zoo(ag15,file=ITPower15minv2.txt,index.name=Time,row.names=FALSE,col.names=FALSE) # this may also have a problem. #2011-10-11 2011-10-11 is all that is written in the file #data in the Kevin-0-comma-ITPower.txt starts like this.. 10/11/2011 23:00:06,432.12 10/11/2011 23:02:09,432.42 10/11/2011 23:05:00,432.42 10/11/2011 23:07:10,432.12 10/11/2011 23:10:01,432.12 10/11/2011 23:12:12,432.22 10/11/2011 23:15:00,432.22 10/11/2011 23:20:00,432.22 10/11/2011 23:22:14,432.32 10/11/2011 23:25:01,432.32 10/11/2011 23:26:15,432.22 10/11/2011 23:30:01,432.22 10/11/2011 23:31:17,432.32 10/11/2011 23:35:00,432.32 10/11/2011 23:36:18,432.22 10/11/2011 23:37:18,432.72 10/11/2011 23:39:19,432.23 -- View this message in context: http://r.789695.n4.nabble.com/still-need-read-zoo-command-help-tp4398897p4398897.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] still need read.zoo command help
Henry, You're reading a CSV with read.zoo. This is not likely to work. The way I'd do this is: data - read.csv('/tmp/Kevin-0-comma-ITPower.txt', header=FALSE) z - zoo(data[,2], order.by=as.POSIXct(data[,1], format='%d/%m/%y %H:%M:%S') # or whatever your format actually is... -- H Sent from my mobile device Envoyait de mon portable __ 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] assigning NULL to a list element
Hi everyone, For reasons beyond the scope of this message, I'd like to append a NULL element to the end of a list. tmp0 - list(a=1, b=NULL, c=3) append(tmp0, c(d=4)) ## works as expected append(tmp0, c(d=NULL)) ## list with a/b/c only Given that I could use tmp0$a - NULL to remove 'a', I seem to understand why appending NULL returns me the original list... But how should I proceed to actually have d=NULL (just like I have 'b' in tmp0 above)? Thank you very much, benilton __ 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] assigning NULL to a list element
On Feb 17, 2012, at 8:51 PM, Benilton Carvalho wrote: tmp0 - list(a=1, b=NULL, c=3) length(tmp0) - 4 tmp0 $a [1] 1 $b NULL $c [1] 3 [[4]] NULL David Winsemius, MD West Hartford, CT __ 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] assigning NULL to a list element
Thank you very much, 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] assigning NULL to a list element
Hi Benilton: David's solution is short and sweet but below also works. I searched and searched and finally found it in the R-inferno by Patrick Burns. I never looked at the R-inferno carefully before. After glancing at it, I'm printing it out and binding it tomorrow. It's the got ya book for R. tmp0 - list(a=1, b=NULL, c=3) c(tmp0,list(d=NULL)) On Fri, Feb 17, 2012 at 9:17 PM, David Winsemius dwinsem...@comcast.netwrote: On Feb 17, 2012, at 8:51 PM, Benilton Carvalho wrote: tmp0 - list(a=1, b=NULL, c=3) length(tmp0) - 4 tmp0 $a [1] 1 $b NULL $c [1] 3 [[4]] NULL David Winsemius, MD West Hartford, CT __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] editing import data, strings
It looks like you've gotten answers elsewhere, but for completeness, I'll explain my shot in the dark: The construction function (x) sin(x^2) to pick one example, is what's called an anonymous (or lambda) function. In R, they are often used in conjunction with the *apply() family to describe a set of operations to be done column/rowwise on your data. For example, there are the same: apply(d, 2, sin) apply(d, 2, function(x) sin(x)) apply(d, 2, function(y) sin(y)) apply(d, 2, function(d) sin(d)) As you can see, the x is simply a place holder variable, not really tied to anything. Hope this helps, Michael On Feb 17, 2012, at 1:43 PM, gaja gajahor...@hotmail.com wrote: Thanx for posting. :) I'm posting a link to excel file, same as I want import to table. Its dl link, don't be mad, hehe http://spreadsheets.google.com/pub?key=phAwcNAVuyj0XOoBL_n5tAQoutput=csv Thanx,G. ps: @Michael Weylandt; Thanx for your code,... I tried to used it, but unsucsesfully. I really don't know what the x stands for. I hope I will be able to solve this problem. Gaja -- View this message in context: http://r.789695.n4.nabble.com/editing-import-data-strings-tp4397899p4398120.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.
Re: [R] lmer - error message
Hi Sean, Thanks for the data. Your first problem is that Age is a factor with 14 levels. Second, Year is a factor with 16 levels. Now consider what interactions of these will be---factors with a huge number of levels, exceeding what is reasonable to fit to your size of data. I included inline code below. First I convert these variables to numeric. I also do some plots. While I get a model to run, the estimated variance of the random intercept is 0, which is a bit troublesome. I looked at the data, but I do not have a particularly good reason, other than presumably there is very little variability by fish after with age and lake in the model. Anyway, I go on to try a log transformation of Age because of its relationship with Increment. That seems to work pretty well, but the residuals are clearly heteroscedastic, so I also show how you can use the sandwich package to (at least partially) address this. Cheers, Josh require(lme4) ## shows that there are 224 levels in the Age by Year interaction!! with(odata1, interaction(Age, Year)) ## create numeric variables instead odata1 - within(odata1, { numAge - as.numeric(levels(Age))[Age] numYear - as.numeric(levels(Year))[Year] }) ## look at a density plot of Increment plot(density(odata1$Increment)) rug(odata1$Increment) ## look at Increment versus Age (numeric) ## looks like a straight line is likely a poor fit xyplot(Increment ~ numAge, data = odata1) ## compare by lake (looks pretty similar) xyplot(Increment ~ numAge | lake, data = odata1) ## also note that it looks like there is more variability when age is log than hight ## we'll keep that in mind for later ## simple model m1 - lmer(Increment ~ 0 + numAge*lake + (1 | FishID), data = odata1) ## check residuals against normal qqnorm(resid(m1)) ## residuals against age ## this looks pretty bad plot(odata1$numAge, resid(m1)) ## what about the random effects? plot(ranef(m1)) ## checking the model summary ## we see that the variance for the random intercepts is 0 ## this is also rather concerning summary(m1) ## lets look at some descriptives descriptives - with(odata1, do.call(rbind, tapply(Increment, FishID, function(x) { c(M = mean(x, na.rm = TRUE), V = var(x, na.rm = TRUE), N = length(x)) }))) descriptives - descriptives[order(descriptives[, M]), ] descriptives # print ## looks like there are quite a few fish with only one observations ## also, those with only one tend to have a higher mean increment ## given the shape of the relationship, we might try a log transformation on Age ## also given that the random intercepts have 0 variance, we can drop it malt - lm(Increment ~ 1 + log(numAge)*lake, data = odata1) qqnorm(resid(malt)) ## looks decent enough ## not too bad, but clearly not homoscedastic residuals plot(odata1$numAge, resid(malt)) ## the residuals appear heteroscedastic, so we could ## use a sandwhich estimator of the covariance matrix ## the general form is: inv(X'X) X' W X inv(X'X) ## the correction comes in terms of the weight matrix, W which ## can be defined in various ways ## load two required packages require(lmtest) require(sandwich) ## the default coef(summary(malt)) ## using sandwhich estimator ## (okay, the results come out pretty similar, not parameter estimates will be unchaged ## only SEs change) coeftest(malt, vcov. = vcovHC(malt, type = HC, sandwich = TRUE)) On Thu, Feb 16, 2012 at 11:44 PM, Sean Godwin sean.god...@gmail.com wrote: Hi Josh, Thank you so much for your response. The point of the process was actually to find out whether there are different age effects for each lake, so an interaction term between age and lake is a necessary one. Taking out the other random effects to make the model simpler would work perfectly to make this easier to tackle though, and I can add the other terms on later as you say! So: m1 - lmer(Increment ~ 0 + Age + Age*lake + (1|FishID),lakedata) But apparently I don't understand the Age*lake syntax... all I'm trying to do with this is to have an interaction term between age and lake, but since neither are random effects, I can't just write (1|Age:lake) as I could with (1|Age:Year), right? It is the Age*lake term that is causing the error... when I take it out, the model runs fine. There are 117 fish observations, so 117 unique values of fishID. The number of observations per fish changes depending on how old the fish is ( a2 year old fish = 2 observations), with a maximum fish age of 13 years (so max 13 observations per fish and 13 years total in the dataset). I've attached my data (Josh_fulldata.csv) and the script used to rearrange it into a usable format (Josh_model.R). For some reason, I wasn't able to export the resulting dataframe without causing errors when re-inputting it, so hopefully this works for you. Hopefully the inclusion of the full dataset answers your other questions. Interestingly, when I used a 50 fish subset, the error message didn't occur (I've attached
Re: [R] sequencing environments
Thanks Gabor/Duncan, I might give that proto package a try. The R.oo package is more intuitive for someone coming from a traditional OO background, but compared to proto, it looks like it requires a lot more typing to create the same amount of functionality. I've used R.oo for a number of months now and it works great. The other option is to just use get() and assign(), like I suggested in my original post, which seems to be the simplest, but more typing than proto. Thanks for the info! Have a good weekend... ben On Wed, Feb 15, 2012 at 11:09 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Wed, Feb 15, 2012 at 11:58 PM, Ben quant ccqu...@gmail.com wrote: Thank you Duncan. Interesting. I find it strange that you can't get a list of the environments. But I'll deal with it... Anyway, I'm about to start a new R dev project for my company. I'm thinking about architecture, organization, and gotchas. I went through much of the documentation you sent me. Thanks!. I came up with what I think is the best way to implement environments (which I am using like I would use a class in a traditional OO language) that can be reused in various programs. I'm thinking of creating different scripts like this: #this is saved as script name EnvTest.R myEnvir = new.env() var1 = 2 + 2 assign(myx,var1,envir=myEnvir) Then I will write programs like this that will use the environments and the objects/functions they contain: source(EnvTest.r) prgmVar1 = get(myVar1,pos=myEnvir) ## do stuff with env objects print(prgmVar1) Do you think this is the best way to use environments to avoid naming conflicts, take advantage of separation of data, organize scripting logically, etc. (the benefits of traditional OO classes)? Eventually, I'll use this on a Linux machine in the cloud using.: https://github.com/armstrtw/rzmq https://github.com/armstrtw/AWS.tools https://github.com/armstrtw/deathstar http://code.google.com/p/segue/ Reference classes, the oo.R package and the proto package provide OO implementations based on environments. Being particular familiar with the proto package (http://r-proto.googlecode.com), I will discuss it. The graph.proto function in that package will draw a graphViz graph of your proto objects (environments). Using p and x in place of myEnv and myx your example is as follows. library(proto) p - proto(x = 2+2) p$x # 4 # add a method, incr p$incr - function(.) .$x - .$x + 1 p$incr() # increment x p$x # 5 # create a child # it overrides x; inherits incr from p ch - p$proto(x = 100) ch$incr() ch$x # 101 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] is there a command to withdraw already performed command in R?
Hi all, Is there any command or function to withdraw a command performed already in R? For instance, after drawing a line in existing plot, can I remove the line in the plot? I know I can use a way of overlapping on the former line so that it looks like a removing the line, but I'm wondering there is a command to retract the already performed command. Thanks. YN [[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] still need read.zoo command help
On Fri, Feb 17, 2012 at 7:54 PM, Henry hcco...@lbl.gov wrote: The problem now is it looks like my read.zoo isn't working. Sorry for sort of double posting. Someone please assist if you have time with my read.zoo command line. my data is as just below this line, a time stamp and a real number with a comma sep. 10/11/2011 23:00:06,432.12 z=read.zoo(Kevin-0-comma-ITPower.txt, format=%m/%d/%Y %H:%M:%S, tz=, FUN=NULL, regular=FALSE, header=FALSE, sep=,, index.column=1) library(zoo) library(chron) The read.zoo statement should come AFTER the library statements, not before, and the read.zoo should be specified like this where fmt was also defined in my response to your prior post: Lines - 10/11/2011 23:00:06,432.12 10/11/2011 23:02:09,432.42 10/11/2011 23:05:00,432.42 library(zoo) library(chron) fmt - %m/%d/%Y %H:%M:%S z - read.zoo(text = Lines, FUN = as.chron, format = fmt, sep = ,) Also regarding the comment by the other poster, read.zoo reads csv data fine. Be sure you have read and assimilated ?read.zoo and also vignette(zoo-read) which is a document entirely devoted to read.zoo examples. -- 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] convert zoo object to standard R object so I can plot and output to csv file
On Fri, Feb 17, 2012 at 2:56 PM, Henry hcco...@lbl.gov wrote: Another newbie question I got the 1 minute spine interpolation and 15 mean aggregation working with many thanks to Gabor Grothendieck using Zoo functions. I got a tip from Hasan Diwan to look at xts but it seemed I would make better progress using code from Gabor. Now I'm having trouble plotting this zoo object. I'm thinking I want a function to split the zoo object back to a regular R object with x time values and y values so I can plot using plot functions I'm familiar with. If z is a zoo object then plot(z) or library(lattice) xyplot(z) will plot it. See ?plot.zoo and ?xyplot.zoo -- 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.