[R] two-level poisson, again
Hi, I compare results of a simple two-level poisson estimated using lmer and those estimated using MLwiN and Stata (v.9). In R, I trype: --- m2 <- lmer(.D ~ offset(log(.Y)) + (1|pcid2) + educy + agri, male, poisson) --- In Stata, I type: --- xtpois _D educy agri, e(_Y) i(pcid2) --- Results using R look like: --- ... Random effects: GroupsNameVarianceStd.Dev. pcid2 (Intercept) 5e-10 2.2361e-05 # of obs: 25360, groups: pcid2, 174 Estimated scale (compare to 1) 7.190793 Fixed effects: Estimate Std. Error z value Pr(>|z|) (Intercept) -3.28548086 0.00408771 -803.75 < 2.2e-16 *** educy0.00507475 0.00039616 12.81 < 2.2e-16 *** agri 0.01346887 0.003348374.02 5.758e-05 *** ... -- Results using Stata look like: -- _D | Coef. Std. Err. zP>|z| [95% Conf. Interval] -+ educy | .0120431 .000444127.12 0.000 .0111725.0129136 agri | .0293177 .0035586 8.24 0.000 .022343.0362924 _cons | -3.325073 .0076275 -435.93 0.000-3.340023 -3.310123 _Y | (exposure) -+ /lnalpha | -4.982977 .1156474 -5.209641 -4.756312 -+ alpha | .0068536 .0007926 .0054636.0085973 -- As you can see, the discrepency is significant! And results using MLwiN agree with Stata. Any help will be greately appreciated! Shige __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] RODBC and sqlColumns
I have a Postgres database that I am connecting to with the Postgres ODBC driver on Windows XP in R 2.1.0. In the database is a database with two schemas (public and X). With RODBC (1.1-4) , I can connect to the database and get the tables with sqlTables(db). I can query tables in the schema with sqlQuery("SELECT * FROM X.test"). However, I can't get the columns in table X.test with sqlColumns(db,"X.test") //it returns Error in sqlColumns(db, "X.test") : 'X.test': table not found on channel If I do sqlColumns(db, "test") it returns [1] TABLE_QUALIFIER TABLE_OWNER TABLE_NAMECOLUMN_NAME DATA_TYPE [6] TYPE_NAME PRECISION LENGTHSCALE RADIX [11] NULLABLE REMARKS COLUMN_DEFSQL_DATA_TYPE SQL_DATETIME_SUB [16] CHAR_OCTET_LENGTH ORDINAL_POSITION IS_NULLABLE DISPLAY_SIZE FIELD_TYPE <0 rows> (or 0-length row.names) But there is no test table defined anywhere else but the X schema. If I do sqlSave(db,aDataFrame,"X.test",T,F), it says test already defined. If I change the aDataFrame to be different than the fields actually in the data, then R starts to create a new table but returns Error in sqlColumns(db, "X.test") : 'X.test': table not found on channel It seems to be having problems with what is returned by the columns.since Error in sqlSave(db, aDataFrame, "X.test", T, F) : [RODBC] ERROR: Could not SQLExecDirectS1000 7 ERROR: relation "test" already exists but if I change the input table to be differentthen R can create the table, but fails to populate it. I checked the db in PgAdmin and the table is created by the sqlSave call. All this stuff works if I don't use a schema "schema.table". So it appears there is something wrong in some place dealing with understanding the columns for tables in schemas. Any ideas? Any help would be much appreciated. Thank you. Ben Stabler Project Manager PTV America, Inc. 1128 NE 2nd St, Suite 204 Corvallis, OR 97330 541-754-6836 x205 541-754-6837 fax www.ptvamerica.com Ben Stabler Project Manager PTV America, Inc. 1128 NE 2nd St, Suite 204 Corvallis, OR 97330 541-754-6836 x205 541-754-6837 fax www.ptvamerica.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Two-level Poisson model with cross classified random effects
Dear All, I have two-level data with individual as level-1, birth cohort and community as level-2. All the level-2 covariates are generated from the level-1 covariates by cross-classifying by cohort and community. >From what I read, an ordinary three-level model with individual nesed within birth cohort nested within community, or individual nested within community nested within birth cohort do not work well, neither do model with individual nested within community by cohort. The right way to go is to estimate a two-level model with two separate random effects: within cohort and within community. The question I want to ask is: how to do this using lmer? I tried the following for a simple unconditioal model: m1 <- lmer(count ~ offset(log(total)) + (1|comm) + (1|cohort), data, poisson) where "count" is the dependent variable, "total" is the exposure variable, "comm" is the community ID, and "cohort" is the birth cohort ID. Will this be suffice? I got really smalle randome intercept (5.e-10 for community and 4.4226e-05 for cohort), which got me a bit nervous. Thanks! Best, Shige __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Stacked Area chart
At 16:03 16/08/05, Mike Saunders wrote: >I wish to do a stacked area chart to show how relative proportions of >species within a stand have changed over time. > >I know this is simple, but can someone point me to the right function (if >it exists). I have not had any luck finding it in the R-help, but maybe I >am searching using the wrong keywords. > >Thanks, >Mike > > >Mike Saunders >Research Assistant >Forest Ecosystem Research Program >Department of Forest Ecosystem Sciences >University of Maine >Orono, ME 04469 >207-581-2763 (O) >207-581-4257 (F) > > [[alternative HTML version deleted]] > >__ >R-help@stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html I recently did some graphs using xyplot in lattice where I had the data ordered by days, the groups argument and possibly by condition. I have slightly reduced the code for general use and re run it The process is to create a matrix of cumulative data (xy) and to make a filled polygon for each of the groups using the previous group value as the lower limit of the polygon. For the first group there has to be a dummy lower limit in these cases of zero ie rep(0,5) in the single panel graph in the rbind sequence Plotting of a group line is referred to as j+1 row due to the fact that there is a dummy line for the lower polygon of the first group The first script is for a single graph where there were the groups (codeno) were 4 species. The days were 1,2,4,6,9 and the y values (comp ) were percentages. All groupings and conditions are numeric for both datasets Any NAs were converted to 0s so as not to give error messages etc. The second script is for a conditioned graph of similar data but is generalised. The maximum y limit can cause problems in setting. In these cases I had a good idea of what they would be. For count data it would be necessary to first do a calculation to find it. # Single panel xyplot(comp ~ days, data = stackln, as.table = T, groups = codeno, subscripts = T, panel= function(x,y,subscripts,groups) { xy <- rbind(rep(0,5), apply(sapply(1:4, function(j) y[groups[subscripts]==j]),1,cumsum)) for(j in 1:4){ grid.polygon(x = c(c(1,2,4,6,9), rev(c(1,2,4,6,9)) ), y = c(xy[(j+1),],rev(xy[(j),]) ), gp = gpar(col = 0, fill = c(1,2,6,8)[j]), default.units = "native") } } ) # Conditioned panel xyplot(comp ~ days|grps3, data = in1, as.table = T, groups = codeno, subscripts = T, panel = function(x,y,subscripts,groups,panel.number) { grp.no <- sort(unique(groups[subscripts]) ) x.vals <- sort(unique(x)) xy <- rbind(rep(0,length(x.vals) ), apply(sapply(1:length(grp.no), function(j) y[groups[subscripts]==grp.no[j]]),1,cumsum)) for (j in 1:length(grp.no)) { grid.polygon(x = c(x.vals, rev(x.vals) ), y = c(xy[(j+1),], rev(xy[(j),]) ), gp = gpar(col = 0, fill = c(6,1,2,5,3,4,7,8)[j]), default.units = "native") } # for (j in 1:length(grp.no)) } # panel ) Regards Duncan Mackay (The other Duncan Mackay) Duncan Mackay Dept of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] permutated p values vs. normal p values
A **guess** ... subject to correction by others. If you had large systematic error in your experiment, nothing will turn out "significant" (which is what you saw). If you permute the data so that the systematic error becomes "random", you'll get a random number of significant p-values, which is what you saw. If the samples came from animals (or people),-- possibly performed over time by differnet people at diffeent labs (sites)-- large systematic error that would overwhelm small sample size is not unusual.Lack of explicit and careful randomization/cage effects in animal experiments/ equipment and calibration issues are some possible sources for such error. OTOH, what I just said might be pure nonsense, so caveat emptor. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Steve Adams > Sent: Tuesday, August 16, 2005 3:14 PM > To: R-help@stat.math.ethz.ch > Subject: [R] permutated p values vs. normal p values > > Hi, I am performing Cox proportional hazards > regression on a microarray dataset with 15000 genes. > The p values generated from the Cox regression (based > on normal distribution of large sample theory) showed > only 2 genes have a p value less than 0.05. However, > when I did a permutation on the dataset to obtained > permutated p values, and it turned out about 750 genes > had a permutated p value less than 0.05 (that just > happens to be equal to the number of significant genes > you would expect by chance alone). With that big > difference in the number of significant genes, which > one should I trusted? and what's reason why such a big > difference exists? My dataset is not large in sample > size (17 samples), might this be the reason? > > > Thanks > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] as.character and a formula
On Tue, 2005-08-16 at 21:44 +0200, Peter Dalgaard wrote: > Gavin Simpson <[EMAIL PROTECTED]> writes: > > > Dear list, > > > > given this formula: > > > > > fmla <- formula(y1 ~ spp1 + spp2 + spp3 + spp5) > > > fmla[[3]] > > spp1 + spp2 + spp3 + spp5 > > > > is this the intended behaviour of as.character: > > > > > as.character(fmla[[3]]) > > [1] "+" "spp1 + spp2 + spp3" "spp5" > > Yes. Thanks Uwe, Brian and Peter for setting me straight. Being unobservant, forgetful and stupid, all in one day, is some going, even for me. All the best, Gav > > ? Where does the extra "+" come from? > > What extra "+" ? There are three of them in fmla[[3]] and three in > as.character(). > > as.character of an object of mode call is obtained by converting it to > a list and deparsing each term (modulo some details regarding > backquotes). This is somewhat peculiar, but quite a bit of legacy code > is depending on it. Things like testing for as.character(e)[1] == "~" > > -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] preprocessing data
> My question is concerning the line > "This is adequate for small files, but for anything more > complicated we > recommend using the facilities of a language like perl to > pre-process the file." An alternative to Perl is to use the big data library of S-PLUS 7 Enterprise, which would allow you to read in the entire fixed-format file and pre-process it using S commands. You could then export the processed data to a file from S-PLUS and import into R. If your university has S-PLUS, S-PLUS 7 Enterprise should be available (all academic institutions were upgraded to S-PLUS 7 Enterprise, which has the big data library). You can read more information about the big data library at: http://www.insightful.com/insightful_doclib/document.asp?id=167 # David Smith -- David M Smith <[EMAIL PROTECTED]> Senior Product Manager, Insightful Corp, Seattle WA Tel: +1 (206) 802 2360 Fax: +1 (206) 283 6310 New S-PLUS 7! Create advanced statistical applications with large data sets. www.insightful.com/splus > -Original Message- > From: Jean Eid [mailto:[EMAIL PROTECTED] > Sent: Tuesday, August 16, 2005 5:39 AM > To: r-help@stat.math.ethz.ch > Subject: [R] preprocessing data > > > Dear all, > > My question is concerning the line > "This is adequate for small files, but for anything more > complicated we > recommend using the facilities of a language like perl to > pre-process > the file." > > in the import/export manual. > > I have a large fixed-width file that I would like to > preprocess in Perl or > awk. The problem is that I do not know where to start. Does > anyone have a > simple example on how to turn a fixed-width file in any of these > facilities into csv or tab delimited file. I guess I am looking for > somewhat a perl for dummies or awk for dummies that does this. any > pointers for website will be greatly appreciated > > Thank you > > > Jean Eid > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] permutated p values vs. normal p values
Hi, I am performing Cox proportional hazards regression on a microarray dataset with 15000 genes. The p values generated from the Cox regression (based on normal distribution of large sample theory) showed only 2 genes have a p value less than 0.05. However, when I did a permutation on the dataset to obtained permutated p values, and it turned out about 750 genes had a permutated p value less than 0.05 (that just happens to be equal to the number of significant genes you would expect by chance alone). With that big difference in the number of significant genes, which one should I trusted? and what's reason why such a big difference exists? My dataset is not large in sample size (17 samples), might this be the reason? Thanks __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] specify seed for Random Number Generator
"Dhiren DSouza" <[EMAIL PROTECTED]> writes: > I need to generate 100 I.I.D samples from an exponential distribution. I > use rexp(100,parameter). Is there anyway to specify a seed to determine the > first input for the uniform random number generator used to generate these > exponentials? Try set.seed() -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to reshape an array avoiding for loops
Wladimir Eremeev <[EMAIL PROTECTED]> writes: > Dear r-help, > > I have an array a1 with dimensions [1:660,1:65,1:25] > I would like the first dimension to be the last one. > That is I want and array [1:65,1:25,1:660] > > The only way to do this, I know, is > > tmp.a<-array(dim=dim(a1)[c(2,3,1)]) > for(i in 1:dim(a1)[1]) tmp.a[,,i]<-a1[i,,] > a1<-tmp.a > rm(tmp.a) > > > Is it possible to avoid 'for' loop here? aperm() is your friend. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to reshape an array avoiding for loops
?aperm -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Wladimir Eremeev > Sent: Tuesday, August 16, 2005 2:12 PM > To: r-help@stat.math.ethz.ch > Subject: [R] how to reshape an array avoiding for loops > > Dear r-help, > > I have an array a1 with dimensions [1:660,1:65,1:25] > I would like the first dimension to be the last one. > That is I want and array [1:65,1:25,1:660] > > The only way to do this, I know, is > > tmp.a<-array(dim=dim(a1)[c(2,3,1)]) > for(i in 1:dim(a1)[1]) tmp.a[,,i]<-a1[i,,] > a1<-tmp.a > rm(tmp.a) > > > Is it possible to avoid 'for' loop here? > > Thank you! > > --- > Best regards, > Wladimirmailto:[EMAIL PROTECTED] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] specify seed for Random Number Generator
I need to generate 100 I.I.D samples from an exponential distribution. I use rexp(100,parameter). Is there anyway to specify a seed to determine the first input for the uniform random number generator used to generate these exponentials? -Dhiren __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] how to reshape an array avoiding for loops
Dear r-help, I have an array a1 with dimensions [1:660,1:65,1:25] I would like the first dimension to be the last one. That is I want and array [1:65,1:25,1:660] The only way to do this, I know, is tmp.a<-array(dim=dim(a1)[c(2,3,1)]) for(i in 1:dim(a1)[1]) tmp.a[,,i]<-a1[i,,] a1<-tmp.a rm(tmp.a) Is it possible to avoid 'for' loop here? Thank you! --- Best regards, Wladimirmailto:[EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Broken tkrplot on Mac OS X
Because of the way Tcl works the C code needs to be linked into a dylib rather than the other thing. I keep meaning to either put in a README.MacOSX or figure out a way to get configure to deal with this but never get around to it. Here is the strategy that works for me (from notes and memory--I may have got a detail wrong): Download, untar, and run R CMD INSTALL cd to the src directory and repeat the final link command with -bundle replaced by -dynamiclib Then move the new trkplot.so by hand to the lib directory of the installed package If you are offended by a .so extension on a dylib you can change the extension and the R code that load it. If you figure out a better way to do this please let me know, Best, luke On Thu, 12 May 2005, stefano iacus wrote: > It seems it doesn't work for me either > > http://159.149.213.137/R/bin/2.1/check/checkSummaryOSX.html > > Will forward to Luke, hopefully he could help > stefano > > On 12/mag/05, at 23:13, Simon Urbanek wrote: > >> Hi Robert, >> >> On May 12, 2005, at 4:48 PM, Robert Gentleman wrote: >> >>> I am getting something a bit weird when I do an install.packages on >>> tkrplot, >>> > library(tkrplot) >>> Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class = >>> "tclObj") : >>> [tcl] dyld: /Users/rgentlem/R/R-devel/bin/exec/R malformed >>> library: /Users/rgentlem/R/R-devel/library/tkrplot/libs/tkrplot.so (not a >>> Mach-O library file, bad filetype value) >>> . >>> Error in library(tkrplot) : .First.lib failed for 'tkrplot' >>> > >>> >>> can either of you confirm - or point me towards what is wrong with my >>> installation - >> >> It's rather a problem with tkrplot than with your installation - it >> compiles tkrplot.so as if it was a library to be loaded into R (via >> dyn.load - more precisely it creates a bundle for R), but then tries to >> load it as dylib using Tcl/Tk. I don't know the exact system how to load >> plug-ins into Tcl/Tk, but I suspect that the tkrplot code needs to be split >> into R part bundle and dylib that is loaded into Tcl/Tk. Chances are that >> the bundle is actually not needed at all, because I don't see any .C/.Call >> in the tkrplot R code. I have to run now, but I can have a closer look >> later this week if it's of interest. >> >> Cheers, >> Simon >> > > -- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: [EMAIL PROTECTED] Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu On Fri, 12 Aug 2005, Marco Blanchette wrote: > Dear all-- > > I have been trying to get the tkrplot package to work in order to use the > bioconductor package genArise. > > I am trying to build it on a Mac running OS 10.4.1 with R 2.1.1. Following a > stanadard install from R here the error I get when I try to load tkrplot > >> library(tkrplot) > Loading required package: tcltk > Loading Tcl/Tk interface ... done > Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class = > "tclObj") : > [tcl] no suitable image found. Did find: > > /Library/Frameworks/R.framework/Versions/2.1.1/Resources/library/tkrplot/li > b > s/tkrplot.so: not a dylib. > Error in library(tkrplot) : .First.lib failed for 'tkrplot' > > Gustavo Corral suggestion was to rebuild the tkrplot.so bundle as a library > by doing: > >> It can be rather tricky to make it work. You have to download it, then >> install it with R CMD INSTALL, then you may need to edit the file Makeconf in >> the RHOME/etc directory (the command R RHOME says the path to RHOME >> directory). >> In this file you must change: >> >> (line 41 in my case) >> SHLIB_CXXLDFLAGS = -bundle -flat_namespace -undefined suppress >> replaced by: >> SHLIB_CXXLDFLAGS = -dynamiclib -flat_namespace -undefined suppress >> >> (line 45 ...) >> SHLIB_LDFLAGS = -bundle -flat_namespace -undefined suppress >> replaced by: >> SHLIB_LDFLAGS = -dynamiclib -flat_namespace -undefined suppress >> >> then move to the src directory in the tkrplot you just download and link >> tkrplot >> with the statement: R CMD SHLIB -o tkrplot.so. Then move tkrplot.so by hand >> to >> >> the libs directory of the tkrplot installation (RHOME/library/tkrplot/libs). > > That what I did. Now I am having a different error when I try to load > tkrplot... > >> library(tkrplot) > Loading required package: tcltk > Loading Tcl/Tk interface ... done > Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class = > "tclObj") : >[tcl] couldn't find procedure Rplot_Init. > Error in library(tkrplot) : .First.lib failed for 'tkrplot' > > Any clue as how to fix tkrplot? > > Why is this package so difficult to install??? > > Anyway, I would appreciate any help/suggestions. > > Many t
[R] vector autoregression
dear All, I have the following problem: I need to calculate an h-step ahead forecast from a var model (estimated with a dse1 method estVARXls), which in turn will be used as an input for another model as conditioning data, so I need it as a simple, numeric matrix. No exogenous input is used. However, the standard forecast method produces a 1-element list that includes a forecast matrix, yet I have no clue as to how to extract the values of interest. Featherforecast and Horizonforecast do not allow prediction only beyond the sample period, quote: "from.periods cannot exceed available output data". any help will be much appreciated, regards, konrad __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Image from bytes streams
"Márcio de Medeiros Ribeiro" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... >My big problem is that my program reads the image before that its >complete by the png() function. For instance, my graphic image has >1000Kb. When R saves it into the hard disk, my Java program reads the >file before the save operation completes (500Kb for example). So, I >got only a part of the file and hence the image... :( > >One solution is read the image and search for a byte which represents >the end of the file, but it depends on the image format... Have you considered in R writing the file to a temporary name (see ?tempfile). When the file is complete, after the dev.off() in R as suggested by Prof Ripley, you could rename the file [using file.name() in R]. Your external program can now access the file without worrying about whether it is complete, since the file appears not to exist until the whole file has been written. efg __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] as.character and a formula
Gavin Simpson <[EMAIL PROTECTED]> writes: > Dear list, > > given this formula: > > > fmla <- formula(y1 ~ spp1 + spp2 + spp3 + spp5) > > fmla[[3]] > spp1 + spp2 + spp3 + spp5 > > is this the intended behaviour of as.character: > > > as.character(fmla[[3]]) > [1] "+" "spp1 + spp2 + spp3" "spp5" Yes. > ? Where does the extra "+" come from? What extra "+" ? There are three of them in fmla[[3]] and three in as.character(). as.character of an object of mode call is obtained by converting it to a list and deparsing each term (modulo some details regarding backquotes). This is somewhat peculiar, but quite a bit of legacy code is depending on it. Things like testing for as.character(e)[1] == "~" -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] data manipulation help
Thanks to Patrick Burns, Dieter Menne and Peter Alspach for your help. Peter Alspach indicated me how to get the first and the last capture of every individual with the following code: capture <- matrix(rbinom(40, 1, 0.3), 4, 10) capture [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,]000001101 1 [2,]101000111 0 [3,]000000101 0 [4,]010110000 0 firstcap<-apply(capture, 1, function(x) min((1:length(x))[x==1])) [1] 6 1 7 2 lastcap<-apply(capture, 1, function(x) max((1:length(x))[x==1])) [1] 10 9 9 5 Roberto Hello everybody, I have a dataframe with 468 individuals (rows) that I captured at least once during 28 visits (columns), iso I can know how many times every individual was captured, 0= not capture, 1=capture. persistence<-apply(mortacap2,1,sum) I also want to know when was the first and the last capture for every individual, if I use: which(mortacap2[1,]==1) X18.10.2004 X26.10.2004 X28.10.2004 X30.10.2004 1 5 6 7 I can estimate manually row by row, but I dont get how to estimate the first and the last capture, to all individuals in the database at the same time. I tried d<-numeric(368) for (i in 1:368) {d[i]<-which(mortacap2[1:368,]==1} but it didnt work. Any help would be appreciated. Thanks in advance!! Roberto Munguia Steyer Departamento Biologia Evolutiva Instituto de Ecologia, A.C. Xalapa, Veracruz. MEXICO Windows XP R 2.10 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Stacked Area chart
Maybe this is useful: stackedPlot <- function(data, time=NULL, col=1:length(data), ...) { if (is.null(time)) time <- 1:length(data[[1]]); plot(0,0 , xlim = range(time) , ylim = c(0,max(rowSums(data))) , t="n" , ... ); for (i in length(data):1) { # Die Summe bis zu aktuellen Spalte prep.data <- rowSums(data[1:i]); # Das Polygon muss seinen ersten und letzten Punkt auf der Nulllinie haben prep.y <- c(0 , prep.data , 0 ) prep.x <- c(time[1] , time , time[length(time)] ) polygon(prep.x, prep.y , col=col[i] , border = NA ); } } dogs <- runif(10)+ 1:10; cats <- 11 - dogs; birds <- 11 - cats; population <- data.frame(dogs,cats,birds); stackedPlot(population); Documentation is bad (as this function is for personal use) and you may want to normalize your data, but it should be useful for different sized data.frames. Best regards, Christian 2005/8/16, Mike Saunders <[EMAIL PROTECTED]>: > I wish to do a stacked area chart to show how relative proportions of species > within a stand have changed over time. > > I know this is simple, but can someone point me to the right function (if it > exists). I have not had any luck finding it in the R-help, but maybe I am > searching using the wrong keywords. > > Thanks, > Mike > > > Mike Saunders > Research Assistant > Forest Ecosystem Research Program > Department of Forest Ecosystem Sciences > University of Maine > Orono, ME 04469 > 207-581-2763 (O) > 207-581-4257 (F) > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] as.character and a formula
I guess the problem is that Gavin is unaware of what [[]] does for a call. It is still a call and so you want to use deparse() and not as.character(): > deparse(fmla[[3]]) [1] "spp1 + spp2 + spp3 + spp5" Watch out for the line length limit on deparse() if you do this in programs. On Tue, 16 Aug 2005, Uwe Ligges wrote: > Gavin Simpson wrote: > >> Dear list, >> >> given this formula: >> >> >>> fmla <- formula(y1 ~ spp1 + spp2 + spp3 + spp5) >>> fmla[[3]] >> >> spp1 + spp2 + spp3 + spp5 >> >> is this the intended behaviour of as.character: >> >> >>> as.character(fmla[[3]]) >> >> [1] "+" "spp1 + spp2 + spp3" "spp5" >> >> ? Where does the extra "+" come from? > > Which *extra* "+"? > > This expression is the same as > > "+"(spp1 + spp2 + spp3, spp5) > > hence "+" with arguments "spp1 + spp2 + spp3" and "spp5" > > Same below. > > Uwe Ligges > > >> >>> as.character(fmla) >> >> [1] "~" "y1" >> [3] "spp1 + spp2 + spp3 + spp5" >> >> Thanks in advance, >> >> Gav > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Mixed Effects Model Power Calculations
Is there an R package available that would facilitate doing a power/sample size analysis for linear mixed effects models? I have seen the Java applets made available by Russell Length which would seem to be able to handle most any lme, but there is little documentation and it's not clear how the models need to be formulated. Rick B. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Compile failure on OSX
On Tue, 16 Aug 2005, Adam Witney wrote: > I am trying to compile R-2.1.1 on MacOSX 10.3.9, but the make is failing (I > am building it without all the aqua stuff): > > ./configure --enable-R-shlib --with-lapac That's incorrect. Please follow the advice in the R-admin.html file which the INSTALL file does ask you to read if you have any problems. It says for your OS: ./configure --with-blas='-framework vecLib' --with-lapack --with-aqua make The last option @option{--with-aqua} is needed only if you want a Console GUI. The first two options are strongly recommended. It also warns you against using --with-lapack if you don't know what you are doing. > make > > Snip . > > gcc -dynamiclib -L/sw/lib -L/usr/local/lib -install_name > /Library/Frameworks/R.framework/Versions/2.1.1/Resources/lib/libRlapack.dyli > b -o libRlapack.dylib dlamc.lo dlapack0.lo dlapack1.lo dlapack2.lo > dlapack3.lo cmplx.lo cmplxblas.lo > -L/sw/lib/gcc/powerpc-apple-darwin7.9.0/3.4 -lg2c -lSystem > ld: Undefined symbols: > _dasum_ [...] -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Dots in models formulae
On Tue, 16 Aug 2005, Gavin Simpson wrote: > I still can't find this documented for a formula (I found > update.formula, but the meaning of "." is different there, slightly, as > you indicate) - but it must be as I didn't imagine seeing it - or maybe > I did... It _is_ in `An Introduction to R', both for lm() and update.formula(). Since this meaning does depend on using terms.formula(), it is on that functions' help page. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Compile failure on OSX
Hi, I am trying to compile R-2.1.1 on MacOSX 10.3.9, but the make is failing (I am building it without all the aqua stuff): ./configure --enable-R-shlib --with-lapac make Snip . gcc -dynamiclib -L/sw/lib -L/usr/local/lib -install_name /Library/Frameworks/R.framework/Versions/2.1.1/Resources/lib/libRlapack.dyli b -o libRlapack.dylib dlamc.lo dlapack0.lo dlapack1.lo dlapack2.lo dlapack3.lo cmplx.lo cmplxblas.lo -L/sw/lib/gcc/powerpc-apple-darwin7.9.0/3.4 -lg2c -lSystem ld: Undefined symbols: _dasum_ _daxpy_ _dcopy_ _ddot_ _dgemm_ _dgemv_ _dger_ _dnrm2_ _drot_ _dscal_ _dswap_ _dsymv_ _dsyrk_ _dtbsv_ _dtpsv_ _dtrmm_ _dtrmv_ _dtrsv_ _idamax_ _xerbla_ _dtpmv_ _dtrsm_ _dgbmv_ _dsbmv_ _dspmv_ _dspr2_ _dspr_ _dsymm_ _dsyr2_ _dsyr2k_ _dsyr_ _dtbmv_ _zgemm_ /usr/bin/libtool: internal link edit command failed make[4]: *** [libRlapack.dylib] Error 1 make[3]: *** [R] Error 2 make[2]: *** [R] Error 1 make[1]: *** [R] Error 1 make: *** [R] Error 1 Thanks for any help Adam -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] as.character and a formula
Gavin Simpson wrote: > Dear list, > > given this formula: > > >>fmla <- formula(y1 ~ spp1 + spp2 + spp3 + spp5) >>fmla[[3]] > > spp1 + spp2 + spp3 + spp5 > > is this the intended behaviour of as.character: > > >>as.character(fmla[[3]]) > > [1] "+" "spp1 + spp2 + spp3" "spp5" > > ? Where does the extra "+" come from? Which *extra* "+"? This expression is the same as "+"(spp1 + spp2 + spp3, spp5) hence "+" with arguments "spp1 + spp2 + spp3" and "spp5" Same below. Uwe Ligges > >>as.character(fmla) > > [1] "~" "y1" > [3] "spp1 + spp2 + spp3 + spp5" > > Thanks in advance, > > Gav __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] recategorizing a vector into discrete states
On Tue, 2005-08-16 at 13:18 -0400, Allan Strand wrote: > Hi All, > > I'm trying to take a numerical vector and produce a new vector of the > same length where each element in the first is placed into a category > given by a 'breaks-like' vector. The values in the result should equal > the lower bounds of each category as defined in the breaks vector. > > I suspect that a vectorized solution is pretty simple, but I can't > seem to figure it out today. Here is an example of my problem: > > Vector 'a' is the original vector. Vector 'b' gives the lower bounds > of the categories. Vector 'c' is the result I am seeking. > > a <- c(0.9, 11, 1.2, 2.4, 4.0, 5.0, 7.3, 8.1, 3.3, 4.5) > b <- c(0, 2, 4, 6, 8) > > c <- c(0, 8, 0, 2, 4, 4, 6, 8, 2, 4) > > Any suggestions would be greatly appreciated. > > cheers, > Allan Strand See ?cut > a <- c(0.9, 11, 1.2, 2.4, 4.0, 5.0, 7.3, 8.1, 3.3, 4.5) > b <- c(0, 2, 4, 6, 8) > cut(a, c(b, Inf), labels = b, right = FALSE) [1] 0 8 0 2 4 4 6 8 2 4 Levels: 0 2 4 6 8 Note that cut() returns a factor. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] preprocessing data
Thank you Gabor, Jean On Tue, 16 Aug 2005, Gabor Grothendieck wrote: > On 8/16/05, Jean Eid <[EMAIL PROTECTED]> wrote: > > Dear all, > > > > My question is concerning the line > > "This is adequate for small files, but for anything more complicated we > > recommend using the facilities of a language like perl to pre-process > > the file." > > > > in the import/export manual. > > > > I have a large fixed-width file that I would like to preprocess in Perl or > > awk. The problem is that I do not know where to start. Does anyone have a > > simple example on how to turn a fixed-width file in any of these > > facilities into csv or tab delimited file. I guess I am looking for > > somewhat a perl for dummies or awk for dummies that does this. any > > pointers for website will be greatly appreciated > > > > > > Try to do it in R first. I have found that I rarely need to go to > an outside language to massage my data. > > # fixed with fields of 10 and 5 > Lines <- readLines("mydata.dat") > data.frame( field1 = as.numeric(substring(1,10,Lines), > field2 = as.numeric(substring(11,15,Lines) ) > > If you do find that you have speed or memory problems that > require that you go outside of R to preprocess your data > then the gawk version of awk has a FIELDWIDTHS variable that > makes handling fixed fields very easy. The gawk program below > assumes two fields of widths 10 and 5, respectively, which > is set in the first line. Then it repeatedly executes the > second line for each input line forcing field splitting by a > dummy manipulation (since field splitting is lazy) and then > printing each line, the default being to print out the > entire line with a space between successive fields: > > BEGIN { FIELDWIDTHS = "10 5" } > { $1 = $1; print } > > In R, do the following assuming the above two lines are in > split.awk: > > read.table(pipe("gawk -f split.awk mydata.dat")) > > or else run gawk outside of R then read in the output file > created: > > gawk -f split.awk mydata.dat > mydata2.dat > > For more information, google for > > FIELDWIDTHS gawk > > for that portion of the manual on FIELDWIDTHS -- it includes > an example and, of course, the whole manual is there too. The > book by Kernighan et al is also good. > > I have used both awk and perl and I think its unlikely you > would need perl given that you have R at your disposal for > the hard parts and awk is easier to learn, better designed > and more focused on this sort of task. > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] as.character and a formula
Dear list, given this formula: > fmla <- formula(y1 ~ spp1 + spp2 + spp3 + spp5) > fmla[[3]] spp1 + spp2 + spp3 + spp5 is this the intended behaviour of as.character: > as.character(fmla[[3]]) [1] "+" "spp1 + spp2 + spp3" "spp5" ? Where does the extra "+" come from? > as.character(fmla) [1] "~" "y1" [3] "spp1 + spp2 + spp3 + spp5" Thanks in advance, Gav -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] recategorizing a vector into discrete states
On Tue, 16 Aug 2005 13:18:23 -0400 Allan Strand wrote: > Hi All, > > I'm trying to take a numerical vector and produce a new vector of > the same length where each element in the first is placed into a > category given by a 'breaks-like' vector. The values in the result > should equal the lower bounds of each category as defined in the > breaks vector. > > I suspect that a vectorized solution is pretty simple, but I can't > seem to figure it out today. Here is an example of my problem: > > Vector 'a' is the original vector. Vector 'b' gives the lower bounds > of the categories. Vector 'c' is the result I am seeking. > > a <- c(0.9, 11, 1.2, 2.4, 4.0, 5.0, 7.3, 8.1, 3.3, 4.5) > b <- c(0, 2, 4, 6, 8) > > c <- c(0, 8, 0, 2, 4, 4, 6, 8, 2, 4) > > Any suggestions would be greatly appreciated. cut(a, c(b, Inf), labels = b) which returns a factor. Z > cheers, > Allan Strand > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] kernel smoothing of weighted data
You can also specify weights in sm.density() in the package sm. Cheers Francisco >From: Prof Brian Ripley <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] >CC: r-help@stat.math.ethz.ch >Subject: Re: [R] kernel smoothing of weighted data >Date: Tue, 16 Aug 2005 18:13:43 +0100 (BST) > >density() in the R-devel version of R allows weights. > >locfit() in the package of the same name also appears to be documented to. > >On Tue, 16 Aug 2005 [EMAIL PROTECTED] wrote: > > > I want to use kde() or a similar function for kernel smoothing but I >want > > to specify the weight of each of my data points. I do not want to >specify > > the bandwidth on a point by point basis. > >The only kde() I found is from the recent package ks, and is for >multivariate data -- if you want that, you did not say so and I've not >looked for an answer there. > > > This seems such a simple and obvious thing to want to do I am suspicious > > that there is not an obvious way to do it. The only discussion I have > > found is about negative weights(!) and says nothing about >implementation. > > Can anyone suggest a package I have missed or suggest the best starting > > point for writing my own solution. > > > > The reason for wanting this is that I have a number of samples each of > > ~1000 data points from the same distribution but the samples are of > > slightly differing statistical weight and eventually each point in each > > sample may have its own statistical weight. > > > > I have searched the list but I am not subscribed to it so please make me >an > > addressee of any reply. > > >-- >Brian D. Ripley, [EMAIL PROTECTED] >Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ >University of Oxford, Tel: +44 1865 272861 (self) >1 South Parks Road, +44 1865 272866 (PA) >Oxford OX1 3TG, UKFax: +44 1865 272595 > >__ >R-help@stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! >http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Dots in models formulae
On Tue, 2005-08-16 at 12:24 -0500, Sundar Dorai-Raj wrote: > > Uwe Ligges wrote: > > Laurent Valdes wrote: > > > > > >>I have seen, several times, dots (like this: "y ~." ) in formula > >>descriptions, noticeably in R help. > >> > >>I am unable to see what it does correspond to. > >> > >>Any ideas ? > > > > > > All other variables (except y) from the given data.frame... > > > > Uwe Ligges > > > > Hi, Uwe, > > Doesn't this depend on the context? For example, > > z <- data.frame(y = rnorm(10), x = rnorm(10)) > fit <- lm(y ~ ., z) > update(fit, y ~ . + I(x^2)) > > The original poster did not say where he saw this formula. However, I > think the reference in ?formula has the most authorative explanation. Not for "." in a formula in ?formula, at least in platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status Patched major2 minor1.1 year 2005 month08 day 15 language R I still can't find this documented for a formula (I found update.formula, but the meaning of "." is different there, slightly, as you indicate) - but it must be as I didn't imagine seeing it - or maybe I did... G > Thanks, > > --sundar > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Dots in models formulae
On Tue, 16 Aug 2005, Sundar Dorai-Raj wrote: > Uwe Ligges wrote: >> Laurent Valdes wrote: >> >> >>> I have seen, several times, dots (like this: "y ~." ) in formula >>> descriptions, noticeably in R help. >>> >>> I am unable to see what it does correspond to. >>> >>> Any ideas ? >> >> All other variables (except y) from the given data.frame... >> >> Uwe Ligges >> > > Hi, Uwe, > > Doesn't this depend on the context? For example, > > z <- data.frame(y = rnorm(10), x = rnorm(10)) > fit <- lm(y ~ ., z) > update(fit, y ~ . + I(x^2)) > > The original poster did not say where he saw this formula. However, I > think the reference in ?formula has the most authorative explanation. (It does not cover this, as it is part of the interpretation of a formula.) Yes, it must depend on context, as an R function can do anything it likes with a formula (including making y ~ x mean the regression of x on y). If terms.formula() is used, y ~ . means what Uwe said, _if_ there is a 'data' argument. However, if not it has its literal meaning (a variable named '.'), at least until 2.2.0. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Course***R/S-plus Programming**** New York, Washington DC, Seattle, San Francisco / September 2005
XLSolutions Corporation (www.xlsolutions-corp.com) is proud to announce 2-day "R/S-plus Fundamentals and Programming Techniques" at 4 locations nationwide. www.xlsolutions-corp.com/Rfund.htm Seattle, WA - September 1st-2nd, 2005 Washington, DC -- September 8th - 9th, 2005 San Francisco - September 8th - 9th, 2005 New York City September 22nd-23rd, 2005 Reserve your seat now at the early bird rates! Ends August 30th. Payment due AFTER the class Course Description: This two-day beginner to intermediate R/S-plus course focuses on a broad spectrum of topics, from reading raw data to a comparison of R and S. We will learn the essentials of data manipulation, graphical visualization and R/S-plus programming. We will explore statistical data analysis tools,including graphics with data sets. How to enhance your plots, build your own packages (librairies) and connect via ODBC,etc. We will perform some statistical modeling and fit linear regression models. Participants are encouraged to bring data for interactive sessions With the following outline: - An Overview of R and S - Data Manipulation and Graphics - Using Lattice Graphics - A Comparison of R and S-Plus - How can R Complement SAS? - Writing Functions - Avoiding Loops - Vectorization - Statistical Modeling - Project Management - Techniques for Effective use of R and S - Enhancing Plots - Using High-level Plotting Functions - Building and Distributing Packages (libraries) - Connecting; ODBC, Rweb, Orca via sockets and via Rjava Interested in R/Splus Advanced course? email us. Email us for group discounts. Email Sue Turner: [EMAIL PROTECTED] Phone: 206-686-1578 Visit us: www.xlsolutions-corp.com/training.htm Please let us know if you and your colleagues are interested in this classto take advantage of group discount. Register now to secure your seat! Interested in R/Splus Advanced course? email us. Cheers, Elvis Miller, PhD Manager Training. XLSolutions Corporation 206 686 1578 www.xlsolutions-corp.com [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Dots in models formulae
Uwe Ligges wrote: > Laurent Valdes wrote: > > >>I have seen, several times, dots (like this: "y ~." ) in formula >>descriptions, noticeably in R help. >> >>I am unable to see what it does correspond to. >> >>Any ideas ? > > > All other variables (except y) from the given data.frame... > > Uwe Ligges > Hi, Uwe, Doesn't this depend on the context? For example, z <- data.frame(y = rnorm(10), x = rnorm(10)) fit <- lm(y ~ ., z) update(fit, y ~ . + I(x^2)) The original poster did not say where he saw this formula. However, I think the reference in ?formula has the most authorative explanation. Thanks, --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] recategorizing a vector into discrete states
Hi All, I'm trying to take a numerical vector and produce a new vector of the same length where each element in the first is placed into a category given by a 'breaks-like' vector. The values in the result should equal the lower bounds of each category as defined in the breaks vector. I suspect that a vectorized solution is pretty simple, but I can't seem to figure it out today. Here is an example of my problem: Vector 'a' is the original vector. Vector 'b' gives the lower bounds of the categories. Vector 'c' is the result I am seeking. a <- c(0.9, 11, 1.2, 2.4, 4.0, 5.0, 7.3, 8.1, 3.3, 4.5) b <- c(0, 2, 4, 6, 8) c <- c(0, 8, 0, 2, 4, 4, 6, 8, 2, 4) Any suggestions would be greatly appreciated. cheers, Allan Strand __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Dots in models formulae
On Tue, 2005-08-16 at 18:43 +0200, Laurent Valdes wrote: > I have seen, several times, dots (like this: "y ~." ) in formula > descriptions, noticeably in R help. > > I am unable to see what it does correspond to. > > Any ideas ? The "." is a short cut to mean all variables specified in the data argument. E.g.: > dat <- data.frame(y = 1:10, x = 1:10, z = 1:10) > model.frame(y ~ ., data = dat) y x z 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 If the response is also found on the rhs (right-hand-side) of the formula (i.e via using ".") then it is silently droppped from the rhs. So this is equivalent to the above formula > model.frame(y ~ x + y + z, data = dat) y x z 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 Here y isn't the response but is included as it is in ".", i.e. dat. > a <- 1:10 > model.frame(a ~ ., data = dat) a y x z 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 10 10 10 10 10 If we don't specify data and we don't have an object named "." (which may be impossible - I don't know) you get an error: > model.frame(a ~ .) Error in eval(expr, envir, enclos) : Object "." not found I couldn't find "." documented for use in forumla (only for update(), where it means something slightly different) but I remember seeing this somewhere. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Dots in models formulae
Laurent Valdes wrote: > I have seen, several times, dots (like this: "y ~." ) in formula > descriptions, noticeably in R help. > > I am unable to see what it does correspond to. > > Any ideas ? All other variables (except y) from the given data.frame... Uwe Ligges __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] kernel smoothing of weighted data
density() in the R-devel version of R allows weights. locfit() in the package of the same name also appears to be documented to. On Tue, 16 Aug 2005 [EMAIL PROTECTED] wrote: > I want to use kde() or a similar function for kernel smoothing but I want > to specify the weight of each of my data points. I do not want to specify > the bandwidth on a point by point basis. The only kde() I found is from the recent package ks, and is for multivariate data -- if you want that, you did not say so and I've not looked for an answer there. > This seems such a simple and obvious thing to want to do I am suspicious > that there is not an obvious way to do it. The only discussion I have > found is about negative weights(!) and says nothing about implementation. > Can anyone suggest a package I have missed or suggest the best starting > point for writing my own solution. > > The reason for wanting this is that I have a number of samples each of > ~1000 data points from the same distribution but the samples are of > slightly differing statistical weight and eventually each point in each > sample may have its own statistical weight. > > I have searched the list but I am not subscribed to it so please make me an > addressee of any reply. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] A question about MIX package
Hello all, When I used commands "ecm.mix and dabipf.mix" to do a simulation (sample size is small 100), I got an error : Steps of ECM, missing value where True/False needed. I've checked the menu, and the option "prior" of ecm.mix said that if structural zeros appear in the table, hyperparameters for those cells should be set to NA. However, it didn't say how to do that in the command. I am wondering if someone knows how to fix this. I appreciate your help, Jia __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Looking for a collaborator
I'm looking for a collaborator with strong R debugging skills to work on a project involving symmetric permutations. Should have interest in permutation/randomization methods. Please reply directly to me and not to the list. Phillip Good for background, see http://tbf.coe.wayne.edu/jmasm/vol1_no2.pdf pages 243-47, or http://mysite.verizon.net/res7sf1o/subgroups.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Dots in models formulae
I have seen, several times, dots (like this: "y ~." ) in formula descriptions, noticeably in R help. I am unable to see what it does correspond to. Any ideas ? -- --~~ Toulouse, Grenoble, Auch, Arcachon, Béziers, Paris, Saragosse, Lévignac Sur Save, habitats naturel du Valdo. ~~-- < http://www.le-valdo.com> __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Stacked Area chart
On Tue, 16 Aug 2005 12:03:01 -0400 Mike Saunders wrote: > I wish to do a stacked area chart to show how relative proportions of > species within a stand have changed over time. If you don't want to show the marginal distribution over time, then you can use barplot() on the table of relative frequencies (e.g., obtained by prop.table()). If you want to show the marginal distribution, you can use mosaicplot(). The functions doubledecker() and mosaic() in package vcd might also be helpful. Z > I know this is simple, but can someone point me to the right function > (if it exists). I have not had any luck finding it in the R-help, but > maybe I am searching using the wrong keywords. > > Thanks, > Mike > > > Mike Saunders > Research Assistant > Forest Ecosystem Research Program > Department of Forest Ecosystem Sciences > University of Maine > Orono, ME 04469 > 207-581-2763 (O) > 207-581-4257 (F) > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] kernel smoothing of weighted data
Hi, I want to use kde() or a similar function for kernel smoothing but I want to specify the weight of each of my data points. I do not want to specify the bandwidth on a point by point basis. This seems such a simple and obvious thing to want to do I am suspicious that there is not an obvious way to do it. The only discussion I have found is about negative weights(!) and says nothing about implementation. Can anyone suggest a package I have missed or suggest the best starting point for writing my own solution. The reason for wanting this is that I have a number of samples each of ~1000 data points from the same distribution but the samples are of slightly differing statistical weight and eventually each point in each sample may have its own statistical weight. I have searched the list but I am not subscribed to it so please make me an addressee of any reply. Thanks Robert Patterson __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] stepAIC invalid scope argument
Thank you. Your suggestion is equivalent is the same as my second stepAIC command that failed in R-2.1.1. See Prof. Ripley's reply where he pointed out that this was due to using the name 'df' which clashes with built-in function with the same name from stats package. Regards, Adai On Tue, 2005-08-16 at 15:52 +0100, John Wilkinson (pipex) wrote: > Adai, > > The following works.Perhaps you should define your 'upper' and 'lower' > in the list as aov's, as you have done with your lo,hi and mid. > > John > > > stepAIC( mid, scope=list(upper = mid , lower = lo) ) > Start: AIC= -594.66 > y ~ x2 + x3 > >Df Sum of Sq RSS AIC > - x21 0.11 548.56 -596.45 > - x31 0.95 549.40 -594.93 >548.45 -594.66 > > Step: AIC= -596.45 > y ~ x3 > > Adaikalavan Ramasamy wrote --- > > I am trying to replicate the first example from stepAIC from the MASS > package with my own dataset but am running into error. If someone can > point where I have gone wrong, I would appreciate it very much. > > Here is an example : > > set.seed(1) > df <- data.frame( x1=rnorm(1000), x2=rnorm(1000), x3=rnorm(1000) ) > df$y <- 0.5*df$x1 + rnorm(1000, mean=8, sd=0.5) > # pairs(df); head(df) > > lo <- aov( y ~ 1, data=df ) > hi <- aov( y ~ .^2, data=df ) > mid <- aov( y ~ x2 + x3, data=df ) > > Running any of the following commands > > stepAIC( mid, scope=list(upper = ~x1 + x2 + x3 , lower = ~1) ) > stepAIC( mid, scope=list(upper = hi , lower = lo) ) > addterm( mid, ~ x1 + x2 + x3 ) > addterm( lo, hi ) > > gives the same error message : > Error in eval(expr, envir, enclos) : invalid second argumen > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Stacked Area chart
I wish to do a stacked area chart to show how relative proportions of species within a stand have changed over time. I know this is simple, but can someone point me to the right function (if it exists). I have not had any luck finding it in the R-help, but maybe I am searching using the wrong keywords. Thanks, Mike Mike Saunders Research Assistant Forest Ecosystem Research Program Department of Forest Ecosystem Sciences University of Maine Orono, ME 04469 207-581-2763 (O) 207-581-4257 (F) [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] preprocessing data
On 8/16/05, Jean Eid <[EMAIL PROTECTED]> wrote: > Dear all, > > My question is concerning the line > "This is adequate for small files, but for anything more complicated we > recommend using the facilities of a language like perl to pre-process > the file." > > in the import/export manual. > > I have a large fixed-width file that I would like to preprocess in Perl or > awk. The problem is that I do not know where to start. Does anyone have a > simple example on how to turn a fixed-width file in any of these > facilities into csv or tab delimited file. I guess I am looking for > somewhat a perl for dummies or awk for dummies that does this. any > pointers for website will be greatly appreciated > Try to do it in R first. I have found that I rarely need to go to an outside language to massage my data. # fixed with fields of 10 and 5 Lines <- readLines("mydata.dat") data.frame( field1 = as.numeric(substring(1,10,Lines), field2 = as.numeric(substring(11,15,Lines) ) If you do find that you have speed or memory problems that require that you go outside of R to preprocess your data then the gawk version of awk has a FIELDWIDTHS variable that makes handling fixed fields very easy. The gawk program below assumes two fields of widths 10 and 5, respectively, which is set in the first line. Then it repeatedly executes the second line for each input line forcing field splitting by a dummy manipulation (since field splitting is lazy) and then printing each line, the default being to print out the entire line with a space between successive fields: BEGIN { FIELDWIDTHS = "10 5" } { $1 = $1; print } In R, do the following assuming the above two lines are in split.awk: read.table(pipe("gawk -f split.awk mydata.dat")) or else run gawk outside of R then read in the output file created: gawk -f split.awk mydata.dat > mydata2.dat For more information, google for FIELDWIDTHS gawk for that portion of the manual on FIELDWIDTHS -- it includes an example and, of course, the whole manual is there too. The book by Kernighan et al is also good. I have used both awk and perl and I think its unlikely you would need perl given that you have R at your disposal for the hard parts and awk is easier to learn, better designed and more focused on this sort of task. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Fwd: Documenting data sets with many variables
On Tue, 2005-08-16 at 17:11 +0200, Arne Henningsen wrote: > On Tuesday 16 August 2005 14:49, Roger D. Peng wrote: > > Have you tried using 'promptData()' on the data frame and then > > just using the resulting documentation file? > > Thank you, Roger, for bringing 'promptData()' to my mind. This is really a > useful tool. However, in my special case my aim is to reduce the extent and > increase the comprehensibility of the documentation rather than to reduce my > effort to write the documentation. > > Any further hints are welcome! > > Thanks, > Arne Would it not be expedient then to ignore the \format{} section and just provide the information on the variables say in the \description{}, e.g.: This example taken from package vegan describing 2 data.frames with 44 and 14 columns. Admittedly, none of the variables in the species dataset are explicitly and individually described in this example, but it is sufficient in this case I think. \name{varespec} \alias{varechem} \alias{varespec} \docType{data} \title{Vegetation and environment in lichen pastures} \usage{ data(varechem) data(varespec) } \description{ The \code{varespec} data frame has 24 rows and 44 columns. Columns are estimated cover values of 44 species. The variable names are formed from the scientific names, and are self explanatory for anybody familiar with the vegetation type. The \code{varechem} data frame has 24 rows and 14 columns, giving the soil characteristics of the very same sites as in the \code{varespec} data frame. The chemical measurements have obvious names. \code{Baresoil} gives the estimated cover of bare soil, \code{Humpdepth} the thickness of the humus layer. } HTH G > > > -roger > > > > Arne Henningsen wrote: > > > Hi, > > > > > > since nobody answered to my first message, I try to explain my problem > > > more clearly and more general this time: > > > > > > I have a data set in my R package "micEcon", which has many variables > > > (82). Therefore, I would like to avoid to describe all variables in the > > > "\format" section of the documentation (.Rd file). However, doing this > > > lets "R CMD check" complain about "data codoc mismatches" (details see > > > below). Is there a way to avoid the description of all variables without > > > getting a complaint from "R CMD check"? > > > > > > Thanks, > > > Arne > > > > > > > > > -- Forwarded Message -- > > > > > > Subject: Documenting data sets with many variables > > > Date: Friday 05 August 2005 14:03 > > > From: Arne Henningsen <[EMAIL PROTECTED]> > > > To: R-help@stat.math.ethz.ch > > > > > > Hi, > > > > > > I extended the data set "Blanciforti86" that is included in my R package > > > "micEcon". For instance, I added consumer prices, annual consumption > > > expenditures and expenditure shares of eleven aggregate commodity groups. > > > The corresponding variables in the data frame are called "pAgg1", > > > "pAgg2", ..., "pAgg11", "xAgg1", "xAgg2", ..., "xAgg11", "wAgg1", > > > "wAgg2", ..., "wAgg11". To avoid to describe all 33 items in the > > > "\format" section of the documentation (.Rd file) I wrote something like > > > > > > \format{ > > >This data frame contains the following columns: > > >\describe{ > > > [ . . . ] > > > \item{xAggX}{Expenditure on the aggregate commodity group X > > > (in Millions of US-Dollars).} > > > \item{pAggX}{Price index for the aggregate commodity group X > > > (1972 = 100).} > > > \item{wAggX}{Expenditure share of the aggregate commodity group X.} > > > [ . . . ] > > >} > > > } > > > > > > and explained the 11 aggregate commodity groups only once in a different > > > section (1=food, 2=clothing, ... ). However, "R CMD check" now complains > > > about "data codoc mismatches", e.g. > > > Code: [...] pAgg1pAgg2 pAgg3 [...] > > > Docs: [...] pAggX [...] > > > > > > Is there a way to avoid the description of all 33 items without getting a > > > complaint from "R CMD check"? > > > > > > Thanks, > > > Arne > > > > > > --- > -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [T] +44 (0)20 7679 5522 ENSIS Research Fellow [F] +44 (0)20 7679 7565 ENSIS Ltd. & ECRC [E] gavin.simpsonATNOSPAMucl.ac.uk UCL Department of Geography [W] http://www.ucl.ac.uk/~ucfagls/cv/ 26 Bedford Way[W] http://www.ucl.ac.uk/~ucfagls/ London. WC1H 0AP. %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Fwd: Documenting data sets with many variables
On Tuesday 16 August 2005 14:49, Roger D. Peng wrote: > Have you tried using 'promptData()' on the data frame and then > just using the resulting documentation file? Thank you, Roger, for bringing 'promptData()' to my mind. This is really a useful tool. However, in my special case my aim is to reduce the extent and increase the comprehensibility of the documentation rather than to reduce my effort to write the documentation. Any further hints are welcome! Thanks, Arne > -roger > > Arne Henningsen wrote: > > Hi, > > > > since nobody answered to my first message, I try to explain my problem > > more clearly and more general this time: > > > > I have a data set in my R package "micEcon", which has many variables > > (82). Therefore, I would like to avoid to describe all variables in the > > "\format" section of the documentation (.Rd file). However, doing this > > lets "R CMD check" complain about "data codoc mismatches" (details see > > below). Is there a way to avoid the description of all variables without > > getting a complaint from "R CMD check"? > > > > Thanks, > > Arne > > > > > > -- Forwarded Message -- > > > > Subject: Documenting data sets with many variables > > Date: Friday 05 August 2005 14:03 > > From: Arne Henningsen <[EMAIL PROTECTED]> > > To: R-help@stat.math.ethz.ch > > > > Hi, > > > > I extended the data set "Blanciforti86" that is included in my R package > > "micEcon". For instance, I added consumer prices, annual consumption > > expenditures and expenditure shares of eleven aggregate commodity groups. > > The corresponding variables in the data frame are called "pAgg1", > > "pAgg2", ..., "pAgg11", "xAgg1", "xAgg2", ..., "xAgg11", "wAgg1", > > "wAgg2", ..., "wAgg11". To avoid to describe all 33 items in the > > "\format" section of the documentation (.Rd file) I wrote something like > > > > \format{ > >This data frame contains the following columns: > >\describe{ > > [ . . . ] > > \item{xAggX}{Expenditure on the aggregate commodity group X > > (in Millions of US-Dollars).} > > \item{pAggX}{Price index for the aggregate commodity group X > > (1972 = 100).} > > \item{wAggX}{Expenditure share of the aggregate commodity group X.} > > [ . . . ] > >} > > } > > > > and explained the 11 aggregate commodity groups only once in a different > > section (1=food, 2=clothing, ... ). However, "R CMD check" now complains > > about "data codoc mismatches", e.g. > > Code: [...] pAgg1pAgg2 pAgg3 [...] > > Docs: [...] pAggX [...] > > > > Is there a way to avoid the description of all 33 items without getting a > > complaint from "R CMD check"? > > > > Thanks, > > Arne > > > > --- -- Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 [EMAIL PROTECTED] http://www.uni-kiel.de/agrarpol/ahenningsen/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] stepAIC invalid scope argument
Adai, The following works.Perhaps you should define your 'upper' and 'lower' in the list as aov's, as you have done with your lo,hi and mid. John > stepAIC( mid, scope=list(upper = mid , lower = lo) ) Start: AIC= -594.66 y ~ x2 + x3 Df Sum of Sq RSS AIC - x21 0.11 548.56 -596.45 - x31 0.95 549.40 -594.93 548.45 -594.66 Step: AIC= -596.45 y ~ x3 Adaikalavan Ramasamy wrote --- I am trying to replicate the first example from stepAIC from the MASS package with my own dataset but am running into error. If someone can point where I have gone wrong, I would appreciate it very much. Here is an example : set.seed(1) df <- data.frame( x1=rnorm(1000), x2=rnorm(1000), x3=rnorm(1000) ) df$y <- 0.5*df$x1 + rnorm(1000, mean=8, sd=0.5) # pairs(df); head(df) lo <- aov( y ~ 1, data=df ) hi <- aov( y ~ .^2, data=df ) mid <- aov( y ~ x2 + x3, data=df ) Running any of the following commands stepAIC( mid, scope=list(upper = ~x1 + x2 + x3 , lower = ~1) ) stepAIC( mid, scope=list(upper = hi , lower = lo) ) addterm( mid, ~ x1 + x2 + x3 ) addterm( lo, hi ) gives the same error message : Error in eval(expr, envir, enclos) : invalid second argumen __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] regression with more than one observation per x value
Sounds like you're looking for something like pure.error.anova in the `alr3' package on CRAN... Andy > From: Christoph Scherber > > Dear R users, > > How can I do a regression analysis in R where there is more than one > observation per x value? I tried the example in Sokal&Rohlf > (3rd edn., > 1995), page 476 ff., but I somehow couldn´t find a way to > partition the > sums of squares into "linear regression", "deviations from > regression", > and within-groups SS. > > I tried > > model1<-lm(y~as.numeric(x)+as.factor(x) #with treatment contrasts > > > but I am sure there´s a better way around it. I would be very > happy if > anyone could give me some suggestions on this. > > Best regards > Christoph. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] predict nbinomial glm
Katharina, I agree with Prof. Ripley's assessment. But, perhaps one thing you may have overlooked is that subset.data.frame does not remove unused levels. So, > subset_of_dataframe = subset(data_frame, (b > 80 & c < 190)) > levels(subset_of_dataframe$d) [1] "q" "r" "s" "t" > table(subset_of_dataframe$d) q r s t 0 20 50 10 Even though the level "q" does not appear it is still a level of "d". Perhaps you need to do the following after the subset: subset_of_dataframe[] <- lapply(subset_of_dataframe, "[", drop = TRUE) which drops all unused levels from factors. I'm not sure if your problem is statistical in nature or simply a misunderstanding of the software. I'm only attempting to answer the latter. As Prof. Ripley suggests, discuss any statistical problem (i.e. predicting on missing levels) with your advisor. HTH, --sundar P.S. Also, update R. It's free. Prof Brian Ripley wrote: > This is seems to be an unstated repeat of much of an earlier and > unanswered post > > https://stat.ethz.ch/pipermail/r-help/2005-August/075914.html > > entitled > > [R] error in predict glm (new levels cause problems) > > It is nothing to do with `nbinomial glm' (sic): all model fitting > functions including lm and glm do this. The reason you did not get at > least one reply from your first post is that you seemed not to have done > your homework. (One thing the posting guide does ask is for you to try > the current version of R, and yours is three versions old.) > > The code is protecting you from an attempt at statistical nonsense. > (Indeed, the check was added to catch such misuses.) Your email address > seems to be that of a student, so please seek the help of your advisor. > You seem surprised that you are not allowed to make predictions about > levels for which you have supplied no relevant data. > > > On Tue, 16 Aug 2005, K. Steinmann wrote: > > >>Dear R-helpers, >> >>let us assume, that I have the following dataset: >> >>a <- rnbinom(200, 1, 0.5) >>b <- (1:200) >>c <- (30:229) >>d <- rep(c("q", "r", "s", "t"), rep(50,4)) >>data_frame <- data.frame(a,b,c,d) >> >>In a first step I run a glm.nb (full code is given at the end of this mail) >>and >>want to predict my response variable a. >>In a second step, I would like to run a glm.nb based on a subset of the >>data_frame. As soon as I want to predict the response variable a, I get the >>following error message: >>"Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = >>object$xlevels) : >> factor d has new level(s) q" >> >>Does anybody have a solution to this problem? >> >>Thank you in advance, >>K. Steinmann (working with R 2.0.0) >> >> >>Code: >> >>library(MASS) >> >>a <- rnbinom(200, 1, 0.5) >>b <- (1:200) >>c <- (30:229) >>d <- rep(c("q", "r", "s", "t"), rep(50,4)) >> >>data_frame <- data.frame(a,b,c,d) >> >>model_1 = glm.nb(a ~ b + d , data = data_frame) >> >>pred_model_1 = predict(model_1, newdata = data_frame, type = "response", >>se.fit >>= FALSE, dispersion = NULL, terms = NULL) >> >>subset_of_dataframe = subset(data_frame, (b > 80 & c < 190 )) >> >>model_2 = glm.nb(a ~ b + d , data = subset_of_dataframe) >>pred_model_2 = predict(model_2, newdata = subset_of_dataframe, type = >>"response", se.fit = FALSE, dispersion = NULL, terms = NULL) > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] The naPattern agrument of gnls()
I was hoping someone could help me to better understand the naPattern argument in the function gnls(). Unfortunately, there's no example using this argument provided in the help file. According to the gnls() help file, naPattern is "an expression or formula object, specifying which returned values are to be regarded as missing". As I understand it, the idea is that with some models (e.g. quinModel) some of the rows that are needed to compute the predicted values aren't observations of the response variable and need to be left out of the optimization. The nlme() function has an argument with the same name and description. I've used naPattern successfully with the nlme() function, following an example in the book "Mixed-Effects Models in S and S-PLUS" by Pinheiro and Bates, but a similar attempt with gnls() fails with the error message: Error in data.frame(data, getParsGnls(plist, pmap, beta, N)) : arguments imply differing number of rows: 695, 287 Any help or explanation would be appreciated. I'm using R version 2.1.0 on linux. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] regression with more than one observation per x value
Dear R users, How can I do a regression analysis in R where there is more than one observation per x value? I tried the example in Sokal&Rohlf (3rd edn., 1995), page 476 ff., but I somehow couldn´t find a way to partition the sums of squares into "linear regression", "deviations from regression", and within-groups SS. I tried model1<-lm(y~as.numeric(x)+as.factor(x) #with treatment contrasts but I am sure there´s a better way around it. I would be very happy if anyone could give me some suggestions on this. Best regards Christoph. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] predict nbinomial glm
This is seems to be an unstated repeat of much of an earlier and unanswered post https://stat.ethz.ch/pipermail/r-help/2005-August/075914.html entitled [R] error in predict glm (new levels cause problems) It is nothing to do with `nbinomial glm' (sic): all model fitting functions including lm and glm do this. The reason you did not get at least one reply from your first post is that you seemed not to have done your homework. (One thing the posting guide does ask is for you to try the current version of R, and yours is three versions old.) The code is protecting you from an attempt at statistical nonsense. (Indeed, the check was added to catch such misuses.) Your email address seems to be that of a student, so please seek the help of your advisor. You seem surprised that you are not allowed to make predictions about levels for which you have supplied no relevant data. On Tue, 16 Aug 2005, K. Steinmann wrote: > Dear R-helpers, > > let us assume, that I have the following dataset: > > a <- rnbinom(200, 1, 0.5) > b <- (1:200) > c <- (30:229) > d <- rep(c("q", "r", "s", "t"), rep(50,4)) > data_frame <- data.frame(a,b,c,d) > > In a first step I run a glm.nb (full code is given at the end of this mail) > and > want to predict my response variable a. > In a second step, I would like to run a glm.nb based on a subset of the > data_frame. As soon as I want to predict the response variable a, I get the > following error message: > "Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = > object$xlevels) : >factor d has new level(s) q" > > Does anybody have a solution to this problem? > > Thank you in advance, > K. Steinmann (working with R 2.0.0) > > > Code: > > library(MASS) > > a <- rnbinom(200, 1, 0.5) > b <- (1:200) > c <- (30:229) > d <- rep(c("q", "r", "s", "t"), rep(50,4)) > > data_frame <- data.frame(a,b,c,d) > > model_1 = glm.nb(a ~ b + d , data = data_frame) > > pred_model_1 = predict(model_1, newdata = data_frame, type = "response", > se.fit > = FALSE, dispersion = NULL, terms = NULL) > > subset_of_dataframe = subset(data_frame, (b > 80 & c < 190 )) > > model_2 = glm.nb(a ~ b + d , data = subset_of_dataframe) > pred_model_2 = predict(model_2, newdata = subset_of_dataframe, type = > "response", se.fit = FALSE, dispersion = NULL, terms = NULL) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Image from bytes streams
On Tue, 16 Aug 2005, Márcio de Medeiros Ribeiro wrote: First, thank you very much for the answers... I have used the png() function before for generate the image and then capture its bytes. My big problem is that my program reads the image before that its complete by the png() function. For instance, my graphic image has 1000Kb. When R saves it into the hard disk, my Java program reads the file before the save operation completes (500Kb for example). So, I got only a part of the file and hence the image... :( One solution is read the image and search for a byte which represents the end of the file, but it depends on the image format... So, how can I discover that R image save operation stored the complete file into the hard disk? When dev.off() completes and you get an R prompt back. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Image from bytes streams
Hi, First, thank you very much for the answers... I have used the png() function before for generate the image and then capture its bytes. My big problem is that my program reads the image before that its complete by the png() function. For instance, my graphic image has 1000Kb. When R saves it into the hard disk, my Java program reads the file before the save operation completes (500Kb for example). So, I got only a part of the file and hence the image... :( One solution is read the image and search for a byte which represents the end of the file, but it depends on the image format... So, how can I discover that R image save operation stored the complete file into the hard disk? Thank you one more time! -- Márcio de Medeiros Ribeiro Graduando em Ciência da Computação Departamento de Tecnologia da Informação - TCI Universidade Federal de Alagoas - UFAL Maceió - Alagoas - Brasil Projeto ArCo - Arcabouço de Comunidades Contato: +55 82 354-3358/9997-6794 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] return unique values from date/time class object
__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to merge two strings
On Tue, 16 Aug 2005, Barry Rowlingson wrote: > Claus Hindsgaul wrote: >> Thank you all! >> Paste() was just the function I needed to know! > > Or sprintf: > > > s1 <- "R-" > > s2 <- "project" > > sprintf("%s%s",s1,s2) > [1] "R-project" > > It seems to be much faster: > > > unix.time(for(i in 1:10){junk=sprintf("%s%s",s1,s2)}) > [1] 1.12 0.00 1.12 0.00 0.00 > > unix.time(for(i in 1:10){junk=paste(s1,s2,sep='')}) > [1] 5.90 0.01 5.92 0.00 0.00 > > Not that I imagine string concatenation will ever be a bottleneck > worth optimising but there it is. A well-constructed sprintf() call may > be more readable than a pastey mess though, with all its fiddly commas > and quotes - contrived example: > > > sprintf("%s://%s%s/%s",scheme,host,dir,file) > [1] "http://www.foo.com/foo/bar/baz.txt"; > > > paste(scheme,'://',host,dir,'/',file,sep='') > [1] "http://www.foo.com/foo/bar/baz.txt"; > > which do you prefer? That's actually the reason we have the enhanced sprintf that we do nowadays: to enable readable (and translatable) error messages to be written via gettextf. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] preprocessing data
Thank you, that is exactly what I was looking for. Just a minor suggestion to the manual Import/Export. maybe a reference to the paper right underneath the line below would be helpfull for people like me that have never used perl and would like to take the suggestion to preprosses the data Jean On Tue, 16 Aug 2005, Kevin E. Thorpe wrote: > Some time ago, Doug Bates wrote a useful paper called "Data > manipulatation in perl." It is a very concise intoduction and > introduces the unpack function which is one way to deal with fixed > format data. Just google for > >"data manipulation in perl" bates > > and you should be able to find a copy. > > Jean Eid wrote: > > Dear all, > > > > My question is concerning the line > > "This is adequate for small files, but for anything more complicated we > > recommend using the facilities of a language like perl to pre-process > > the file." > > > > in the import/export manual. > > > > I have a large fixed-width file that I would like to preprocess in Perl or > > awk. The problem is that I do not know where to start. Does anyone have a > > simple example on how to turn a fixed-width file in any of these > > facilities into csv or tab delimited file. I guess I am looking for > > somewhat a perl for dummies or awk for dummies that does this. any > > pointers for website will be greatly appreciated > > > > Thank you > > > > > > Jean Eid > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > -- > Kevin E. Thorpe > Biostatistician/Trialist, Knowledge Translation Program > Assistant Professor, Department of Public Health Sciences > Faculty of Medicine, University of Toronto > email: [EMAIL PROTECTED] Tel: 416.946.8081 Fax: 416.971.2462 > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] preprocessing data
Some time ago, Doug Bates wrote a useful paper called "Data manipulatation in perl." It is a very concise intoduction and introduces the unpack function which is one way to deal with fixed format data. Just google for "data manipulation in perl" bates and you should be able to find a copy. Jean Eid wrote: > Dear all, > > My question is concerning the line > "This is adequate for small files, but for anything more complicated we > recommend using the facilities of a language like perl to pre-process > the file." > > in the import/export manual. > > I have a large fixed-width file that I would like to preprocess in Perl or > awk. The problem is that I do not know where to start. Does anyone have a > simple example on how to turn a fixed-width file in any of these > facilities into csv or tab delimited file. I guess I am looking for > somewhat a perl for dummies or awk for dummies that does this. any > pointers for website will be greatly appreciated > > Thank you > > > Jean Eid > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > -- Kevin E. Thorpe Biostatistician/Trialist, Knowledge Translation Program Assistant Professor, Department of Public Health Sciences Faculty of Medicine, University of Toronto email: [EMAIL PROTECTED] Tel: 416.946.8081 Fax: 416.971.2462 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Fwd: Documenting data sets with many variables
Have you tried using 'promptData()' on the data frame and then just using the resulting documentation file? -roger Arne Henningsen wrote: > Hi, > > since nobody answered to my first message, I try to explain my problem more > clearly and more general this time: > > I have a data set in my R package "micEcon", which has many variables (82). > Therefore, I would like to avoid to describe all variables in the "\format" > section of the documentation (.Rd file). However, doing this lets "R CMD > check" complain about "data codoc mismatches" (details see below). > Is there a way to avoid the description of all variables without getting a > complaint from "R CMD check"? > > Thanks, > Arne > > > -- Forwarded Message -- > > Subject: Documenting data sets with many variables > Date: Friday 05 August 2005 14:03 > From: Arne Henningsen <[EMAIL PROTECTED]> > To: R-help@stat.math.ethz.ch > > Hi, > > I extended the data set "Blanciforti86" that is included in my R package > "micEcon". For instance, I added consumer prices, annual consumption > expenditures and expenditure shares of eleven aggregate commodity groups. > The corresponding variables in the data frame are called "pAgg1", > "pAgg2", ..., "pAgg11", "xAgg1", "xAgg2", ..., "xAgg11", "wAgg1", > "wAgg2", ..., "wAgg11". To avoid to describe all 33 items in the "\format" > section of the documentation (.Rd file) I wrote something like > > \format{ >This data frame contains the following columns: >\describe{ > [ . . . ] > \item{xAggX}{Expenditure on the aggregate commodity group X > (in Millions of US-Dollars).} > \item{pAggX}{Price index for the aggregate commodity group X > (1972 = 100).} > \item{wAggX}{Expenditure share of the aggregate commodity group X.} > [ . . . ] >} > } > > and explained the 11 aggregate commodity groups only once in a different > section (1=food, 2=clothing, ... ). However, "R CMD check" now complains > about "data codoc mismatches", e.g. > Code: [...] pAgg1pAgg2 pAgg3 [...] > Docs: [...] pAggX [...] > > Is there a way to avoid the description of all 33 items without getting a > complaint from "R CMD check"? > > Thanks, > Arne > > --- > -- Roger D. Peng http://www.biostat.jhsph.edu/~rpeng/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] preprocessing data
Dear all, My question is concerning the line "This is adequate for small files, but for anything more complicated we recommend using the facilities of a language like perl to pre-process the file." in the import/export manual. I have a large fixed-width file that I would like to preprocess in Perl or awk. The problem is that I do not know where to start. Does anyone have a simple example on how to turn a fixed-width file in any of these facilities into csv or tab delimited file. I guess I am looking for somewhat a perl for dummies or awk for dummies that does this. any pointers for website will be greatly appreciated Thank you Jean Eid __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] p-values
On Thu, 4 Aug 2005, Peter Ho wrote: > HI R-users, > > I am trying to repeat an example from Rayner and Best "A contingency > table approach to nonparametric testing (Chapter 7, Ice cream example). > > In their book they calculate Durbin's statistic, D1, a dispersion > statistics, D2, and a residual. P-values for each statistic is > calculated from a chi-square distribution and also Monte Carlo p-values. Hi Peter, when I understand the example correctly, the main interest is testing independence of the judges' ranking and the ice cream brand, where the judges are interpreted as `blocks' using a chi^2-type statistic based on the rank sums for each ice cream. In R: ice <- data.frame(judge = factor(rep(c(1:7),rep(3,7))), variety = factor(c(1,2,4,2,3,5,3,4,6,4,5,7,1,5,6,2,6,7,1,3,7)), rank = c(2,3,1,3,1,2,2,1,3,1,2,3,3,1,2,3,1,2,3,1,2)) library("coin") it <- independence_test(rank ~ variety | judge, data = ice, teststat = "quadtype") it Asymptotic General Independence Test data: rank by groups 1, 2, 3, 4, 5, 6, 7 stratified by judge T = 12, df = 6, p-value = 0.06197 So without having checked the theory exactly, this looks like being Dubin's D1 statistic with _asymptotic conditional p-value_ (please have a look at coin's vignette which explains what happens here). The Monte-Carlo p-value can now be computed by 99,999 replications: pvalue(independence_test(rank ~ variety | judge, data = ice, teststat = "quadtype", distribution = approximate(B = 9))) [1] 0.01778018 99 percent confidence interval: 0.01672170 0.01888482 which seems to be a little bit smaller than 0.02. Hope that helps, Torsten > > I have found similar p-values based on the chi-square distribution by > using: > > > pchisq(12, df= 6, lower.tail=F) > [1] 0.0619688 > > pchisq(5.1, df= 6, lower.tail=F) > [1] 0.5310529 > > Is there a way to calculate the equivalent Monte Carlo p-values? > > The values were 0.02 and 0.138 respectively. > > The use of the approximate chi-square probabilities for Durbin's test > are considered not good enough according to Van der Laan (The American > Statistician 1988,42,165-166). > > > Peter > > ESTG-IPVC > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] different leave-one-out cross-validation results from tune.svm(...) and svm(...)
Hi, I am currently using the svm functions from R package e1071 (1.5-9). I use function tune.svm(...) to tune the parameters for SVM with RBF kernel. To obtain reproducible tuning results, I chose leave-one-out cross-validation (LOOCV) as my perfomance measurement. > tune.rlt <- tune.svm(classes~., data = data.frame(features, classes), gamma = 2^(-12:0), cost = 2^(0:12), tunecontrol = tune.control(cross = length(cls))) With this LOOCV scheme I obtained certain best performance with tuned parameters (gamma1, cost1). Let's assume the best error estimation in tune.rlt is E. Then I trained a SVM with these parameters (gamma1 & cost1). I also ask it to return LOOCV results: > svm.rlt <- svm(classes~., data = data.frame(features, classes), gamma=gamma1, cost=cost1, cross=length(classes)) And I obtain LOOCV accuracy from svm.rlt, let's assume it is A. Unfortunately, it is usually the case that E+A < 100% (it is not numerical error) Since I used LOOCV as the perfomance measurement, I suppose E+A =100% Why is this the case? -- Wolfgang Meyer __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to merge two strings
Claus Hindsgaul wrote: > Thank you all! > Paste() was just the function I needed to know! Or sprintf: > s1 <- "R-" > s2 <- "project" > sprintf("%s%s",s1,s2) [1] "R-project" It seems to be much faster: > unix.time(for(i in 1:10){junk=sprintf("%s%s",s1,s2)}) [1] 1.12 0.00 1.12 0.00 0.00 > unix.time(for(i in 1:10){junk=paste(s1,s2,sep='')}) [1] 5.90 0.01 5.92 0.00 0.00 Not that I imagine string concatenation will ever be a bottleneck worth optimising but there it is. A well-constructed sprintf() call may be more readable than a pastey mess though, with all its fiddly commas and quotes - contrived example: > sprintf("%s://%s%s/%s",scheme,host,dir,file) [1] "http://www.foo.com/foo/bar/baz.txt"; > paste(scheme,'://',host,dir,'/',file,sep='') [1] "http://www.foo.com/foo/bar/baz.txt"; which do you prefer? Barry __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to merge two strings
Thank you all! Paste() was just the function I needed to know! Claus tir, 16 08 2005 kl. 13:06 +0200, skrev Dimitris Rizopoulos: > look at ?paste(), e.g., > > s1 <- "R-" > s2 <- "project" > paste(s1, s2, sep = "") > > > Best, > Dimitris > > > Dimitris Rizopoulos > Ph.D. Student > Biostatistical Centre > School of Public Health > Catholic University of Leuven > > Address: Kapucijnenvoer 35, Leuven, Belgium > Tel: +32/16/336899 > Fax: +32/16/337015 > Web: http://www.med.kuleuven.be/biostat/ > http://www.student.kuleuven.be/~m0390867/dimitris.htm > > > - Original Message - > From: "Claus Hindsgaul" <[EMAIL PROTECTED]> > To: > Sent: Tuesday, August 16, 2005 1:01 PM > Subject: [R] How to merge two strings > > > > Hi r-help, > > > > A very simple question for which I have not been able to find an > > answer > > in the docs: > > > > How can I merge two character strings? > > > > I am searching for the equivalent of the (non-existing) stringmerge > > function illustrated below: > > > >> s1 <- "R-" > >> s2 <- "project" > >> stringmerge(s1,s2) > > [1] "R-project" > >> > > > > Claus > > > > -- > > Ph.D. Student Claus Hindsgaul > > CHEC, Dept. Chemical Eng. (KT), DTU > > and Biomass Gasification Group, Dept. Mechanical Eng. (MEK), DTU > > DTU Building 229 room 154, Phone +45 4525 2838 > > http://bgg.mek.dtu.dk/ and http://www.kt.dtu.dk/ > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > -- Ph.D. Student Claus Hindsgaul CHEC, Dept. Chemical Eng. (KT), DTU and Biomass Gasification Group, Dept. Mechanical Eng. (MEK), DTU DTU Building 229 room 154, Phone +45 4525 2838 http://bgg.mek.dtu.dk/ and http://www.kt.dtu.dk/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Vector comparison to matrix
or maybe something like this: nMatches2 <- sum(!is.na( match(apply(A, 1, paste, collapse = ""), paste(target, collapse = "")) )) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: "Sigurdur Jonsson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: Sent: Tuesday, August 16, 2005 12:47 PM Subject: [R] Vector comparison to matrix Hi Todd and list, I see you have received a few suggestions, here's another: # set up data: your vector and an a 3x30 matrix with a few # matching lines: target<-c(1,2,3) A<-matrix(sample(1:3,30,replace=TRUE),ncol=3) # count matches: nMatches<-sum(apply(A,1,function(x,target) all.equal(x,target),target)=="TRUE") # by applying a simple function, which takes 'target' as an 'extra' # argument, to the rows of A. The function returns a vector of # differences and 'TRUE'-s, the latter of which can be counted. This took 1-2 minutes on my >3 year old laptop. Siggi > version _ platform i686-redhat-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor0.0 year 2004 month10 day 04 language R Yeah, I know, an update is (over)due. -- - Sigurður Þór Jónsson / Sigurdur Tor Jonsson E-mail: <[EMAIL PROTECTED]> Snail-mail: Marine Research Institute, P.O. Box 1390, 121 Reykjavik,Iceland Telephone (direct line): +354 5752093 Telephone (switchboard): +354 5752000 Fax: +354 5752001 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to merge two strings
Claus Hindsgaul wrote: >Hi r-help, > >A very simple question for which I have not been able to find an answer >in the docs: > > How can I merge two character strings? > >I am searching for the equivalent of the (non-existing) stringmerge >function illustrated below: > > > >>s1 <- "R-" >>s2 <- "project" >>stringmerge(s1,s2) >> >> >[1] "R-project" > > > >Claus > > > paste(s1, s2, sep = "") HTH, Tobias __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to merge two strings
On 8/16/05 7:01 AM, "Claus Hindsgaul" <[EMAIL PROTECTED]> wrote: > Hi r-help, > > A very simple question for which I have not been able to find an answer > in the docs: > > How can I merge two character strings? > > I am searching for the equivalent of the (non-existing) stringmerge > function illustrated below: > >> s1 <- "R-" >> s2 <- "project" >> stringmerge(s1,s2) > [1] "R-project" See ?paste. Sean __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Re-sort list of vectors
Dear list members, thank all of you for replying to my question. Finally I came up with 3 working solutions, which I ask you to rank now in terms of used resources, computation speed, "design questions" etc. x <- list("1" = c(a = 1, b = 2, c = 3), "2" = c(d = 4, b = 5, e = 6)) #looping; Thanks to Jim Holtman solution1<-function(x){ Result <- list() for (i in names(x)){ for (j in names(x[[i]])){ Result[[j]][[i]] <- x[[i]][[j]] } } return(Result) } #lapplying function within function; derived from Solution1 solution2<-function(x){ temporaryList <- list() lapply(names(x),function(y){lapply(names(x[[y]]),function(z){temporaryLi st[[z]][[y]]<<-x[[y]][[z]]})}) return(temporaryList) } #vectorized; Thanks to Dimitris Rizopoulos solution3<-function(x){ y <- data.frame(name = rep(names(x), sapply(x, length)), value = unlist(x)) lapply(split(y, unlist(lapply(x, names))), function(z){ res <- z$value; names(res) <- z$name; return(res) }) } I would prefer solution2(), because ... I don't know. Thanks in advance! Jan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to merge two strings
look at ?paste(), e.g., s1 <- "R-" s2 <- "project" paste(s1, s2, sep = "") Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: "Claus Hindsgaul" <[EMAIL PROTECTED]> To: Sent: Tuesday, August 16, 2005 1:01 PM Subject: [R] How to merge two strings > Hi r-help, > > A very simple question for which I have not been able to find an > answer > in the docs: > > How can I merge two character strings? > > I am searching for the equivalent of the (non-existing) stringmerge > function illustrated below: > >> s1 <- "R-" >> s2 <- "project" >> stringmerge(s1,s2) > [1] "R-project" >> > > Claus > > -- > Ph.D. Student Claus Hindsgaul > CHEC, Dept. Chemical Eng. (KT), DTU > and Biomass Gasification Group, Dept. Mechanical Eng. (MEK), DTU > DTU Building 229 room 154, Phone +45 4525 2838 > http://bgg.mek.dtu.dk/ and http://www.kt.dtu.dk/ > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] How to merge two strings
Hi r-help, A very simple question for which I have not been able to find an answer in the docs: How can I merge two character strings? I am searching for the equivalent of the (non-existing) stringmerge function illustrated below: > s1 <- "R-" > s2 <- "project" > stringmerge(s1,s2) [1] "R-project" > Claus -- Ph.D. Student Claus Hindsgaul CHEC, Dept. Chemical Eng. (KT), DTU and Biomass Gasification Group, Dept. Mechanical Eng. (MEK), DTU DTU Building 229 room 154, Phone +45 4525 2838 http://bgg.mek.dtu.dk/ and http://www.kt.dtu.dk/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Vector comparison to matrix
Hi Todd and list, I see you have received a few suggestions, here's another: # set up data: your vector and an a 3x30 matrix with a few # matching lines: target<-c(1,2,3) A<-matrix(sample(1:3,30,replace=TRUE),ncol=3) # count matches: nMatches<-sum(apply(A,1,function(x,target) all.equal(x,target),target)=="TRUE") # by applying a simple function, which takes 'target' as an 'extra' # argument, to the rows of A. The function returns a vector of # differences and 'TRUE'-s, the latter of which can be counted. This took 1-2 minutes on my >3 year old laptop. Siggi > version _ platform i686-redhat-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major2 minor0.0 year 2004 month10 day 04 language R Yeah, I know, an update is (over)due. -- - Sigurður Þór Jónsson/ Sigurdur Tor Jonsson E-mail: <[EMAIL PROTECTED]> Snail-mail: Marine Research Institute, P.O. Box 1390, 121 Reykjavik,Iceland Telephone (direct line):+354 5752093 Telephone (switchboard):+354 5752000 Fax:+354 5752001 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R CMD check failure on minimal code
On 8/15/05 5:19 PM, "Prof Brian Ripley" <[EMAIL PROTECTED]> wrote: > Did you remember to declare a dependency on package 'methods'? I suspect > not. Please see `Writing R Extensions'. As usual, Professor Ripley, you are correct Thanks, Sean __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Re-sort list of vectors
maybe something like this can be helpful: x <- list("1" = c(a = 1, b = 2, c = 3), "2" = c(d = 4, b = 5, e = 6)) y <- data.frame(nam = rep(names(x), sapply(x, length)), val = unlist(x)) lapply(split(y, unlist(lapply(x, names))), function(x){ res <- x$val; names(res) <- x$nam; res }) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: "Jan Hummel" <[EMAIL PROTECTED]> To: Sent: Monday, August 15, 2005 7:09 PM Subject: Re: [R] Re-sort list of vectors Thanks a lot! But unfortunately I will not know the dimensions of both lists. And further, the lists may be (partly) disjoint as: x <- list("1"=c(a=1, b=2, c=3), "2"=c(d=4, b=5, e=6)). And last but not least I'm really have to have access to the names of the named list items. The problem I dealt with is in unlist() merging the names together, as you can see in your example given: "V1", "V2" and "V3". Because off interpreting the names later as identifiers in db queries I'm really interested in getting something like list("a"=c("1"=1), "b"=c("1"=2, "2"=5), "c"=c("1"=3), "d"=c("1"=4), "e"=c("1"=6)) for the above input. By giving the result this way I'm able to extract both names from two sets as well as the according value between both items. One point could be to build a matrix but this matrix would have many NA's. So I prefer Lists of Lists. Any ideas? cheers Jan -Ursprüngliche Nachricht- Von: Liaw, Andy [mailto:[EMAIL PROTECTED] Gesendet: Montag, 15. August 2005 17:31 An: Jan Hummel; r-help@stat.math.ethz.ch Betreff: RE: [R] Re-sort list of vectors If all vectors in the list have the same length, why not use a matrix? Then you'd just transpose the matrix if you need to. If you really have to have it as a list, here's one possibility: > x <- list("1"=c(a=1, b=2, c=3), "2"=c(a=4, b=5, c=6)) x $"1" a b c 1 2 3 $"2" a b c 4 5 6 > as.list(as.data.frame(t(matrix(unlist(x), nrow=3 $V1 [1] 1 4 $V2 [1] 2 5 $V3 [1] 3 6 Andy > From: Jan Hummel > > Hi. > Can anyone suggest a simple way to re-sort in R a list of vectors of > the following form? > > input > $"1" > a b c > 1 2 3 > $"2" > a b c > 4 5 6 > > Output should be something like: > "a" > "1" 1 > "2" 4 > "b" > "1" 2 > "2" 5 > "c" > "1" 3 > "2" 6 > > I've been futzing with mapply(), outer(), split(), rbind() and so on > but haven't found an elegant solution. > > Thanks, > Jan. > > P.S. E-mailed CCs of posted replies appreciated. > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict nbinomial glm
Dear R-helpers, let us assume, that I have the following dataset: a <- rnbinom(200, 1, 0.5) b <- (1:200) c <- (30:229) d <- rep(c("q", "r", "s", "t"), rep(50,4)) data_frame <- data.frame(a,b,c,d) In a first step I run a glm.nb (full code is given at the end of this mail) and want to predict my response variable a. In a second step, I would like to run a glm.nb based on a subset of the data_frame. As soon as I want to predict the response variable a, I get the following error message: "Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor d has new level(s) q" Does anybody have a solution to this problem? Thank you in advance, K. Steinmann (working with R 2.0.0) Code: library(MASS) a <- rnbinom(200, 1, 0.5) b <- (1:200) c <- (30:229) d <- rep(c("q", "r", "s", "t"), rep(50,4)) data_frame <- data.frame(a,b,c,d) model_1 = glm.nb(a ~ b + d , data = data_frame) pred_model_1 = predict(model_1, newdata = data_frame, type = "response", se.fit = FALSE, dispersion = NULL, terms = NULL) subset_of_dataframe = subset(data_frame, (b > 80 & c < 190 )) model_2 = glm.nb(a ~ b + d , data = subset_of_dataframe) pred_model_2 = predict(model_2, newdata = subset_of_dataframe, type = "response", se.fit = FALSE, dispersion = NULL, terms = NULL) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Fwd: Documenting data sets with many variables
Hi, since nobody answered to my first message, I try to explain my problem more clearly and more general this time: I have a data set in my R package "micEcon", which has many variables (82). Therefore, I would like to avoid to describe all variables in the "\format" section of the documentation (.Rd file). However, doing this lets "R CMD check" complain about "data codoc mismatches" (details see below). Is there a way to avoid the description of all variables without getting a complaint from "R CMD check"? Thanks, Arne -- Forwarded Message -- Subject: Documenting data sets with many variables Date: Friday 05 August 2005 14:03 From: Arne Henningsen <[EMAIL PROTECTED]> To: R-help@stat.math.ethz.ch Hi, I extended the data set "Blanciforti86" that is included in my R package "micEcon". For instance, I added consumer prices, annual consumption expenditures and expenditure shares of eleven aggregate commodity groups. The corresponding variables in the data frame are called "pAgg1", "pAgg2", ..., "pAgg11", "xAgg1", "xAgg2", ..., "xAgg11", "wAgg1", "wAgg2", ..., "wAgg11". To avoid to describe all 33 items in the "\format" section of the documentation (.Rd file) I wrote something like \format{ This data frame contains the following columns: \describe{ [ . . . ] \item{xAggX}{Expenditure on the aggregate commodity group X (in Millions of US-Dollars).} \item{pAggX}{Price index for the aggregate commodity group X (1972 = 100).} \item{wAggX}{Expenditure share of the aggregate commodity group X.} [ . . . ] } } and explained the 11 aggregate commodity groups only once in a different section (1=food, 2=clothing, ... ). However, "R CMD check" now complains about "data codoc mismatches", e.g. Code: [...] pAgg1pAgg2 pAgg3 [...] Docs: [...] pAggX [...] Is there a way to avoid the description of all 33 items without getting a complaint from "R CMD check"? Thanks, Arne --- -- Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 [EMAIL PROTECTED] http://www.uni-kiel.de/agrarpol/ahenningsen/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to repeat code snippet for several variables in a data frame?
Thanks for the very useful tips! Now I have enough round and square bracket and other tricks to wrap up the function! The double square bracket trick in test[[varname]] is golden! Thanks again, Sander. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Conditional Matrices
#M1 = first matrix #M2 = second matrix M2[M1==0]<-NA - Original Message - From: "ISAIAH SHALWITZ" <[EMAIL PROTECTED]> To: Sent: Tuesday, August 16, 2005 5:00 AM Subject: [R] Conditional Matrices > This seems like a simple problem but I can't figure it out: > > I have two identical DIMENSION matrices. Both contain only binary values > NOT identical between matrices. What I want to do: If in cell (1,1) the > value in the first matrix (x) equals 1, then I keep the value in cell > (1,1) in the second matrix (y). If in cell (1,1) the value in the first > matrix (x) equals 0, then I change the value in cell (1,1) in the second > matrix (y)to missing (NA). Repeat for every pair of cells (coordinates of > the paired cells always match). > > Please help. > > I > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Conditional Matrices
On 16-Aug-05 ISAIAH SHALWITZ wrote: > This seems like a simple problem but I can't figure it out: > > I have two identical DIMENSION matrices. Both contain only binary > values NOT identical between matrices. What I want to do: If in cell > (1,1) the value in the first matrix (x) equals 1, then I keep the value > in cell (1,1) in the second matrix (y). If in cell (1,1) the value in > the first matrix (x) equals 0, then I change the value in cell (1,1) in > the second matrix (y)to missing (NA). Repeat for every pair of cells > (coordinates of the paired cells always match). > > Please help. It seems the following is what you are looking for: A<-matrix(c(1,0,1,0,1,1,1,1,1),nrow=3) A # [,1] [,2] [,3] # [1,]101 # [2,]011 # [3,]111 B<-matrix(c(1,2,3,4,5,6,7,8,9),nrow=3) B # [,1] [,2] [,3] # [1,]147 # [2,]258 # [3,]369 B[A==0]<-NA B # [,1] [,2] [,3] # [1,]1 NA7 # [2,] NA58 # [3,]369 Best wishes, Ted. E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 16-Aug-05 Time: 09:08:25 -- XFMail -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Conditional Matrices
ifelse(mat1, mat2, NA) should do what you want. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") ISAIAH SHALWITZ wrote: >This seems like a simple problem but I can't figure it out: > >I have two identical DIMENSION matrices. Both contain only binary values NOT >identical between matrices. What I want to do: If in cell (1,1) the value in >the first matrix (x) equals 1, then I keep the value in cell (1,1) in the >second matrix (y). If in cell (1,1) the value in the first matrix (x) equals >0, then I change the value in cell (1,1) in the second matrix (y)to missing >(NA). Repeat for every pair of cells (coordinates of the paired cells always >match). > >Please help. > >I > >__ >R-help@stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to get a list work in RData file
you know about ?history Sean On 16/08/05, Liaw, Andy <[EMAIL PROTECTED]> wrote: > If you want to keep track of the function call that produced an object, > usually you need to do that inside the function that's being called, e.g., > > > test.xy <- function(x,y) { > + xy <- x+y > + attr(xy, "Call") <- match.call() > + xy > + } > > xyadd <- test.xy(x=2, y=3) > > xyadd > [1] 5 > attr(,"Call") > test.xy(x = 2, y = 3) > > str(xyadd) > atomic [1:1] 5 > - attr(*, "Call")= language test.xy(x = 2, y = 3) > > > Andy > > > From: Xiyan Lon > > > > Dear R-Helper, > > I want to know how I get a list work which I saved in RData > > file. For > > example, > > > > > test.xy <- function(x,y) { > > +xy <- x+y > > +xy > > + } > > > > > > xyadd <- test.xy(x=2, y=3) > > > xyadd > > [1] 5 > > > x1 <- c(2,43,60,8) > > > y1 <- c(91,7,5,30) > > > > > > xyadd1 <- test.xy(x=x1, y=y1) > > > xyadd1 > > [1] 93 50 65 38 > > > save(list = ls(all=TRUE), file = "testxy.RData") > > > rm(list=ls(all=TRUE)) > > > load("C:/R/useR/testxy.RData") > > > ls() > > [1] "test.xy" "x1" "xyadd" "xyadd1" "y1" > > > > > > ls.str(pat="xyadd") > > xyadd : num 5 > > xyadd1 : num [1:4] 93 50 65 38 > > > > > > > When I run, I know the result like above > > > xyadd > > [1] 5 > > > xyadd1 > > [1] 93 50 65 38 > > > > > what I want to know, is there any function to make the result like: > > > > > xyadd > > > > test.xy(x=2, y=3) > > > > and > > > > > xyadd1 > > > > test.xy(x=x1, y=y1) > > > > Best, > > Xiyan Lon > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Image from bytes streams
The R graphics is not sent to the standard output of the R process, which you assume when you try to "capture" it via your Java 'input' stream. Simple illustration: C:\>echo plot(1) | R --quiet --no-save > plot(1) > C:\> So where did the graphics go then? If you "batch" run R commands like this, all graphical output is written to (one) default postscript file "Rplots.ps"; that's the file you want to read. I bet you have a two page Rplots.ps file for your pie and scatter plot. If you do not want postscript, but other formats, you have to generate you image files explicitly, e.g. png("image.png", width=640, height=480) plot(1) dev.off() Make sure you understand how R works before you try to call it from Java; there is nothing magic going on if you understand it. Cheers Henrik Bengtsson Márcio de Medeiros Ribeiro wrote: > Hello! > > I'm trying to get an array of bytes from graphic images generated by > R. Here, you can see my Java code: > > -- > Process p = Runtime.getRuntime().exec("C:/Arquivos de > programas/R/rw1090/bin/Rterm.exe --no-save"); > > DataOutputStream output = new DataOutputStream(new > BufferedOutputStream(p.getOutputStream())); > > DataInputStream input = new DataInputStream(new > BufferedInputStream(p.getInputStream())); > > // output.writeBytes("pie(c(50,30,20))"); //Pie graphic > output.writeBytes("plot(1,1)"); // Plot graphic > output.flush(); > > input.readFully(new byte[200]); // Here I read the "image" bytes. > -- > > That's the problem: when I use Pie graphic, I got some bytes. However, > when I use the Plot graphic, I got the same bytes! So, I suppose that > my program does not read the bytes from the generated graphic from R. > > Is it possible to get the bytes from the generated graphic? How can I > get these bytes? > > Sorry about my english. I'm brazilian! :) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] data manipulation help
roberto munguia posgrado.ecologia.edu.mx> writes: > > I have a dataframe with 468 individuals (rows) that I captured at least once > during 28 visits (columns), it looks like: > > mortality[1:10,] > > > 11 0 0 0 1 1 > 1 0 0 0 .. > so I can know how many times every individual was captured, 0= not capture, > 1=capture. > I also want to know when was the first and the last capture for every > individual, This should give you a starter # create play data cap = data.frame(matrix(rbinom(120,1,0.3),nrow=10)) firstthat<-function(x) which(x)[1] # stolen from Thomas Lumley # Make your data logical; not really needed, but easier to understand cap.log = cap==1 apply(cap.log,1,firstthat) # gives first captures Dieter __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] missing sh.exe file when running "R CMD INSTALL test"
Chin Chieh wrote: > I am trying to learn how to make a simple package that contains no C > or Fortran code. I used package.skeleton(...) to make a package > called "test". The directory and files look good. I downloaded and > installed Rtools (www.murdoch-sutherland.com/Rtools/tools.zip). I > added the path and from the dos prompt I can verify that make.exe and > sh.exe both exist, but when I try to run "R CMD INSTALL test" I get an > error "make: sh.exe: Command not found" and "make: *** [pkg-test] > Error 127". I get the same error message if a try the command "make > pkg-test". Are you sure it is really in the path of the shell from which you are executing R CMD? I think this is not the case. Try typing sh.exe therein directly ... Uwe Ligges > I saw in an old FAQ a suggestion to move sh.eve to the C:\bin\ folder, > but my C: root does not have a "bin" folder. Nonetheless, I created > one and put sh.exe there and it provided no help (I didn't expect it > too). > > Can anyone help me? > > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] missing sh.exe file when running "R CMD INSTALL test"
I am trying to learn how to make a simple package that contains no C or Fortran code. I used package.skeleton(...) to make a package called "test". The directory and files look good. I downloaded and installed Rtools (www.murdoch-sutherland.com/Rtools/tools.zip). I added the path and from the dos prompt I can verify that make.exe and sh.exe both exist, but when I try to run "R CMD INSTALL test" I get an error "make: sh.exe: Command not found" and "make: *** [pkg-test] Error 127". I get the same error message if a try the command "make pkg-test". I saw in an old FAQ a suggestion to move sh.eve to the C:\bin\ folder, but my C: root does not have a "bin" folder. Nonetheless, I created one and put sh.exe there and it provided no help (I didn't expect it too). Can anyone help me? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] merge warning is.na(out$h)
That error/warning is not from merge() (it does not contain that code, nor do the standard R packages). options(warn=2) and traceback() will show you where it is coming from. Note that you have an error during printing the warning, which suggests there is more wrong than you have seen. Please provide a reproducible example, or at least str(data1) and str(data2). (Your final comment suggests it is data1 that is unusual.) On Mon, 15 Aug 2005, Fulton, Brent wrote: > Does anyone know how to interpret this merge warning and whether it's > critical to fix? The merge seemed to work fine, but I am concerned. > > data3<-merge(data1, data2, by="ID", all=TRUE) > > Warning messages: 1: is.na() applied to non-(list or vector) in: > is.na(out$h) Error in cat(list(...), file, sep, fill, labels, append) : > argument 2 not yet handled by cat > > When I remove all=TRUE or just include all.y=TRUE, I don't get the > warning; however, I get the warning when I include all.x=TRUE. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html