[R] Rounding?
I was a bit puzzed by: > formatC(6.65,format="f",digits=1) [1] "6.6" So I experimented and found: > formatC(6.6501,format="f",digits=1) [1] "6.6" > formatC(6.651,format="f",digits=1) [1] "6.7" > round(6.6501,1) [1] 6.7 > round(6.651,1) [1] 6.7 > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 5.0 year 2007 month 04 day23 svn rev41293 language R version.string R version 2.5.0 (2007-04-23) My machine runs Windows NT. Is this intended or just a Windows facility? __ Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2-4 DK-2820 Gentofte Denmark +45 44 43 87 38 (direct) +45 30 75 87 38 (mobile) +45 44 43 73 13 (fax) [EMAIL PROTECTED] http://www.biostat.ku.dk/~bxc This e-mail (including any attachments) is intended for the ...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Compilation of source package.
I have a samll package that works well and complies nicly on WinXP, using R-2.4.1 Now I want to add a document so i make a folder inst\doc and put the .tex and .pdf in there. But the complation then crashes. Is this because the installin expects some file to be present in inst if an inst folder is there? This is how the thing progress is on my command promp: ___ C:\Stat\R\BxC\library.sources>c:\stat\r\R-2.4.1\bin\Rcmd check MethComp * checking for working latex ... OK * using log directory 'C:/Stat/R/BxC/library.sources/MethComp.Rcheck' * using R version 2.4.1 (2006-12-18) * checking for file 'MethComp/DESCRIPTION' ... OK * this is package 'MethComp' version '0.0.8' * checking package dependencies ... OK * checking if this is a source package ... OK * checking whether package 'MethComp' can be installed ... ERROR Installation failed. See 'C:/Stat/R/BxC/library.sources/MethComp.Rcheck/00install.out' for details. C:\Stat\R\BxC\library.sources>more MethComp.Rcheck\00install.out installing R.css in C:/Stat/R/BxC/library.sources/MethComp.Rcheck -- Making package MethComp adding build stamp to DESCRIPTION installing R files installing inst files FIND: Parameter format not correct make[2]: *** [C:/Stat/R/BxC/library.sources/MethComp.Rcheck/MethComp/inst] Error 2 make[1]: *** [all] Error 2 make: *** [pkg-MethComp] Error 2 *** Installation of MethComp failed *** Removing 'C:/Stat/R/BxC/library.sources/MethComp.Rcheck/MethComp' ___ Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2-4 DK-2820 Gentofte Denmark +45 44 43 87 38 (direct) +45 30 75 87 38 (mobile) +45 44 43 73 13 (fax) [EMAIL PROTECTED] http://www.biostat.ku.dk/~bxc __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to join two arrays using their column names intersection
Here is a workable solution: df1 <- data.frame(ar1) df2 <- data.frame(ar2) cmn <- intersect(names(df1),names(df2)) rbind(df1[,cmn],df2[,cmn]) Best Bendix __ Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2-4 DK-2820 Gentofte Denmark +45 44 43 87 38 (direct) +45 30 75 87 38 (mobile) +45 44 43 73 13 (fax) [EMAIL PROTECTED] http://www.biostat.ku.dk/~bxc __ > -Original Message- > From: Federico Abascal [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 30, 2007 12:28 PM > To: r-help@stat.math.ethz.ch > Subject: [R] how to join two arrays using their column names > intersection > > Dear all, > > I have a problem that may be someone of you can help. I am a > newbie and do not find how to do it in manuals. > > I have two arrays, for example: > > ar1 <- array(data=c(1:16),dim=c(4,4)) > ar2 <- array(data=c(1:16),dim=c(4,4)) > colnames(ar1)<-c("A","B","D","E") > colnames(ar2)<-c("C","A","E","B") > > > ar1 > A B D E > [1,] 1 5 9 13 > [2,] 2 6 10 14 > [3,] 3 7 11 15 > [4,] 4 8 12 16 > > ar2 > C A E B > [1,] 1 5 9 13 > [2,] 2 6 10 14 > [3,] 3 7 11 15 > [4,] 4 8 12 16 > > > I would like to join both arrays only for the columns present in both > ar1 and ar2 (the intersection). I would like to obtain this: > A B E > [1,] 1 5 13 > [2,] 2 6 14 > [3,] 3 7 15 > [4,] 4 8 16 > [5,] 5 13 9 > [6,] 6 14 10 > [7,] 7 15 11 > [8,] 8 16 12 > > (rows 5-8 correspond to ar2) > > I have tried several things but I am unable to accomplish it. > Any experienced user could give me some advice, please? > > I have another question: how can I sort the columns of an > array according to its column names (for ar2, change CAEB to ABCE)? > > Thanks in advance! > Federico > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dimensions of a all objects
Generally it is difficult to get an overview of what's there. But the following function I acquired from (???) ages ago does a nice job: lls <- function (pos = 1, pat = "") { dimx <- function(dd) if (is.null(dim(dd))) length(dd) else dim(dd) lll <- ls(pos = pos, pat = pat) cat(formatC("mode", 1, 15), formatC("class", 1, 18), formatC("name", 1, max(nchar(lll)) + 1), " size\n---\n") if (length(lll) > 0) { for (i in 1:length(lll)) { cat(formatC(eval(parse(t = paste("mode(", lll[i], ")"))), 1, 15), formatC(paste(eval(parse(t = paste("class(", lll[i], ")"))), collapse = " "), 1, 18), formatC(lll[i], 1, max(nchar(lll)) + 1), " ", eval(parse(t = paste("dimx(", lll[i], ")"))), "\n") } } } Just say lls() and you get a reasnoable listing of obejcts. Best, Bendix __ Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2-4 DK-2820 Gentofte Denmark +45 44 43 87 38 (direct) +45 30 75 87 38 (mobile) +45 44 43 73 13 (fax) [EMAIL PROTECTED] http://www.biostat.ku.dk/~bxc __ > -Original Message- > From: Farrel Buchinsky [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 09, 2007 3:30 PM > To: r-help@stat.math.ethz.ch > Subject: [R] dimensions of a all objects > > Why will the following command not work > sapply(objects(),dim) > What does it say about the objects list? What does it say > about the dim command? > > Likewise, the following also does not work > all<-ls() > for (f in all) print(dim(f)) > -- > Farrel Buchinsky > > [[alternative HTML version deleted]] > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Course announcement: STATISTICAL PRACTICE IN EPIDEMIOLOGY USING R
Course in STATISTICAL PRACTICE IN EPIDEMIOLOGY USING R Tartu, Estonia, 25 to 30 May 2007 The course is aimed at epidemiologists and statisticians who wish to use R for statistical modelling and analysis of epidemiological data. The course requires basic knowledge of epidemiological concepts and study types. These will only be briefly reviewed, whereas the more advanced epidemiological and statistical concepts will be treated in depth. Contents: - * History of R. Language. Objects. Functions. * Interface to other dataformats. Dataframes. * Graphical methods for exploring data. * Classical methods and tabulation of data. * Logistic regression for case-control-studies. * Poisson regression for follow-up studies. * Parametrization of models. * Graphics in R. * Graphical reporting of results. * Causal inference. * Time-splitting & SMR. * Survival analysis in continuous time. * Interval censoring. * Nested and matched case-control studies. * Case-cohort studies. * Competing risk models. * Multistage models. * Bootstrap and simulation The methods will be illustrated using R in practical exercises. The Epi package which is under development for epidemiological analysis in R will be introduced. Participants are required to have a fairly good understanding of statistical principles and some familiarity with epidemiological concepts. The course will be mainly practically oriented with more than half the time at the computer. Price: 600 EUR. (300 EUR for countries outside EU-2003 and the like). Application: Deadline 1st April 2007. Send and e-mail which briefly states your qualifications in epidemiology and statistics, to the organizers Krista Fischer, Esa Läärä & Bendix Carstensen. Further information at: www.pubhealth.ku.dk/~bxc/SPE --- Organizers: Krista Fischer, University of Tartu, Estonia <[EMAIL PROTECTED]> Esa Läärä, University of Oulu, Finland <[EMAIL PROTECTED]> Bendix Carstensen, Steno Diabetes Center, Denmark <[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 and provide commented, minimal, self-contained, reproducible code.
[R] How to extract the variance componets from lme
Here is a piece of code fitting a model to a (part) of a dataset, just for illustration. I can extract the random interaction and the residual variance in group meth==1 using VarCorr, but how do I get the other residual variance? Is there any way to get the other variances in numerical form directly - it seems a litte contraintuitive to use "as.numeric" when extracting estimates, it's a bit like good old days writing SAS-programs that reads the SAS output files... Bendix --- library( nlme ) dfr <- structure(list(meth = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), .Label = c("CO", "pulse"), class = "factor"), item = c(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4), repl = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3), y = c(78, 76.4, 77.2, 68.7, 67.6, 68.3, 82.9, 80.1, 80.7, 62.3, 65.8, 67.5, 71, 72, 73, 68, 67, 68, 82, 77, 77, 43, 69, 77)), .Names = c("meth", "item", "repl", "y"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "184", "185", "186", "187", "188", "189", "190", "191", "192", "193", "194", "195"), class = "data.frame") m1 <- lme( y ~ factor( meth ) + factor( item ), random = ~1 | MI, weights = varIdent( form = ~1 | meth ), method ="REML", data = cbind( dfr, MI=interaction( dfr$meth, dfr$item ) ) ) m1 # The MI std and the residual std for meth==1 as.numeric(VarCorr(m1)[,2]) __ Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2-4 DK-2820 Gentofte Denmark +45 44 43 87 38 (direct) +45 30 75 87 38 (mobile) +45 44 43 73 13 (fax) [EMAIL PROTECTED] http://www.biostat.ku.dk/~bxc __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data frames questions
> -Original Message- > From: X.H Chen [mailto:[EMAIL PROTECTED] > Sent: Sunday, September 24, 2006 12:16 AM > To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch > Subject: Re: [R] Data frames questions > > > >1) Is there a way to build an empty data frame, containing > nothing but > >the data frame variable names? > > Yes, you can do it one way as followings: > > df1<-as.data.frame(matrix(nrow=2,ncol=2),row.names=c("R1","R2")) This results in a dataframe with two rows and two columns NA in it. In order to build an empty dataframe one you could use: df1 <- data.frame( X1=1, x2=3, l1=TRUE, d3=as.Date("2003-07-14") )[NULL,] str( df1 ) The key is the "NULL" for the rows, it removes the data but keeps the content. Best, Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- (snip) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] zero.print in print.table after adding margins
The function addmargins() adds margins to a table, but returns a matrix. But even after converted to a table the print.zero="." option of print.table() does not work: > x <- sample( 1:7, 20, replace=T ) > y <- sample( 1:7, 20, replace=T ) > tt <- table( x, y ) > tx <- as.table( addmargins( table( x, y ) ) ) > print( tt, zero.print="." ) y x 1 2 3 4 5 6 7 1 1 2 2 . . 1 . 2 1 . . 1 . . . 3 . . . . . . 2 4 1 . . . . 1 . 5 1 . 1 . . 1 . 6 . 1 . 1 . . . 7 . . 1 . 1 1 . > print( tx, zero.print="." ) y x 1 2 3 4 5 6 7 Sum 11 2 2 0 0 1 0 6 21 0 0 1 0 0 0 2 30 0 0 0 0 0 2 2 41 0 0 0 0 1 0 2 51 0 1 0 0 1 0 3 60 1 0 1 0 0 0 2 70 0 1 0 1 1 0 3 Sum 4 3 4 2 1 4 2 20 Is this a facility of print.table? The attributes() of tt and tx have identical stucture. Best, Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ 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 reminder: Statistical practise in Epidemiology with R
STATISTICAL PRACTICE IN EPIDEMIOLOGY USING R Tartu, Estonia, Thursday 8 - Tuesday 13 June 2006 Application deadline: 15 April 2006. The course is aimed at epidemiologists and statisticians who wish to use R for statistical modelling and analysis of epidemiological data. The course requires basic knowledge of epidemiological concepts and study types. These will only be briefly reviewed, whereas more advanced epidemiological and statistical concepts will be treated in depth. The methods will be illustrated using R in practical exercises. The Epi package for epidemiological analysis in R will be introduced. Participants are required to have a fairly good understanding of statistical principles and some familiarity with epidemiological concepts. The course will be mainly practically oriented with more than half the time at the computer. Price: 500 EUR. (250 EUR for countries outside EU-2003 and the like). Further information at: www.biostat.ku.dk/~bxc/SPE -- Krista Fischer, University of Tartu, Estonia Esa Läärä, University of Oulu, Finland Bendix Carstensen, Steno Diabetes Center, Denmark Organizers __ 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 in Statistical Practise in Epidemiology using R
Course in STATISTICAL PRACTICE IN EPIDEMIOLOGY USING R Tartu, Estonia, Thursday 8 - Tuesday 13 June 2006 The course is aimed at epidemiologists and statisticians who wish to use R for statistical modelling and analysis of epidemiological data. The course requires basic knowledge of epidemiological concepts and study types. These will only be briefly reviewed, whereas the more advanced epidemiological and statistical concepts will be treated in depth. Contents: - History of R. Language. Objects. Functions. Interface to other dataformats. Dataframes. Classical methods: Mantel-Haenszel etc. Tabulation of data. Logistic regression for case-control-studies. Poisson regression for follow-up studies. Parametrization of models. Causal inference. Graphics in R. Graphical reporting of results. Time-splitting & SMR. Survival analysis in continuous time. Parametric survival models. Interval censoring. Nested and matched case-control studies. Case-cohort studies. Competing risk models. Multistage models. Bootstrap and simulation. The methods will be illustrated using R in practical exercises. The Epi package for epidemiological analysis in R will be introduced. Participants are required to have a fairly good understanding of statistical principles and some familiarity with epidemiological concepts. The course will be mainly practically oriented with more than half the time at the computer. Price: 500 EUR. (250 EUR for cuntries outside EU-2003 and the like). Application deadline: 15 April 2006. Further information at: www.biostat.ku.dk/~bxc/SPE -- Krista Fischer, University of Tartu, Estonia Esa Läärä, University of Oulu, Finland Bendix Carstensen, Steno Diabetes Center, Denmark Organizers __ 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] [R-pkgs] Epi package
There is now an Epi-package on CRAN. It is intended for epidemiological analysis in R. It has its own homepage, http://www.pubhealth.ku.dk/~bxc/Epi The package has been used at the course "Statistical practise in Epidemiology with R", see http://www.pubhealth.ku.dk/~bxc/SPE. A mailing list for people using R for epidemiology, R-sig-Epi, has been set up, see https://stat.ethz.ch/mailman/listinfo/r-sig-epi or through the R-homepage -> Mailing lists Bendix Carstensen maintainer -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] assignment of inidividual variables from spss save files
The key to solving your problem is that read.spss per default gives you a *list* and not a *dataframe* (can anyone explain this choice of default?). So most likely wou want: children = read.spss(filename,to.data.frame=TRUE) attach(children) or to get things a little more handy: children <- read.spss(filename,to.data.frame=TRUE) names(children) <- tolower( names( children ) ) attach(children) best, Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: Romain Francois [mailto:[EMAIL PROTECTED] > Sent: Monday, June 13, 2005 9:48 AM > To: Mike Day; RHELP > Subject: Re: [R] assignment of inidividual variables from > spss save files > > > Le 13.06.2005 09:22, Mike Day a écrit : > > >New to R, can't afford SPSS! > > > >Why can't I assign spss variables? Here are the details. > > > > > ### I've read in my collaborator's sav file using read.spss, eg > > > children = read.spss(filename) ### It has many variables > > > length(children) > >[1] 347 > > > ### and I would like to assign individual variables. > > > ### I can of course type out all the ones I want, eg > > > ADULTS11<-children[18] ### But I'm lazy, so tried: > > > (function (x,n){assign(names(x[n]),x[n])})(children,2) > > > ### where > > > names(children[2]) > >[1] "ADNUTS06" > > > ### but > > > ADNUTS06 > >Error: Object "ADNUTS06" not found > > > ### I've tried lots of variations, including creating and ### > > > evaluating statements such as "ADNUTS06<-children[2]", ### but > > > without apparently yielding the required variable. > > > >I expect the answer will be "You shouldn't start from here!" Ideas > >welcome. > > > >Thanks, Mike > > > > > ?attach may be what you are looking for > > > -- > visit the R Graph Gallery : http://addictedtor.free.fr/graphiques > > ~ > ~~ Romain FRANCOIS - http://addictedtor.free.fr >~~ > Etudiant ISUP - CS3 - Industrie et Services > > ~~http://www.isup.cicrp.jussieu.fr/ >~~ > Stagiaire INRIA Futurs - Equipe SELECT > > ~~ http://www.inria.fr/recherche/equipes/select.fr.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] plots from batchfile on windows
Just open a device before you plot: pdf( "plotfile.pdf" ) plot( x, y ) dev.off() also have a look at: ?Devices Best Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Gabor > Grothendieck > Sent: Friday, June 03, 2005 4:33 PM > To: Hans-Peter > Cc: r-help@stat.math.ethz.ch > Subject: Re: [R] plots from batchfile on windows > > > On 6/3/05, Hans-Peter <[EMAIL PROTECTED]> wrote: > > Hi, > > > > On windows I'd like to run a batchfile that leaves me a plot. As a > > test I have the scriptfile "test.r" which only contains: > > > >x <- 1:10; > >y <- sample( 10 ) > >plot( x, y ) > > > > Now I tried the following (but nothing worked): > > > > a) "R --vanilla < test.r" in the cmd window, => that > doesn't give me a > > plot > > b) the same, but I added "bitmap(file="outplot.png")" in the > > scriptfile => Here I get an error that gswin32c.exe was not found. > > (Maybe I need to install ghostscript???) > > c) some attempts with Rgui.exe => I didn't arrive to pass a > command argument. > > > > It would be nice, to get some hints, how this could be done. I did > > search the newsgroup archive, but unfortunately didn't find > something. > > > > This was discussed previously this week. Look right at the end of: > https://www.stat.math.ethz.ch/pipermail/r-help/2005-June/071147.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] print format for difftime
Has anyone written a function that will print a difftime in the form: hh:mm:ss or yy-mm-dd hh:mm:ss depending on the actual size. (sloppy notation for months/minutes, but surely you get the point). Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ 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] Reading Numeric Data -- Trivial Question
You (and the mailing list) would defintely benefit from cliking on: Help -> Manuals -> An introduction to R and spend a few hours in frot of R while reading that. Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Alex K > Sent: Friday, May 20, 2005 11:26 PM > To: r-help@stat.math.ethz.ch > Subject: Re: [R] Reading Numeric Data -- Trivial Question > > > On 5/20/05, Uwe Ligges <[EMAIL PROTECTED]> wrote: > > Alex K wrote: > > > > > Hello, > > > > > >I am very new to R, and this is certainly and uber-newby > > > question: > > > > > >I am trying to read a vector of numeric data that contains the > > > log of daily DJI returns and simply plot a histogram of it. > > > > > >The data I have is in a text file format, on each line > a number > > > represents the log of the returns of one day. > > > > > >I have problems in reading this in a vector numeric format. > > > > > > If I try > > > > > > retr<- as.numeric(read.table("logDJI.TXT", header=FALSE, sep="", > > > dec="." )); > > > > > > read.table() returns a data.frame, as the docs point out, but > > as.numeric expects a vector. > > > > Either extract the first (and only?) column or read the data using > > scan(), if there is really only one column. > > > > Uwe Ligges > > Hi Uwe, thank you for the reply. > > How do I extract only the colum? > > The text file looks like: > "-0.000948343416257784 > 0.00181733586025109 > 0 > 0.0108130251220595" > > except is has about 2200 entries (numbers) instead of just > four as above. > > Thank you again, > Alex > > > > > > > > > > I get: > > > " Error in as.double.default(read.table("logDJIm.TXT", header = > > > FALSE, sep = "", : > > > (list) object cannot be coerced to 'double'" > > > > > > and when I try to plot: > > > > > > plot(density(retr, width=.004), type="l", xlab="y", ylab="pdf"); > > > > > > I get: > > > > > > "Error in density(retr, width = 0.004) : argument 'x' must be > > > numeric" > > > > > > If I try: > > > > > > retr<- as.data.frame(read.table("logDJI.TXT", > header=FALSE, sep="", > > > dec="." )); > > > > > > I get no reading or conversion error, but I get the same > error when > > > I try to plot as above. > > > > > > Can anyone help with this? > > > > > > Thank you in advance, > > > Alex > > > > > > __ > > > 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] Flip rows and columns of a table?
t( my.table ) -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Dan Bolser > Sent: Tuesday, April 26, 2005 11:18 AM > To: R mailing list > Subject: [R] Flip rows and columns of a table? > > > > Any simple way to take a (2D) table and 'rotate' it so all > the rows become columns and the columns rows? > > I'll wager there is a simple way ;) - but I can't find it :( > > __ > 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] Minimum distance
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Williams, Michael > Sent: Monday, April 18, 2005 1:58 AM > To: r-help@stat.math.ethz.ch > Subject: [R] Minimum distance > > > G'day, I have a matrix 2 x 500 populated with all the > distances between a list of airports and a list of towers. > What I'm having trouble doing is finding the closest airport > to each tower, Any help would be greatly appreciated. Try: ( M <- matrix( rnorm( 24 ), 8, 3 ) ) rownames( M ) <- 1:8 ( wh <- sweep( M, 2, apply( M, 2, min ), "==" ) ) rownames(M)[ row( wh )[wh] ] It works in finite time even with M of 2 by 500 but it breaks down if there is more than one minimum per column. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > > Regards, > Michael Williams > > > > [[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] averaging within columns
?tapply Bendix Carstensen > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of thomas hills > Sent: Saturday, February 26, 2005 6:17 PM > To: r-help@stat.math.ethz.ch > Subject: [R] averaging within columns > > > I have a dataframe with names in the first column and wait times > between decisions in the second column. Since individuals make > multiple decisions, I want the average for each individual. For > example, the data might look like this > > name wtime > jo1 > jo2 > jo1 > jo3 > tim 3 > tim 2 > tim 2 > ro1 > ro2 > etc. > > I'm hoping there is something like > > mean(dataname$wtime[name]) > > which will just create a column with length equal to the number of > different names (levels) and an average wtime for each. So > far though, > I haven't had much luck figuring that one out. > > Thanks. > Thomas > > __ > 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 do I get means by factor?
tapply( x, f, mean ) maybe with tapply( x, f, mean, na.rm=T ) -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Chris > Sent: Wednesday, February 23, 2005 10:38 PM > To: r-help@stat.math.ethz.ch > Subject: [R] how do I get means by factor? > > > I want the mean of a response variable for each level of a > factor in a data.frame. How is this done? > > [[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] What file did R read?
When I run in BATCH mode I use a script (win2000): c:\stat\r\%R_VERS%\bin\Rcmd BATCH -q --no-restore --no-save %1 Now I want to be able to print the filename of the program, i.e. the value if the %1 argument, in the .Rout file. (Basically I want to write a piece of code in .First() which prints date and time and program run, so I need to get to the value of %1. Currently I let the operating system print the value of %1 to a file, and then read the contents of this file. Clumsy, it works, but tricky to port to another machine.) The commandArgs() does NOT capture the name of the input file. Is it impossible to recover this filename from within R? Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ 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] save plot as jpg/gif
?Devices > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Liu, Jane > Sent: Monday, February 21, 2005 10:14 AM > To: RHELP > Subject: [R] save plot as jpg/gif > > > > I am generating multiple plots and would like to save them as > jpg or gif files. Could someone tell me which function I shall use? > > 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] Barplot - Can't figure it out
What you want is probably: > cxy <- c(x,y) > xy <- rep( c("x","y"), c(length(x),length(y)) ) > ( txy <- table(xy, cxy ) ) cxy xy 2 3 4 5 x 0 6 4 0 y 4 0 1 5 > barplot( txy, beside=T ) Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of T Petersen > Sent: Friday, February 18, 2005 1:01 PM > To: Petr Pikal > Cc: r-help@stat.math.ethz.ch > Subject: Re: [R] Barplot - Can't figure it out > > > Wow, I'm getting confused...The syntax Petr suggested does what I > wanted, but things are stille wrong...Maybe a bug? Let me explain. > > I got two vectors: > > x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4) > > y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2) > > then I do the barplot you suggest > > barplot(rbind(table(x), table(y)), beside=T) > > but things are wrong(there is no bar for catagory "3") and I > get an error message: Warning message: > number of columns of result > not a multiple of vector length (arg 1) in: > rbind(table(Quest1), table(Quest2)) > > Any ideas? __ 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 get interction terms first in a model
Consider the following two specifications of a model: library( splines ) x <- 1:100 y <- rnorm( 100 ) w <- rep( 1, 100 ) A <- factor( sample( 1:2, 100, replace=T ) ) B <- factor( sample( letters[1:4], 100, replace=T ) ) summary( lm( y ~ ns( x, knots=c(30, 50, 70 ), intercept=T ):A - 1 + B ) ) summary( lm( y ~ ns( x, knots=c(30, 50, 70 ), intercept=T ):A - 1 + B:w ) ) The interaction with the constant variable w is how I got to have the two spline terms as "proper" intercept terms. Is there another way to do this, or is it a featur of the model formulae that lower order terms appear before higher order terms regardless of the order they are specified in the model? Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ 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] GLM fitting
You have a perfect separtaion of y by x, i.e. y == (x>30) is true for all units. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Vito Ricci > Sent: Friday, January 28, 2005 11:14 AM > To: r-help@stat.math.ethz.ch > Subject: [R] GLM fitting > > > DeaR R-useRs, > > I'm trying to fit a logist model with these data: > > > dati >y x > 1 1 37 > 2 1 35 > 3 1 33 > 4 1 40 > 5 1 45 > 6 1 41 > 7 1 42 > 8 0 20 > 9 0 21 > 10 0 25 > 11 0 27 > 12 0 29 > 13 0 18 > > I use glm(), having this output: > > > g<-glm(y~x,family=binomial,data=dati) > Warning messages: > 1: Algorithm did not converge in: glm.fit(x = X, y = > Y, weights = weights, start = start, etastart = > etastart, > 2: fitted probabilities numerically 0 or 1 occurred > in: glm.fit(x = X, y = Y, weights = weights, start = > start, etastart = etastart, > > g > > Call: glm(formula = y ~ x, family = binomial, data = > dati) > > Coefficients: > (Intercept)x > -348.2311.23 > > Degrees of Freedom: 12 Total (i.e. Null); 11 Residual > Null Deviance: 17.94 > Residual Deviance: 7.011e-10AIC: 4 > > I don't understand the meaning of warning. Can anyone > help me? Many thanks. > Cheers, > Vito > > > = > Diventare costruttori di soluzioni > Became solutions' constructors > > "The business of the statistician is to catalyze > the scientific learning process." > George E. P. Box > > Top 10 reasons to become a Statistician > > 1. Deviation is considered normal > 2. We feel complete and sufficient > 3. We are 'mean' lovers > 4. Statisticians do it discretely and continuously > 5. We are right 95% of the time > 6. We can legally comment on someone's posterior distribution > 7. We may not be normal, but we are transformable > 8. We never have to say we are certain > 9. We are honestly significantly different > 10. No one wants our jobs > > > Visitate il portale http://www.modugno.it/ > e in particolare la sezione su Palese > http://www.modugno.it/archivio/palese/ > > > __ > 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] GLM function with poisson distribution
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Florian Menzel > Sent: Tuesday, January 25, 2005 3:22 PM > To: r-help@stat.math.ethz.ch; r-help@stat.math.ethz.ch > Subject: [R] GLM function with poisson distribution > > > Hello all, > I found a weird result of the GLM function that seems > to be a bug. > The code: > a=c(rep(1,8),rep(2,8)) > b=c(rep(0,8),rep(3,8)) > cbind(a,b) > model=glm(b~a, family=poisson) > summary(model) It' because one of the values of b is 0, hence the linear predictor for the corresponding level of a is -Inf, viz. the value -49 for the intercept, and the huge standard errors. Usual theory breaks down. Replace the 0s with 1s and you get something which is closer to what is covered by standard theory. Bendix Carstensen > generates a dataset with two groups. One group > consists entirely of zeros, the other of 3's (as > happened in a dataset I'm analyzing right now). Since > they are count data, one should apply a poisson > distribution. A GLM with poisson distribution delivers > a p value > 0.99, thus, completely fails to detect the > difference between the two groups. Why not and what should I > do to avoid this error? A quasipoisson distribution detects > the difference but I'm not sure whether it's appropriate to > use it. Thanks a lot to everybody who answers! >Florian > > Version information: > version 1.9.0 (2004-4-12) > os mingw32 > arch i386 > > __ > 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] COURSE: Statistical practice in Epidemiology with R
Course in STATISTICAL PRACTICE IN EPIDEMIOLOGY USING R Tartu, Estonia, 26 - 31 May 2005 The course is aimed at epidemiologists and statisticians who wish to use R for statistical modelling and analysis of epidemiological data. The course requires basic knowledge of epidemiological concepts and study types. These will only be briefly reviewed, whereas the more advanced epidemiological and statistical concepts will be treated in depth. Contents: - History of R. Language. Objects. Functions. Interface to other dataformats. Dataframes. Classical methods: Mantel-Haenszel etc. Tabulation of data. Logistic regression for case-control-studies. Poisson regression for follow-up studies. Parametrization of models. Graphics in R. Graphical reporting of results. Time-splitting & SMR. Survival analysis in continuous time. Parametric survival models. Interval censoring. Nested and matched case-control studies. Case-cohort studies. Competing risk models. Multistage models. Bootstrap and simulation. Causal inference. The methods will be illustrated using R in practical exercises. The Epi package which is under development for epidemiological analysis in R will be introduced. Participants are required to have a fairly good understanding of statistical principles and some familiarity with epidemiological concepts. The course will be mainly practically oriented with more than half the time at the computer. Price: 500 EUR. (250 EUR for cuntries outside EU-2003 and the like). Application deadline: 1 April 2005. Further information at: www.pubhealth.ku.dk/~bxc/SPE -- Krista Fischer, University of Tartu, Estonia Esa Läärä, University of Oulu, Finland Bendix Carstensen, Steno Diabetes Center, Denmark Organizers __ 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] glm and percentage data with many zero values
The ZIP model can be fitted with Jim Lindsey's function fmr from his gnlm library, see: http://popgen0146uns50.unimaas.nl/~jlindsey/rcode.html Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Gregor GORJANC > Sent: Friday, January 21, 2005 1:05 PM > To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch > Subject: RE: [R] glm and percentage data with many zero values > > > A hint. > > You might try with ZIP i.e. zero inflated poisson model. I > did not used it, > but I have such data to work on. So if there is anyone hwo > can point how to > do this in R - please. There is also a classs of ZINB or > something like > that for zero inflated negative binomial models. > > Actually I just went on web and found a book from Simonoff "Analyzing > Categorical Data" and there are some examples in it for ZIP > et al. Look > examples for sections 4.5 and 5.4 > http://www.stern.nyu.edu/~jsimonof/AnalCatData/Splus/analcatdata.s http://www.stern.nyu.edu/~jsimonof/AnalCatData/Splus/functions.s -- Lep pozdrav / With regards, Gregor GORJANC --- University of Ljubljana Biotechnical Faculty URI: http://www.bfro.uni-lj.si Zootechnical Departmentmail: gregor.gorjanc bfro.uni-lj.si Groblje 3 tel: +386 (0)1 72 17 861 SI-1230 Domzalefax: +386 (0)1 72 17 888 Slovenia __ 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] summing subsets of rows matrices
What you need is matrix multiplication: rbind( c(1,1,0,0,0,0), c(0,0,1,1,0,0), c(0,0,0,0,1,1) ) %*% M Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Stephen Nyangoma > Sent: Friday, January 14, 2005 10:18 AM > To: r-help@stat.math.ethz.ch > Subject: [R] summing subsets of rows matrices > > > I have a large data matrix (4460X3500) and I want to sum row > subsets in groups of 10 (bin). Is there an efficient way to > do this in R without using loops. Looping takes forever to > perform this task! > > For example suppose we have the matrix > > matrix(1:12,6,2) > [,1] [,2] > [1,]17 > [2,]28 > [3,]39 > [4,]4 10 > [5,]5 11 > [6,]6 12 > > my problem is to sdum for example: > 1. the first and second row > 2. the third and fourth > and > 3. the fifth and the sixth. > > To obtain > > [,1] [,2] > [1,]3 15 > [2,]7 19 > [3,] 11 23 > > > > Thank you. > [[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] coxph() and intervening events
Unless you have repeated events per person, you do not need to keep tack of which follow-up belongs to whom. The likelihood contribution from the two parts is a product. See any textbook on survival anlysis or p. 50 ff. of: http://staff.pubhealth.ku.dk/~bxc/Melbourne/Staff/foils.pdf or another of the zillion of survival/epidemiology lecture notes on the net. Best, Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Vegard Andersen > Sent: Thursday, January 13, 2005 12:52 PM > To: r-help@stat.math.ethz.ch > Subject: [R] coxph() and intervening events > > > Hello! > > I am using the coxph() function for counting process data. I want to > include an intervening event as one of my covariates. In > order to do this > I have split the relevant observations in my data at the time of > intervention. But I have not found any way to "inform" > coxph() of the id > of these observations. The result of this is that coxph() > interprets the > split data as extra observations, which is wrong. > Do anyone have a suggestion on how to specify the ID of subjects > experiencing intervening events? > Or maybe other solutions on how to perform a cox regression > including an > intervening event covariate? > > Thanks in advance! > > -- > Best regards, > Vegard Andersen > Institute of Community Medicine > University of Tromso > Tromso, Norway > > [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
RE: [R] hist function to give each cell equal area
how about: x <- rnorm(400) nbin<-7 hist(x,breaks=quantile(x,prob=seq(0,1,length=nbin+1))) Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Dan Bolser > Sent: Friday, January 07, 2005 11:21 AM > To: R mailing list > Subject: [R] hist function to give each cell equal area > > > > Hi, > > I want to use hist with non-equi-spaced breaks, picked such > that the fraction of the data points falling in the cells > (defined by 'breaks') is > roughly equal accross all cells. > > Is there such a function that will automatically try to > determine the breaks to fullfill this requirement? > > Something like.. > > hist( x, br = magic_function_to_pick_breaks()) > > > For example, if x looked like this... > > x <- c( 1:5, 10+1:5, 100+1:5 ) > > the breaks would define cells like this > > hist(x,breaks=c(0,5,15,105)) > > Is there such a function? > > __ > 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] arrays emerging from tapply
The code below illustrates some points about results from tapply that I find strange. I wonder if they are intended and if so why it is so. 1) When you make a table the dimnames is a *named* list, tapply returns an unnamed list. 2) data.frame behaves differently on an array and a table. Is this an intended feature? 3) For tables class(TAB) and attr(TAB,"class") both return "table", but class(ARR) returns "array" whereas attr(TAB,"class") returns NULL. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- Code: - Aye <- sample( c("Yes","Si","Oui"), 177, replace=TRUE ) Bee <- sample( c("Hum","Buzz"), 177, replace=TRUE ) Sea <- sample( c("White","Black","Red","Dead"), 177, replace=TRUE ) pyr <- rnorm( 177, 57, 14 ) TAB <- table( Aye, Bee, Sea ) ARR <- tapply( pyr, list( Aye, Bee, Sea ), sum ) dimnames( TAB ) dimnames( ARR ) data.frame( TAB ) data.frame( ARR ) data.frame( as.table( ARR ) ) class( TAB ) attr( TAB, "class" ) class( ARR ) attr( ARR, "class" ) --- Result: --- > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor0.1 year 2004 month11 day 15 language R > Aye <- sample( c("Yes","Si","Oui"), 177, replace=TRUE ) > Bee <- sample( c("Hum","Buzz"), 177, replace=TRUE ) > Sea <- sample( c("White","Black","Red","Dead"), 177, replace=TRUE ) > pyr <- rnorm( 177, 57, 14 ) > TAB <- table( Aye, Bee, Sea ) > ARR <- tapply( pyr, list( Aye, Bee, Sea ), sum ) > dimnames( TAB ) $Aye [1] "Oui" "Si" "Yes" $Bee [1] "Buzz" "Hum" $Sea [1] "Black" "Dead" "Red" "White" > dimnames( ARR ) [[1]] [1] "Oui" "Si" "Yes" [[2]] [1] "Buzz" "Hum" [[3]] [1] "Black" "Dead" "Red" "White" > > data.frame( TAB ) Aye Bee Sea Freq 1 Oui Buzz Black2 2 Si Buzz Black 11 3 Yes Buzz Black 10 4 Oui Hum Black7 5 Si Hum Black 11 6 Yes Hum Black3 7 Oui Buzz Dead3 8 Si Buzz Dead 11 9 Yes Buzz Dead5 10 Oui Hum Dead 11 11 Si Hum Dead3 12 Yes Hum Dead5 13 Oui Buzz Red5 14 Si Buzz Red4 15 Yes Buzz Red8 16 Oui Hum Red 11 17 Si Hum Red9 18 Yes Hum Red8 19 Oui Buzz White 10 20 Si Buzz White7 21 Yes Buzz White6 22 Oui Hum White8 23 Si Hum White 11 24 Yes Hum White8 > data.frame( ARR ) Buzz.Black Hum.Black Buzz.Dead Hum.Dead Buzz.Red Hum.Red Buzz.White Hum.White 1 130.5520 377.0875 177.9144 590.1498 346.4448 633.0975 492.9589 424.1464 2 607.4388 635.3015 651.3304 162.9175 223.1840 531.5512 347.7185 622.0213 3 555.8886 177.8216 295.0027 297.4550 417.6824 461.2143 359.4606 432.6165 > data.frame( as.table( ARR ) ) Var1 Var2 Var3 Freq 1 Oui Buzz Black 130.5520 2Si Buzz Black 607.4388 3 Yes Buzz Black 555.8886 4 Oui Hum Black 377.0875 5Si Hum Black 635.3015 6 Yes Hum Black 177.8216 7 Oui Buzz Dead 177.9144 8Si Buzz Dead 651.3304 9 Yes Buzz Dead 295.0027 10 Oui Hum Dead 590.1498 11 Si Hum Dead 162.9175 12 Yes Hum Dead 297.4550 13 Oui Buzz Red 346.4448 14 Si Buzz Red 223.1840 15 Yes Buzz Red 417.6824 16 Oui Hum Red 633.0975 17 Si Hum Red 531.5512 18 Yes Hum Red 461.2143 19 Oui Buzz White 492.9589 20 Si Buzz White 347.7185 21 Yes Buzz White 359.4606 22 Oui Hum White 424.1464 23 Si Hum White 622.0213 24 Yes Hum White 432.6165 > > class( TAB ) [1] "table" > attr( TAB, "class" ) [1] "table" > class( ARR ) [1] "array" > attr( ARR, "class" ) 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
RE: [R] plotting percent of incidents within different 'bins'
You want: tapply( Outcome, predictor, mean ) Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Stephen Choularton > Sent: Wednesday, January 05, 2005 8:35 PM > To: R Help > Subject: [R] plotting percent of incidents within different 'bins' > > > Hi > > Say I have some data, two columns in a table being a binary > outcome plus a predictor and I want to plot a graph that > shows the percentage positives of the binary outcome within > bands of the predictor, e.g. > > > Outcome predictor > > 0 1 > 1 2 > 1 2 > 0 3 > 0 3 > 0 2 > 1 3 > 1 4 > 1 4 > 0 4 > 0 4 > 0 4 > etc > > In this case there are 4 cases in the band 1 - 2 of the > predictor, 2 of them are true so the percent is 50% and there > are 7 cases in the band 3 > - 4, 3 of which are true making the percentage 43% . > > Is there some function in R that will sum these outcomes by > bands of predictor and produce a one by two data set with > the percentages in one column and the ordered bands in the > other, or alternately is there some sort of special plot. > that does it all for you? > > Thanks > > Stephen > > > > [[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] output from table() in matrix form
You probably want something like: > t1 <- table( x ) > t1 x 1 2 20 3 2 1 > t2 <- rbind( as.numeric( names( t1 ) ), t1 ) > t2 1 2 20 1 2 20 t1 3 2 1 > dimnames( t2 ) <- NULL > t2 [,1] [,2] [,3] [1,]12 20 [2,]321 > Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin > Sent: Wednesday, January 05, 2005 1:18 PM > To: R-help@stat.math.ethz.ch > Subject: [R] output from table() in matrix form > > > Hi > > How do I get the output from table() in matrix form? > > If I have > > R> table(c(1,1,1,1,2,20)) > > 1 2 20 > 4 1 1 > > I want > > [,1] [,2] [,3] > [1,]12 20 > [2,]411 > > > The problem is that names(table) is a vector of characters and I need > the numeric values. > > I am using > > R> rbind(as.integer(names(x)),x) > > > > > I thought tabulate() might be better as it takes an integer-valued > vector, but it isn't > quite right because the default bins are 1:20 and I don't want the > zeroes. > > The following is a little clunky: > > R> x <- rbind(1:20,tabulate(c(1,1,1,1,2,20))) > R> x[,x[2,]>0] > [,1] [,2] [,3] > [1,]12 20 > [2,]411 > > > Is there a better way? It seems inelegant to coerce a character > vector back to integers, > but OTOH it's wasteful to have 20 bins when I only need 3. My real > application would have > maybe a dozen distinct (prime) integers in the range 2 up to > about 1e4. > > > > > > -- > Robin Hankin > Uncertainty Analyst > Southampton Oceanography Centre > European Way, Southampton SO14 3ZH, UK > tel 023-8059-7743 > > __ > 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] numeric(0)
You would probably be better off without the loop, for example: ns <- length( sequence ) num.seq <- match( sequence, names ) scores <- mscore[cbind(num.seq[-1],num.seq[-ns])] sum( scores ) I have used the fact that if you index a matrix with a two-column,matrix ( here, cbind( , ) ), you select the corresponding elements of the matrix, see ?"[" But it only works if the matrix is numeric. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of dax42 > Sent: Wednesday, December 29, 2004 2:18 PM > To: r-help@stat.math.ethz.ch > Subject: [R] numeric(0) > > > Dear all, > > I am trying to calculate a score for a string sequence consisting of > the following four letters: ACGT. > I have got a matrix giving the scores for each pair of > letters. So for example the string ACCT has got the pairs: > AC, CC and CT. > > The matrix has got the following form: > names<-c("A","C","G","T"); mscore<-matrix(0,4,4); > rownames(mscore)<-names; colnames(mscore)<-names; > > So for the first example pair above I could get the score > contained in > the matrix with the following code: > >> mscore["A","C"] > > I am now trying to sum up all the scores with the following code: > > score<-0; > > for(j in 1:length(sequence)-1){ > score<-score+mscore[sequence[j],sequence[j+1]]; > } > > where sequence is the string sequence. > Unfortunately, it does not work and I get the following error message: > > Error in "[<-"(`*tmp*`, 1, i, value = numeric(0)) : > nothing to replace with > > What does this mean? Strangely, the command > "print(score+mscore[sequence[j],sequence[j+1]])" > works, so it really is the assignment which won't work. Why > is that? I am running R 2.0 series (GUI version) on Mac OSX 10.3.7. > > Any suggestions are welcome. > Thanks a lot, > Dax > > __ > 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] plots
For exact contol of height and width, you may want to have a look at: ?win.metafile Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > duraikannan sundaramoorthi > Sent: Tuesday, December 28, 2004 2:00 AM > To: r-help@stat.math.ethz.ch > Subject: [R] plots > > > Is there a way to save plots and use in a word > document. Thanks for your help in advance. > durai > > > > __ > > Send holiday email and support a worthy cause. Do good. > > __ > 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] splot.screen: multiple plots
You probably want to use something like par( mar=c(0,0,0,0), oma=c(3,3,2,3) ) which will put all your plots next to each other with no space between them and with a reasonable margin outside ("oma"). Take a print of the (rather long) help page for "par", and bring it with you wherever you go, so youcan study it in waiting lines, traffic jams, trains etc. It's boring to learn but useful to know all those weird arguments... best Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Anne G > Sent: Monday, December 27, 2004 11:55 AM > To: r-help@stat.math.ethz.ch > Subject: [R] splot.screen: multiple plots > > > I have multiple conditions that I would like to plot in a > grid. To save space, I don't need the ticks, labels etc on > the plots which are not on the outside. > > I tried split.screen, but if it is clearer to use, it seems > pretty rigid since it decides of each screen size apriori > while I need more space for the left column and top or bottom > row screens than for the other plots. > > axis(1,tick=FALSE) does not seem to do anything, asp=1 does > not seem to do anything either. par(pty="s") gave it a > somewhate square aspect, But there is a lot of empty space > which must have to do with margins, but setting the margins > did not seem to change anything. > > I think I have seen examples like mine in a book, but it > might have been a book on Splus. Do you know where I can > find an example of what I am looking for. > > thanks > Anne > -- > here is a simplified example with the same data for all > plots > > X<-c(1.0 3.63168 6.44916 10.17572 20.47440) > Y<-c(0.26 0.56 0.80 0.92 0.88) > > numFreq<-7 > numdist<-8 > > coefind <- 1 > quartz(display = "", width =15, height = 10, pointsize = 9, > family = "Helvetica", antialias = TRUE, > autorefresh = TRUE) > par(pty="s") > split.screen(c(numdist,numFreq)) > > for (inddist in 1:numdist) > { > for (indFreq in 1:numFreq) > { > indscreen<- indFreq+(inddist-1)*numFreq > > screen(indscreen) > # mar<-c(1,1,1,0) > > plot(X,Y, > log="x",col="red",xlim=c(1,100),ylim=c(0,1),lab=5, xlab="", > ylab="") > axis(1,tick=FALSE) > axis(2,tick=FALSE) > > if( inddist==1) > { > title(main=sprintf('Freq = > %d',indFreq)); > } > > if( indFreq==1) > { > axis(2, tick=TRUE) > title(ylab=sprintf('dist = > %d',inddist)); > } > if (inddist==8) > { > axis(1,tick=TRUE) > title(xlab="perc face") > } > > coefind <- coefind+1 > } > } > close.screen(all = TRUE)# exit split-screen mode > > __ > 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] vector
If you have all your vectors in a list vl <- list( p1, p2, p3) the the following should do the trick: res <- numeric(0) for( i in 1:length(vl) ) res <- c( res, vl[[i]] ) Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Frederic renaud > Sent: Monday, December 27, 2004 1:57 AM > To: r-help@stat.math.ethz.ch > Subject: [R] vector > > > Hi! > Can you help me? I would like to make a vector from p > pre-determined vector. The parameter p can change. I've try > with ?c with unsuccess! An idee? > > Sorry for my english! > Thanks > Fred > > __ > 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] Make a table
try: tapply( Z, list( X, Y ), mean ) -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Muhammad Subianto > Sent: Wednesday, December 22, 2004 2:26 PM > To: [EMAIL PROTECTED] > Subject: [R] Make a table > > > Dear useR, > > I have a dataset like this below, > > prevRND.dat <- read.table("C:\\workdir\\prevRND.txt", > + header=FALSE, # No header. > + col.names = c("X","Y","Z"), > + sep = ",") > > prevRND.dat >X YZ > 1 A A 0.950933 > 2 A B 0.143600 > 3 A C 0.956133 > 4 B A 0.000533 > 5 B B 0.986467 > 6 B C 0.032066 > 7 C A 0.005333 > 8 C B 0.00 > 9 C C 0.009266 > > How can I make that data above as table, > > Y > XA B C > A 0.950933 0.143600 0.956133 > B 0.000533 0.986467 0.032066 > C 0.005333 0.00 0.009266 > > I cannot use table() or ftable() functions because the 3rd > column (Z) is > probability. Are there any function to make a table as I want? > > Kind regards, > Muhammad Subianto > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] ordering levels: I was wrong
I was wrong about needing the Relevel from the Lexis package. The default verson of relevel does the job of reshuffling levels in any desired order, albeit with a warning (which comes from the fact that apparently only a single number had been anticipated by the designer): > testf <- factor( sample( letters[1:4], 100, replace=T ) ) > table( testf, newf=relevel( testf, ref=c(3,2,1,4) ) ) newf testf c b a d a 0 0 21 0 b 0 21 0 0 c 32 0 0 0 d 0 0 0 26 Warning message: the condition has length > 1 and only the first element will be used in: if (is.na(ref)) stop("ref must be an existing level") Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Anne > Sent: Wednesday, December 22, 2004 1:06 PM > To: R list > Subject: [R] ordering levels > > > Hello! > I would like to know if there is a simple way to reorder > levels of a given factor.Let's say that the vector > testf<-factor(c("red","red","red","blue","blue","white")) > levels(testf) : blue red white > > should have reordered levels such as > levels(testf) : red blue white > > (this is for presentation purposes) > I guess I'm looking for a generalized version of "relevel"... > > Thanks > > Anne > > > Anne Piotet > Tel: +41 79 359 83 32 (mobile) > Email: [EMAIL PROTECTED] > --- > M-TD Modelling and Technology Development > PSE-C > CH-1015 Lausanne > Switzerland > Tel: +41 21 693 83 98 > Fax: +41 21 646 41 33 > -- > > [[alternative HTML version deleted]] > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] ordering levels
In: http://biostat.ku.dk/~bxc/SPE/library/ you will find a zip of the Lexis package that contains the function Relevel, which has precise this (and other) features. Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Anne > Sent: Wednesday, December 22, 2004 1:06 PM > To: R list > Subject: [R] ordering levels > > > Hello! > I would like to know if there is a simple way to reorder > levels of a given factor.Let's say that the vector > testf<-factor(c("red","red","red","blue","blue","white")) > levels(testf) : blue red white > > should have reordered levels such as > levels(testf) : red blue white > > (this is for presentation purposes) > I guess I'm looking for a generalized version of "relevel"... > > Thanks > > Anne > > > Anne Piotet > Tel: +41 79 359 83 32 (mobile) > Email: [EMAIL PROTECTED] > --- > M-TD Modelling and Technology Development > PSE-C > CH-1015 Lausanne > Switzerland > Tel: +41 21 693 83 98 > Fax: +41 21 646 41 33 > -- > > [[alternative HTML version deleted]] > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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 can I take anti log of log base 2 values in R
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Saurin Jani > Sent: Friday, December 17, 2004 3:59 PM > To: [EMAIL PROTECTED] > Subject: [R] How can I take anti log of log base 2 values in R > > > Hi, > > I am using R for microarray data anlaysis. When I > normalize my data, it converts all my data in to log > base 2 values. how can I convert back to log base > 10..is there any function in R which I can use or how > can I take anti log. or is there any function in R > for antilog. This is a math question, from a very early course in analysis: Any two logarithms are proportional, so: log10(x) = K log2(x) for any x In particular for x=2, and since log2(2)=1: log10(2) = K so we have in general: log10(x) = log10(2) * log2(x) The antilog for the natural log is exp(x), for the base 2 log it is 2^x and for the base 10 log it is 10^x. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > Please let me know,..if anyone knows.. > > Thank you so much, > Saurin > > = > Saurin's WebWorld: http://hawkmail.monmouth.edu/~s0451884 > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] take precisely one named argument
specify: f <- function(...,a=NULL,b=NULL) {...etc Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin > Sent: Friday, December 17, 2004 1:18 PM > To: [EMAIL PROTECTED] > Subject: [R] take precisely one named argument > > > Hi > > I want a function that takes precisely one named argument and > no unnamed arguments. The named argument must be one of "a" or "b". > > If "a" is supplied, return "a". If "b" is supplied, return > 2*b. That is, the desired behaviour is: > > R> f(a=4) #return 4 > R> f(b=33) #return 66 > R> f(5) #error > R> f(a=3,b=5) #error > R> f(a=3,q=3) #error > R> f(q=3) #error > > The following function is intended to implement this: > > f <- function(a=NULL, b=NULL){ >if(!xor(is.null(a), is.null(b))){stop("specify exactly one > of a and > b")} >if(is.null(a)){return(2*b)}else{return(a)} > } > > > It almost works, but f(6) returns 6 (and should be an error). > > What is the best way to accomplish my desired behaviour? > > -- > Robin Hankin > Uncertainty Analyst > Southampton Oceanography Centre > European Way, Southampton SO14 3ZH, UK > tel 023-8059-7743 > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] Percentages in contingency tables *warning trivial question*
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Rachel Pearce > Sent: Monday, December 13, 2004 10:37 AM > To: [EMAIL PROTECTED] > Subject: [R] Percentages in contingency tables *warning > trivial question* > > > I hesitate to post this question in the light of recent > threads, indeed I have hesitated for several weeks, however I > have come to a full stop and really need some help if I am > going to progress. I am a new user of R for medical > statistics. I have attempted to read all the relevant > documents, but would welcome any suggestions as to what I have missed. > > I am trying to contruct "table 1" type contingency (mostly) > tables. I would like to include percentages, thus: > > Cases ControlsTotal > N % N % N % > Total 50 100 50 100 100 100 > > > Sex: M23 46 27 54 50 50 > > etc... > > I hesitate even more to mention it here, but I am thinking of > something along the lines of PROC TABULATE in SAS. This is one of the holes in the tabulation features in R. The simplest feature needed in the one in addmargins, but tabulation is still rudimentary in R. I'm afraid that what you want would reqire: 1. Make the table of counts 2. Make the table of percentages by sweeping out a margin ( i.e. take the margin and divide the entire table by that, - sweeping is just the generalization of this; use any desired function instesd of "/" ) 3. Define a new table with an extra dimension (c("N","pct")) and fill in the two original tables there. The last step is necessary in the absence of a generalized cbind/rbind for tables/arrays. Please correct me if such a thing exists. If it does, it should be referenced under "see also" in the help page for cbind. The weird example in addmargins only covers the case where a table of percentages is wanted with a margin of total counts, not the general problem. Somebody should sit down a write a reasonable tabulation feature for R, but the problem in itself is complcated, so the syntax is likely to be arcane. For example, take a look at the syntax for proc tabulate in SAS, which is very strange, but given the features it covers (which are all desirable) it is difficult to come up with something simpler. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > The closest I have found in the documentation I have read so > far is an example given in the help for "addmargins": > > Bee <- sample( c("Hum","Buzz"), 177, replace=TRUE ) > Sea <- sample( c("White","Black","Red","Dead"), 177, > replace=TRUE ) > ... > # Weird function needed to return the N when computing > percentages > sqsm <- function( x ) sum( x )^2/100 > B <- table(Sea, Bee) > round(sweep(addmargins(B, 1, list(list(All=sum, N=sqsm))), 2, > apply( B, 2, sum )/100, "/" ), 1) > round(sweep(addmargins(B, 2, list(list(All=sum, N=sqsm))), 1, > apply(B, 1, sum )/100, "/"), 1) > > .. Which introduced me to "sweep" and maybe could be extended > to do what I want. But I don't like using mysterious "weird" > functions. > > I recently found Paul Johnson's Rtips where: > http://www.ku.edu/~pauljohn/R/Rtips.html#6.1 mentioned the > function prop.table, which is also close to what I want. But > how to show Ns and percentages im the same table? > > I wondered if there were a function which does this already. > Or perhaps I should just write one for myself? Or should I > not be trying to do this in R in the first place and go back > to Excel (I no longer have access to SAS)? Please, NO! Or > perhaps I am looking for the wrong thing in the manuals? > > I have followed recent advice to look at Frank E Harrell's > detailed tabulation code, but this seems to produce many > errors on my system and with my version of R (see below). I > do not have access to LaTeX (apologies for incorrect > typography). I can provide details of the errors if it turns > out that the answer to my question is RTFM by Prof Harrell. > > I would like to add my two pennorth to the debate about > "trivial" questions, of which I assume this is one. I believe > that a very large amount of what is hard about learning R on > one's own with documentation but without a real person, is a > matter of vocabulary. I only found sweep and prop.table by > chance since neither of them are indexed by words like > "proportion" or "percentage" which is what I had been looking > for. Similarly I still do not know exactly what "sweep" does, > since I have never heard this verb used in a mathematical / > statistical context, and the help on sweep state
RE: [R] test multiple objects for being equal length
not that its much shorter: length( table( sapply( list(x,y,z), length ) ) ) == 1 Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Manuel > Gutierrez > Sent: Thursday, December 09, 2004 9:09 AM > To: [EMAIL PROTECTED] > Subject: [R] test multiple objects for being equal length > > > I could not find any help pages on How to test many > objects for being of equal length > Something like identical for more than two objects? > x<-1:6 > y<-1:10 > z<-3:5 > ## For two objects I can do: > identical(length(x),length(y)) > ## For more than two I currently can do: > length(unique(c(length(x),length(y),length(z==1 > > but there must be a better way. > Thanks, > M > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] Modyfing PATH in Windows Installer for R
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Henrik > Andersson > Sent: Monday, December 06, 2004 2:44 PM > To: [EMAIL PROTECTED] > Subject: [R] Modyfing PATH in Windows Installer for R > > > Just a small suggestion since Windows have a file system not designed > for command line use... I would strongly disagree on that one, it is just an unusually well kept secret. Just open a command window in windows and type "cmd /?" and you will get an introduction to a lot of useful features, such as filename completion etc. I run windows 2000 almost exclusively from the commnd line, and it's just about as versatile as the Linux command promp, albeit with slightly different command names. For some odd reasons the commands available are kept in the windows help under the heading "MS-DOS commands" even though DOS is long dead. And if you have loaded the utilities recommended for building R-packages you have almost all you want. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > > Would it be possible to add the possibility of automatically > adding/modifying the path to the R executables in the windows > installer > program? > > > - > Henrik Andersson > Netherlands Institute of Ecology - > Centre for Estuarine and Marine Ecology > P.O. Box 140 > 4400 AC Yerseke > Phone: +31 113 577473 > [EMAIL PROTECTED] http://www.nioo.knaw.nl/ppages/handersson > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] Unable to understand strptime() behaviour
Try to say: class(x) unclass(x) and it will dawn on you what goes on. -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Tim Churches > Sent: Tuesday, November 30, 2004 11:37 PM > To: [EMAIL PROTECTED] > Subject: [R] Unable to understand strptime() behaviour > > > R V2.0.1 on Windows XP. > > I have read the help pages on strptime() over and over, but > can't understand why strptime() is producing the following results. > >> v <- format("2002-11-31", format="%Y-%m-%d") >> v > [1] "2002-11-31" >> factor(v, levels=v) > [1] 2002-11-31 > Levels: 2002-11-31 >> x <- strptime("2002-11-31", format="%Y-%m-%d") >> x > [1] "2002-12-01" >> factor(x, levels=x) > [1] > Levels: 2002-12-01 NA NA NA NA NA NA NA NA > > Tim C > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] About ROC curves
There is a package, Lexis, not officil though, which contains a function ROC (and some other stuff for epidemiology). You can find it in: http://biostat.ku.dk/~bxc/SPE/library/ Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Xin Qi > Sent: Tuesday, November 30, 2004 5:49 AM > To: [EMAIL PROTECTED] > Subject: [R] About ROC curves > > > Hi, Dear all R users: > > Does someone know whether R can calculate the Receiver Operating > Characteristic (ROC) Curves? I didn't find it from the packages. > > Thanks a lot. > > --- Xin > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] SAS or R software
Two major advantages of SAS that seems to have been overlooked in the previous replies are: 1) The data-set language is SAS for data manipulation is more human-readable than R-code in general. R is not a definite write-only laguage as APL, but in particular in datamanipulation it is easy to write code that is impossible to decipher after few weeks. You can also produce unreadable code in SAS, but it generally takes more of an effort. Thus: Data manupulation is easier to document in SAS than in R. 2) proc tabulate. This procedure enables you to do extensive sensible tabulation of your data if you are prepared to read the manual. (This is not a product of the complexity of the software, but of the complexity of the tabulation features). Compared to this only rudimentay tools exist in R (afaik). So if you want to do well documented data manipulation and clear and compact tables go for SAS. If you want to do statistical analyses and graphics (in finite time) go for R. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of neela v > Sent: Saturday, November 20, 2004 9:18 AM > To: [EMAIL PROTECTED] > Subject: [R] SAS or R software > > > Hi all there > > Can some one clarify me on this issue, features wise which is > better R or SAS, leaving the commerical aspect associated > with it. I suppose there are few people who have worked on > both R and SAS and wish they would be able to help me in > deciding on this. > > THank you for the help > > > - > > Meet the all-new My Yahoo! - Try it today! > [[alternative HTML version deleted]] > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] survSplit: further exploration and related topics
To Danardonos concern of splitting time for records with delayed entry: This can fairly easily be accomodated, by simply splitting time in small intervals of time since entry into the study, and then compute the value of the other timescales for each of these e.g.: current.age <- time.from.entry + age.at.entry but the cut on the other timescales will not be exactly where you may want them to be, but this should be of minor importance in real life. This approach will also make it clearer what really is going on. The effect of each of the timescales can then be modelled using the usual regression tools available in R. David Clayton har written an R-function that does it correctly, you can find it in: http://biostat.ku.dk/~bxc/Lexis/ along with its .Rd file. It is also included a Lexis-package which is a first shot at an epidemiology package for R available at http://biostat.ku.dk/~bxc/SPE/library/, but built under 1.9. I recently tried to build it under 2.0, but it crashed for me and I was advised to wait till 2.1 before I had another go at it. A little further exploration of what goes on in survSplit gives: > data(aml) > aml$id <- letters[1:dim(aml)[1]] > aml3<-survSplit(aml,cut=c(5,10,50),end="time",start="start", + event="status",episode="i") > # Sort the rows sensibly > aml3 <- aml3[order(aml3$id,aml3$start),] > aml3$expand <- 1:(dim(aml3)[1]) > aml3[aml3$id=="k",c("id","expand","start","time","status","x")] id expand start time status x 11 k 30 05 0 Maintained 34 k 31 5 10 0 Maintained 57 k 3210 50 0 Maintained 80 k 3350 161 0 Maintained > > # All records are taken as if entry were at time 0: > aml4<-survSplit(aml3,cut=c(9,12,40),end="time",start="entry", + event="status",episode="i",id="id2") > aml4 <- aml4[order(aml4$id,aml4$expand,aml4$start),] > aml4[aml4$id=="k",c("id","expand","start","entry","time","status","x")] id expand start entry time status x 30 k 30 0 05 0 Maintained 31 k 31 5 09 0 Maintained 94 k 31 5 9 10 0 Maintained 32 k 3210 09 0 Maintained 95 k 3210 9 12 0 Maintained 158 k 321012 40 0 Maintained 221 k 321040 50 0 Maintained 33 k 3350 09 0 Maintained 96 k 3350 9 12 0 Maintained 159 k 335012 40 0 Maintained 222 k 335040 161 0 Maintained > > # entry time is is "start", but it seems that it is more or less > # assumed that entry is at the first split point given. > aml5<-survSplit(aml3,cut=c(9,12,40),end="time",start="start", + event="status",episode="i",id="id2") > aml5 <- aml5[order(aml5$id,aml5$expand,aml5$start),] > aml5[aml5$id=="k",c("id","expand","start","time","status","x")] id expand start time status x 30 k 30 05 0 Maintained 31 k 31 59 0 Maintained 94 k 31 9 10 0 Maintained 95 k 32 9 12 0 Maintained 158 k 3212 40 0 Maintained 221 k 3240 50 0 Maintained 96 k 33 9 12 0 Maintained 159 k 3312 40 0 Maintained 222 k 3340 161 0 Maintained > It appears that the intention has been to support counting process input, but not quite succeeded. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Thomas Lumley > Sent: Monday, November 08, 2004 4:28 PM > To: Danardono > Cc: [EMAIL PROTECTED] > Subject: Re: [R] survSplit > > > On Mon, 8 Nov 2004, Danardono wrote: > > > I am just realized that survival has the facility to do > survival time > > splitting survSplit > > after read some postings about time dependency in the list. > > Is it survSplit only for the survival data input > (time,status) and not for > > the 'counting process' input (start,stop,status)? > > > > I take one example modified from the survSplit help: > >> data(aml) > >> > aml3<-survSplit(aml,cut=c(5,10,50),end="time",start="start",event="st > >> atus",episode="i",id="id") > > > >> coxph(Surv(time,status)~x,data=aml) > > > > coef exp(coef) se(coef)z p > > xNonmaintained 0.916 2.50.512 1.79 0.074 > > > > Likelihood ratio test=3.38 on 1 df, p=0.0658 n= 23 > > > > #the same > >> coxph(Surv(time,status)~x,data=aml3) > > > > coef exp(coef) se(coef)z p > > xNonmaintained 0.916 2.50.512 1.79 0.074 > > > > Likelihood ratio test=3.38 on 1 df, p=0.0658 n= 63 > > This should NOT be the
RE: [R] sub- and superscript in plot labels
try: plot(1:10, xlab = substitute( expression(paste("nm SO"[4]^{2-x}, " ", mu, "eq cm"^{-2}, " yr"^{-1})), list(x="") ) ) I have no understanding of why it works, formula fidgeting usually requires use of subtitute(). Btw. I started out trying: plot(1:10, xlab = substitute( expression(paste("nm SO"[4]^x, " ", mu, "eq cm"^{-2}, " yr"^{-1})), list(x="2-") ) ) but that gives a hyphen and not a minus trailing the superscript "2". Bendix Carstensen > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Gavin Simpson > Sent: Thursday, November 04, 2004 1:20 PM > To: [EMAIL PROTECTED] > Subject: [R] sub- and superscript in plot labels > > > Dear List, > > I need to add a subscript and a superscript to some of the > ions in the > labels on some plots. > > I have got to here but now I'm stuck: > > plot(1:10, xlab = expression(paste("nm SO"[4], " ", mu, "eq > cm"^{-2}, " > yr"^{-1}))) > > Which gives almost what I require. No matter what I tried, > however, I > could not get bot a sub script *and* a superscript attached > to the SO in > the label. > > In LaTeX I would just do $SO_4^{2-}$ but taking that to R produces a > syntax error: > > plot(1:10, xlab = expression(paste("nm SO"[4]^{2-}, " ", mu, "eq > cm"^{-2}, " yr"^{-1}))) > > Strangely, I can do this: > > plot(1:10, xlab = expression(paste("nm SO"[4]^2, " ", mu, "eq > cm"^{-2}, > " yr"^{-1}))) > > With almost the desired effect (except I need to add two > characters to > the superscript). > > Can any one offer a solution? > > Many thanks > > Gavin > -- > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~ > %~%~%~%~% > Gavin Simpson [T] +44 (0)20 7679 5522 > ENSIS Research Fellow [F] +44 (0)20 7679 7565 > ENSIS Ltd. & ECRC [E] [EMAIL PROTECTED] > 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. > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~ > %~%~%~%~% > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] Building a package under WIN2000 / rw2.0
I have an odd problem in building a package with only R-code in it. I have a package mainly used by myself which I last build under R 1.9.0. The operation system is Win2000 5.00.2195, Service Pack 3 When I do: c:\stat\r\rw2000\bin\Rcmd install --docs=normal --build --library=c:\stat\R\bxc\library c:\stat\R\bxc\library.sources\xx then after updating help pages I get: preparing package xx for lazy loading Error in tools:::.read_description(file) : file '/DESCRIPTION' does not exist Execution halted make: *** [lazyload] Error 1 *** Installation of xx failed *** (Yes, I have a DESCRIPTION file). Having made a few changes here and there in some of the functions I transferred them one at a time to a new folder and tried to build it there. The probelm seems to be that once I exceed 5 functions in the package the above error appears, with 5 or fewer functions it works OK. Any ideas? Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] 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] deleting specified NA values
How about: all.nas <- apply( old, 1, function(x) sum( is.na( x ) ) ) new <- old[all.nas < dim( old )[2], ] -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Robert > Brown FM CEFAS > Sent: Monday, November 01, 2004 4:18 PM > To: [EMAIL PROTECTED] > Subject: [R] deleting specified NA values > > > I have a data set of about 1 records which was compiled > from several smaller data sets using SPSS. During compilation > 88 false records were accidentally introduced which comprise > all NA values. I want to delete these records but not other > missing data. The functions na.exclude and na.omit seem to > remove all values of NA? How can I delete just the relevant > NA's? . i.e. I want to delete all records in the data frame > DATA where the field age contains NA values > > Regards, > > Robert Brown > > __ > [EMAIL PROTECTED] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] 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] Automatic routine - help
for (j in 1:n) df[,j] <- pmin( pmax( df[,j], 0 ), 1 ) should do the job. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Monica > Palaseanu-Lovejoy > Sent: Wednesday, June 23, 2004 11:07 AM > To: [EMAIL PROTECTED] > Subject: [R] Automatic routine - help > > > Hi, > > I would like to write a little automatic routine in R, but i am a too > much of a beginner for that. I will appreciate any help > regarding this > particular problem. > > Let's suppose I have a data.frame with j columns (from 1 to n) and i > rows (from 1 to p). I would like to write a procedure which reads > every column j (j from 1 to n) and compare each value with the > interval [0,1]. If z(i,j) is less than 0, then replace z(i,j) > with 0. If z(i,j) > is greater than 1, then replace z(i,j) with 1. If z(i,j) is > inside the > interval [0,1] then don't change. In the end I would like to have a > new data.frame with the new values. > > I am not sure how complicated or long such a procedure might be, > so I will be very grateful for any help. > > Thank you in advance, > > Monica > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] frequencies
You want the function cut(), followed by table(). Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Silvia Kirkman > Sent: Monday, June 21, 2004 4:01 PM > To: [EMAIL PROTECTED] > Subject: [R] frequencies > > > Hi > > I have a set of fish lengths (cm) which I'd like to > have divided into bins as specified by myself. I want > to classify my bins as: > > 0<=x<0.5 > 0.5<=x<1 > 1<=x<1.5 > 1.5<=x<2 > and so on... > > I'd like the frequencies to be given as a vector > because I need to use these values for further > analysis. > > Please can someone help me with this. I can't find a > command in R that allows one to do this. > > Many thanks. > > Silvia Kirkman > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] latex function in Hmisc
Is there a way to prevent latex.default() from starting LaTeX and JUST create the file requested? I generate a number of LaTeX tables for inclusion in a document running R in batch, and I don't want a lot of calls to LaTeX. I cannot find any arguments for that task in the documentation. It seems a little clumsy to have to direct the output from a function with a "file" argument using sink() and 'file=""'. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] coef and vcoc for polr inconsistent??
Is the following an inconsistency, programming glitch or a feature? One would expect that vcov(obj) was the variance-covariance of coef(obj), but apparently this is not the case for polr objects: > x <- rnorm( 100 ) > y <- rnorm( 100 ) > ff <- factor( sample( 1:4, 100, replace=T ) ) > pm <- polr( ff ~ x + y ) > coef( pm ) x y 0.21219010 0.03558506 > vcov( pm ) Re-fitting to get Hessian xy 1|2 2|3 3|4 x0.033462790 -0.002414745 -0.006183451 -0.004164503 -0.001585546 y -0.002414745 0.032953020 0.003821232 0.003645342 0.003756031 1|2 -0.006183451 0.003821232 0.060134608 0.029651508 0.018105699 2|3 -0.004164503 0.003645342 0.029651508 0.041604224 0.025465751 3|4 -0.001585546 0.003756031 0.018105699 0.025465751 0.051576286 But of course you CAN get wat you want: > summary( pm )$coef Re-fitting to get Hessian Value Std. Errort value x0.21219010 0.1829284 1.1599628 y0.03558506 0.1815297 0.1960289 1|2 -1.29481930 0.2452236 -5.2801580 2|3 -0.22054056 0.2039711 -1.0812342 3|4 0.98703785 0.2271041 4.3461907 > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major1 minor9.0 year 2004 month04 day 12 language R -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Month names
This is how I get the month names from within R: > mon <- rep(strptime("01/01/1952", format = "%d/%m/%Y"), 12) > mon$mon <- mon$mon + 0:11 > mnam <- months(mon, abbreviate = F) > mnam [1] "januar""februar" "marts" "april" "maj" "juni" "juli" "august""september" [10] "oktober" "november" "december" Surely someone on the list can beat that in elegance? Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Setting up contrasts
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of David > J. Netherway > Sent: Monday, May 03, 2004 10:25 AM > To: [EMAIL PROTECTED] > Subject: [R] Setting up contrasts > > > I am using the following model: > lm <- lm(mydata[[variableName]] ~ Age + Gender + Group, data=mydata) > > There are 5 groups in "Group": nonc (the control), c1,c2,c3 and c4. > > How do I contrast nonc vs the others? "nonc" will be the reference if you use treatment contrasts (the default). > > and > > How do I contrast c1 vs other c's (ie c2,c3,c4 as a subgroup)? In the second case you just replace: Group with relevel( Group, "c1" ) --- see the help page for "relevel". Try for example: table( Group, relevel( Group, "c1" ) ) table( Group, relevel( Group, 2 ) ) to see the mechanics of it. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > > I have looked at the contrasts option in lm and model.matrix > and am really none the wiser. Though it looks like I need to > read up on model matrices again. > > Any help would be appreciated. > > Thanks, David > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Size of R user base
I wonder if there is a count of the number of downloads of each version of the R installations (for example rw1090.exe)? Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] pretty for a log-axis
Is there a function that does the same as pretty but on a log-scale? Suppose you have x <- exp( runif( 100, 0, 6 ) ) (which will between 1 and 403), then I would like to have a result like: log.pretty( x ) [1] 1 5 10 50 100 500 Bendix C. -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Question (on matrix indexes)
I am not sure what you mean but you might be interested in the functions row() and col(). Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of "Ivan Yegorov" > Sent: Friday, April 09, 2004 1:56 PM > To: [EMAIL PROTECTED] > Subject: [R] Question > > > Could you please help me. How can I get indexes of matrix > elements equal to the specified value. Thanks in advance. > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE > do read the posting guide! http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] predict( ..., type="terms")
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Thomas Lumley > Sent: Wednesday, April 07, 2004 5:44 PM > To: Giovanni Petris > On Wed, 7 Apr 2004, Giovanni Petris wrote: > > > > > Hello, > > > > After reading the help for predict.lm and predict.glm, it > is not clear > > to me what are the values returned by predict( ..., type="terms"). > > > > Anybody willing to enlighten me? > > > > For each term in the formula, extract its coefficients and > the corresponding columns of the design matrix, and multiply > the two, and then center the result. > > So, looking at the example in example(termplot) we have a > model y~ns(x,6)+z where z is a factor with 4 levels. > > There are 9 coefficients in the model, but only two terms: > ns(x,6) (based on 5 coefficients) and z (based on 3 coefficients). > > Adding up the terms and the centering value (also returned by > predict(,type="terms")) gives the linear predictor. 1) It would be useful to have this in the help file for predict.(g)lm Also that the constant is accessed as attr( pr.obj, "const" ) 2) A link to termplot might be useful too. 3) I guess that Giovanni (as well as I) was curious what the rationale behind the centering of effects is. Can anyone tell us? Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict.gl( ..., type="terms" )
When I do: > apc <- glm( D ~ ns( Ax, knots=seq(50,80,10), Bo=c(40,90) ) + + ns( Cx, knots=seq(1880,1940,20), Bo=c(1840,1960) ) + + ns( Px, knots=seq(1960,1980,10), Bo=c(1940,2000) ) + + offset( log( Y ) ), + family=poisson ) > pterm <- predict( apc, type="terms" ) > plink <- predict( apc, type="link" ) > ( apply( pterm, 1, sum ) + log( Y ) - plink )[1:10] 1 2 3 4 5 6 7 8 9 10 6.85047 6.85047 6.85047 6.85047 6.85047 6.85047 6.85047 6.85047 6.85047 6.85047 > coef( apc )[1] (Intercept) -13.61998 >From the help page for predict.glm I would have expected that the constant 6.85 was -intercept. What am I missing from predict.glm? (or from splines?) Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Confidence Intervals for slopes
You may want: lm( y ~ x:z ) This is the same model you fitted, but prametrized differently. But please check that what you REALLY want is not lm( y ~ z + x:z ) This is the model with different intercepts as well. Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of David Orme > Sent: Monday, March 29, 2004 4:44 PM > To: [EMAIL PROTECTED] > Subject: [R] Confidence Intervals for slopes > > > Hi, > > I'm trying to get confidence intervals to slopes from a linear model > and I can't figure out how to get at them. As a cut 'n' paste example: > > # > # dummy dataset - regression data for 3 treatments, each > treatment with > different (normal) variance > x <- rep(1:10, length=30) > y <- 10 - (rep(c(0.2,0.5,0.8), each=10)*x)+c(rnorm(10, sd=0.1), > rnorm(10, sd=0.6),rnorm(10, sd=1.1)) > z <- gl(3,10) > plot(y~x, pch=unclass(z)) > > # model as three slopes with common intercept > options(contrasts=c("contr.treatment","contr.poly")) > model <- lm(y~x+x:z) > > # coefficient table in summary gives the intercept, first > slope and the > difference in slopes > summary(model) > > # confint gives the confidence interval for the intercept and first > slope, > # and the CIs for the _differences_ > confint(model) > # > > What I'd like to report are the actual CI's for the slopes for the > second and third treatments, in the same way that confint returns the > parameter estimates for the first treatment. Can anyone point > me in the > right direction? > > Thanks, > David > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Q: Odds Ratio
lr.mod <- glm( y ~ x + w, family=binomial ) exp( summary( lr.mod )$coef[,1:2] %*% rbind( c(1,1,1), 1.96*c(0,-1,-1) ) ) should do the job. Pack it in a function if you like, see e.g. the (so far) undocumented function ci.lin in: http://www.biostat.ku.dk/~bxc/R/ci.lin.R (depends on) http://www.biostat.ku.dk/~bxc/R/ci.mat.R Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Cristian Pattaro > Sent: Wednesday, March 17, 2004 11:50 AM > To: [EMAIL PROTECTED] > Subject: [R] Q: Odds Ratio > > > Dear all, > > is there a automatic method to obtain Odds Ratio estimates and their > confidence intervals from a GLM Logistic model? > > Thanks > Cristian > > = > Cristian Pattaro > = > Unit of Epidemiology & Medical Statistics > Department of Medicines and Public Health > University of Verona > [EMAIL PROTECTED] > = > > > [[alternative HTML version deleted]] > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] glm questions --- saturated model
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of David Firth > Sent: Tuesday, March 16, 2004 1:12 PM > To: Paul Johnson > Cc: [EMAIL PROTECTED] > Subject: Re: [R] glm questions > > > Dear Paul > > Here are some attempts at your questions. I hope it's of some help. > > On Tuesday, Mar 16, 2004, at 06:00 Europe/London, Paul Johnson wrote: > > > Greetings, everybody. Can I ask some glm questions? > > > > 1. How do you find out -2*lnL(saturated model)? > > > > In the output from glm, I find: > > > > Null deviance: which I think is -2[lnL(null) - lnL(saturated)] > > Residual deviance: -2[lnL(fitted) - lnL(saturated)] > > > > The Null model is the one that includes the constant only > (plus offset > > if specified). Right? > > > > I can use the Null and Residual deviance to calculate the > "usual model > > Chi-squared" statistic > > -2[lnL(null) - lnL(fitted)]. > > > > But, just for curiosity's sake, what't the saturated model's -2lnL ? > > It's important to remember that lnL is defined only up to an additive > constant. For example a Poisson model has lnL contributions -mu + > y*log(mu) + constant, and the constant is arbitrary. The > differencing > in the deviance calculation eliminates it. What constant would you > like to use?? > I have always been und the impression that the constant chosen by glm is that which makes the deviance of the saturated model 0, the saturated model being the one with one parameter per observation in the dataset. For example: > y <- sample( 0:10, 15, replace=T ) > A <- factor( rep( 1:5, 3 ) ) > B <- factor( rep( 1:3, each=5 ) ) > data.frame( y, A, B ) y A B 1 1 1 1 2 4 2 1 3 3 3 1 4 7 4 1 5 1 5 1 6 0 1 2 7 5 2 2 8 8 3 2 9 4 4 2 10 2 5 2 11 6 1 3 12 10 2 3 13 6 3 3 14 0 4 3 15 1 5 3 > glm( y ~ A + B, family=poisson ) Call: glm(formula = y ~ A + B, family = poisson) Coefficients: (Intercept) A2 A3 A4 A5 B2 0.6581 0.9985 0.8873 0.4520 -0.5596 0.1719 B3 0.3629 Degrees of Freedom: 14 Total (i.e. Null); 8 Residual Null Deviance: 40.33 Residual Deviance: 24.07AIC: 78.9 > glm( y ~ A * B, family=poisson ) Call: glm(formula = y ~ A * B, family = poisson) Coefficients: (Intercept) A2 A3 A4 A5 B2 2.535e-151.386e+001.099e+001.946e+00 -1.293e-14 -2.330e+01 B3A2:B2A3:B2A4:B2A5:B2 A2:B3 1.792e+002.353e+012.428e+012.274e+012.400e+01 -8.755e-01 A3:B3A4:B3A5:B3 -1.099e+00 -2.704e+01 -1.792e+00 Degrees of Freedom: 14 Total (i.e. Null); 0 Residual Null Deviance: 40.33 Residual Deviance: 3.033e-10AIC: 70.84 -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] creating a ps. file
paste is the function you need. Bendix C. -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > [EMAIL PROTECTED] > Sent: Monday, March 15, 2004 12:37 PM > To: [EMAIL PROTECTED] > Subject: [R] creating a ps. file > > > Dear all > > I wrote a routine. At the end of each cycle of the loop I > would like to > save the result (plot) in a postcriptfile. > Of course if I just use dev.print in the following way: > dev.print(device=postcript, 'c:/Rfigures/plot_1.ps") > I overwrite my results with the second cycle of the loop. I suppose > there is a way to define the file name so that several plots are > created(plot_1,plot_2...). > > Could you give me an advice? Thanks a lot > > Best Regards > Mike > > --- > sunrise ADSL > Gratis, einfach und schnell: sunrise ADSL, inkl. USB Modem > und einmalige Aufschaltgebühr > http://internet.sunrise.ch/de/internet/int_ads> .asp > --- > > sunrise ADSL > Gratuit, simple et rapide: sunrise > ADSL, Modem USB inclus, aucun frais de mise en service > http://internet.sunrise.ch/fr/internet/int_ads> .asp > --- > > sunrise ADSL > Gratis, pratico e veloce: sunrise > ADSL, incl. Modem USB et tassa attivazione > http://internet.sunrise.ch/it/internet/int_ads> .asp > --- > > sunrise ADSL > free, simple and fast: ADSL from > sunrise, incl. Modem USB and one- time activation fee > http://internet.sunrise.ch/de/internet/int_ads> .asp > --- > > > __ > > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] help
I guess what you want is: a <- abs(a) floor( a / 10^floor( log10( a ) ) ) Bendix -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Manica > Sent: Friday, March 12, 2004 3:15 PM > To: [EMAIL PROTECTED] > Subject: [R] help > Importance: High > > > I want to extract the first non-zero digit of any vector, as > for example from a<-runif(100,0,1). Tried it using grep (...) > but didn´t work. > > Any help is very much appreciated. > Thanks, > Manica > > > -- > visite > http://ipimar-iniap.ipimar.pt/neomav/ > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Command Line Expressions
The natural thing would be to pack this into script, but if you in windows do: echo %1 | Rterm --vanilla -q you run into the problem that everything after the first comma is discarded, unless you use: echo %~1 | Rterm --vanilla -q in which case you will have to quote any R-commands with commas in them. Bendix Carstensen > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Liaw, Andy > Sent: Friday, March 05, 2004 1:56 PM > To: 'Pingping Zheng'; [EMAIL PROTECTED] > Subject: RE: [R] Command Line Expressions > > > Use echo in a Unix shell and pipe it to R. At the Windows > command prompt, you could try: > > c:\home>echo R.version | Rterm --vanilla -q > > R.version > _ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major1 > minor8.1 > year 2003 > month11 > day 21 > language R > > HTH, > Andy > > > From: Pingping Zheng > > > > Hi, > > > > Is it possible to run R in command line to evalute R > expressions and > > return results to stdout, something like > > > > >R CMD -e "R.version$minor" > > then you got return > > >"8.1" > > > > Or do a simple calculation > > >R CMD -e "sin(1.2)" > > >0.932039 > > > > Thanks. > > > > -- > > Pingping Zheng > > Department of Mathematics and Statistics > > Fylde College > > Lancaster University > > Lancaster LA1 4YF > > UK > > > > __ > > [EMAIL PROTECTED] mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > > -- > > Notice: This e-mail message, together with any > attachments,...{{dropped}} > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] read.spss and time/date information
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > [EMAIL PROTECTED] > Sent: Wednesday, March 03, 2004 6:27 PM > To: Peter Dalgaard > Cc: [EMAIL PROTECTED] > Subject: Re: [R] read.spss and time/date information > > > > > On Wed, 3 Mar 2004, Peter Dalgaard wrote: > > > Torsten Hothorn <[EMAIL PROTECTED]> writes: > > > > > Could anyone give me a a hint how I can convert 13264300800 to > > > 2003/02/11 again, please? > > > > > ISOdate(1582,10,14) + 13264300800 > > [1] "2003-02-11 13:00:00 CET" > > > ISOdate(1582,10,14) + 13142476800 > > [1] "1999-04-03 14:00:00 CEST" > > > > [October 14, 1582 is Day 1 of the Gregorian calendar.] > > > > I tried January 1th 1970 as "baseline" but I never would have > dreamed of October 14, 1582. This is the day the present Gregorian calendar was instituted, replacing the old Julian that did not have leap years. So it is actually quite sensible as it is the earliest possible date that is in unbroken sequence to present times. Actually I am amazed that this has not been chosen as the natural origin for any of the R-pakages... Bendix Carstensen > > Thanks to all responders! > > Torsten > > > -- > >O__ Peter Dalgaard Blegdamsvej 3 > > c/ /'_ --- Dept. of Biostatistics 2200 Cph. N > > (*) \(*) -- University of Copenhagen Denmark Ph: > (+45) 35327918 > > ~~ - ([EMAIL PROTECTED]) FAX: > (+45) 35327907 > > > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > PLEASE > do read the posting guide! > http://www.R-project.org/posting-guide.html > __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] A course in using R for Epidemiology
Course in STATISTICAL PRACTICE IN EPIDEMIOLOGY USING R Tartu, Estonia, 29 May - 4 June 2004. Aimed at young statisticians and epidemiologists wishing to broaden their epidemiological skills, in particular with respect to practical statistical analysis. Participants will gain access to the versatile analysis tool R, which has good analytical in particular graphical capabilities. Participants are required to have a fairly good understanding of statistical principles and some familiarity with epidemiological concepts. The course will be mainly practically oriented with more than half the time at the computer. Price: 400 EUR. (200 EUR for non-EU countries). Application deadline: 1 April 2004. Further information at: www.biostat.ku.dk/~bxc/SPE -- Krista Fischer, University of Tartu, Estonia Esa Läärä, University of Oulu, Finland Bendix Carstensen, Steno Diabetes Center, Denmark (Organizers) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] converting data to date format
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Mike Hollegger > Sent: Saturday, February 14, 2004 12:03 PM > To: [EMAIL PROTECTED] > Subject: [R] converting data to date format > > > Dear all, > ...snip > I've tried to bring it in character-format (as.charachter()) > followed by > as.POSIXlt() but I get an error message, that the character > string is not in > a standard unambiguous format, although the date is of format > -mm-dd > (what is standard format according to R reference manual). ...snip > Thank you very much for any usefull hint! There seems to be someting fishy about 1 january 1970, I think it is a bug in Windows: > as.POSIXlt("1970-01-01") Error in fromchar(x) : character string is not in a standard unambiguous format > as.POSIXlt("1970-01-02") [1] "1970-01-02" > as.POSIXlt("1970-02-01") [1] "1970-02-01" > as.POSIXlt("1970-12-31") [1] "1970-12-31" A workaround is: > as.POSIXlt( strptime("1970-01-01",format="%Y-%m-%d") ) [1] "1970-01-01" A peep at fromchar which is defined inside as.POSIXlt lead one to try the following: > is.na( strptime("1970-01-01", f <- "%Y-%m-%d") ) [1] TRUE > strptime("1970-01-01", f <- "%Y-%m-%d") [1] "1970-01-01" > is.na( strptime("1970-01-02", f <- "%Y-%m-%d") ) [1] FALSE > strptime("1970-01-02", f <- "%Y-%m-%d") [1] "1970-01-02" I would like to why this is so. And whether thereason for this it is beyond R. Btw, I use: > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major1 minor8.1 year 2003 month11 day 21 language R Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Strange parametrization in polr
In Venables \& Ripley 3rd edition (p. 231) the proportional odds model is described as: logit(p<=k) = zeta_k + eta but polr apparently thinks there is a minus in front of eta, as is apprent below. Is this a bug og a feature I have overlooked? Here is the naked code for reproduction, below the results. --- version library( MASS ) data( housing ) hnames <- lapply( housing[,-5], levels ) house.plr <- polr( Sat ~ Infl + Type + Cont, data=housing, weights=Freq ) summary( house.plr ) newdat <- expand.grid( hnames[-1] )[1:5,] cbind( newdat, predict( house.plr, newdat, type="probs" ) ) # Baseline probs: diff( c(0,tigol( c(-0.4961,0.6907) ), 1) ) # First level of Infl: diff( c(0,tigol( c(-0.4961,0.6907) + 0.5663922 ), 1) ) # But the change of sign for eta is needed to reproduce the fitted values: # Line 2: diff( c(0,tigol( c(-0.4961,0.6907) - 0.5663922 ), 1) ) # Line 5: diff( c(0,tigol( c(-0.4961,0.6907) - 0.5663922 + 0.5723552 ), 1) ) --- Here is the resulting output: --- > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major1 minor8.1 year 2003 month11 day 21 language R > library( MASS ) > data( housing ) > hnames <- lapply( housing[,-5], levels ) > house.plr <- polr( Sat ~ Infl + Type + Cont, data=housing, weights=Freq ) > summary( house.plr ) Re-fitting to get Hessian Call: polr(formula = Sat ~ Infl + Type + Cont, data = housing, weights = Freq) Coefficients: Value Std. Error t value InflMedium 0.5663922 0.10465276 5.412109 InflHigh 1.2888137 0.12715609 10.135682 TypeApartment -0.5723552 0.11923800 -4.800107 TypeAtrium-0.3661908 0.15517331 -2.359882 TypeTerrace -1.0910073 0.15148595 -7.202036 ContHigh 0.3602803 0.09553577 3.771156 Intercepts: Value Std. Error t value Low|Medium -0.4961 0.1248-3.9740 Medium|High 0.6907 0.1255 5.5049 Residual Deviance: 3479.149 AIC: 3495.149 > newdat <- expand.grid( hnames[-1] )[1:5,] > cbind( newdat, predict( house.plr, newdat, type="probs" ) ) Infl Type Cont LowMedium High 1Low Tower Low 0.3784485 0.2876755 0.3338760 2 Medium Tower Low 0.2568261 0.2742125 0.4689614 3 High Tower Low 0.1436927 0.2110841 0.6452232 4Low Apartment Low 0.5190450 0.2605077 0.2204473 5 Medium Apartment Low 0.3798522 0.2875967 0.3325511 > # Baseline probs: > diff( c(0,tigol( c(-0.4961,0.6907) ), 1) ) [1] 0.3784576 0.2876650 0.3338774 > # First level of Infl: > diff( c(0,tigol( c(-0.4961,0.6907) + 0.5663922 ), 1) ) [1] 0.5175658 0.2609593 0.2214749 > # But the change of sign for eta is needed to reproduce the fitted values: > # Line 2: > diff( c(0,tigol( c(-0.4961,0.6907) - 0.5663922 ), 1) ) [1] 0.2568335 0.2742035 0.4689630 > # Line 5: > diff( c(0,tigol( c(-0.4961,0.6907) - 0.5663922 + 0.5723552 ), 1) ) [1] 0.3798613 0.2875862 0.3325525 > - -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html