Re: [R] class export in package creation / setClass / namespace?
> "MartinMo" == Martin Morgan > on Mon, 20 Jul 2009 18:57:33 -0700 writes: MartinMo> L L writes: >> Ok, I could solve also the latter problem by defining show.myclass function in >> the zzz.R file and adding the line 'S3method(show,myclass)' into NAMESPACE >> file. Now the package passes all checks. MartinMo> I would have, in NAMESPACE, MartinMo> importFrom(methods, show) MartinMo> exportMethods(show) MartinMo> and in some file in R/ MartinMo> setMethod(show, "myclass", function(object) { MartinMo> cat("here I am\n") MartinMo> }) MartinMo> Do not try to make an S3 method on an S4 generic, MartinMo> or to create a new S4 generic for show. Since MartinMo> you've defined a method on show, you need to add MartinMo> documentation in a file in man/ (your choice; I'd MartinMo> add the documentation to the myclass documentation MartinMo> page). You only get one MartinMo> \alias{show,myclass-method}. MartinMo> Martin Yes, indeed! I'm just ``signing'' Martin Morgan's very good advice. In case it was explicit enough: do *NOT* define show.myclass() [which is an S3 method for an S4 generic and S4 class ..] Martin Mächler >> The information on how to exactly extend existing methods and include new >> methods/classes into a package is available but rather scattered in the web. A >> step-by-step tutorial written by an experienced user who is aware of best >> practices etc. would be rather useful for a beginner. >> best regards >> Leo >> >> >> On Mon, Jul 20, 2009 at 7:09 PM, L L <[[lmla...@gmail.com]]> wrote: >> >> Thanks, the issue was solved by adding class definitions to the >> zzz.R file in the R code directory. However, this led to a new >> problem. >> The zzz.R now contains class definition: >> > setClass("myclass", contains = "list") >> and method definition for the new class, extending the generic >> show': >> > setGeneric("show",function(x,...){standardGeneric("show")}) > >> setMethod("show", "myclass",function(x, ...) {cat("myclass object >> \n")}) >> I get two warnings. The first one: >> * checking Rd files ... WARNING Rd files with duplicated alias >> show,myclass-method': myclass-class.Rd show-methods.Rd >> I get this one because the alias row for the method >> (\alias{show,myclass-method}) is in both myclass-class.Rd file and >> show-methods.Rd file (created by promptMethods function). This is >> likely related to the second warning: >> * checking for missing documentation entries ... WARNING Undocumented >> code objects: show >> I thought that the show method would've been documented correctly as >> I put 'show-methods.Rd' file in the 'man' directory. This does not >> seem to be the case, however. >> Any help on how I should document the extended show method in this >> case, or are there some mistakes in my original definition for >> extended 'show'? I could not find suitable examples from the >> web/mailing lists. >> br Leo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] heatmap plot
2009/7/21 Markus Mühlbacher : > So just that I understand right. x and y are the scalings of the x and y axis > and the matrix represents the color of the points at each gridpoint? Precisely! Try ?image for more details. -- Michael Knudsen micknud...@gmail.com http://lifeofknudsen.blogspot.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] legend title in qplot
Hi, I've used the following command in qplot qplot(a$V1,geom="histogram",binwidth=0.15,fill = factor(a$V2),ylab="Frequency",xlab="Rate"); but the title in the legend shows up as factor(a$V2)...how can i change this? -- Rajesh.J [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Another SEM question
Hi, [,1] [,2] [,3] [1,] 4.820719e-03 -5.558801e-05 -5.718939e-05 [2,] -5.558801e-05 4.763194e-06 -7.661872e-06 [3,] -5.718939e-05 -7.661872e-06 1.662150e-03 This is mod.cov. It is the covariance matrix of (R, I, M). R, I and M are vectors of length 109 which are contained in the file data4.csv. As far as I understood the package sem. I consider R, I and M as the external veriables and Z as the latent variable which I will receive as an result after calculating the estimated errors and parameters. This is what atually is missing in the output. Moreover, the output provides the information about the quality of the fitted model. I have to admit that this model does not fit quite well. Nevertheless, it should provide the estimated errors like it does just for the first variable Z ->M. Thanks a lot for your help, Luba -Urspr?ngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Jarrett Byrnes Gesendet: Dienstag, 21. Juli 2009 08:19 An: Stein, Luba (AIM SE) Cc: r-help@r-project.org Betreff: Re: [R] Another SEM question You don't appear to be defining Z here. Might that be the problem? Or, I, M, and R may not be defined either. It is unclear. What does mod.cov look like? On Jul 20, 2009, at 11:11 PM, Stein, Luba (AIM SE) wrote: > Thank you for your advice. So I am sending the whole code > > data.dir <- file.path(home.dir, "Data") > file <- file.path(data.dir, "data4.csv") > > SEM <- read.csv(file) > print(SEM) > > library(sem) > SEM1 <- as.matrix(cbind(SEM$R1, SEM$I1, SEM$M1)) > print(SEM1) > mod.cov <- cov(SEM1) > print(mod.cov) > > I <- SEM$I1 > M <- SEM$M1 > R <- SEM$R1 > > model <- specify.model() > Z -> M > Z -> I > Z -> R > M <-> M > I <-> I > R <-> R > Z <-> Z > > sem.mod <- sem(model, mod.cov, N=109) > summary(sem.mod) > > > > All vectors have a length of 109. > > > Thank you for your help once again. > > Best wishes, > Luba > > > > -Urspr?ngliche Nachricht- > Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] Im Auftrag von Jarrett Byrnes > Gesendet: Montag, 20. Juli 2009 18:25 > An: Stein, Luba (AIM SE) > Cc: r-help@r-project.org > Betreff: Re: [R] Another SEM question > > Luba, > > If you could provide the code you ran, perhaps the listserv can be of > help. > > On Jul 20, 2009, at 7:55 AM, Stein, Luba (AIM SE) wrote: > >> Hello, >> >> I use the function sem the following way >> sem.mod <- sem(model, mod.cov, N=109) where the variables are >> modelled: >> >> Z -> M >> Z -> I >> Z -> R >> M <-> M >> I <-> I >> R <-> R >> Z <-> Z >> >> The output is >> ... >> >> Normalized Residuals >> Min. 1st Qu. Median Mean 3rd Qu. Max. >> -7.3300 -0.2750 -0.2670 -0.1290 -0.0369 9.0300 >> >> Parameter Estimates >> Estimate Std Error z value Pr(>|z|) >> 0.0021625 0.00017037 12.693 0 M <--- Z >> >> Iterations = 13 >> >> >> In "Structural Equation Modeling With the sem Package in R" by John >> Fox is stated that there should be an output for each external >> variable. >> >> Where is my fault, that I receive the output only for the first >> variable? >> >> >> Thanks for your help, >> Luba >> >> >> >> >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] new package 'dlnm' to run distributed lag non-linear models
Dear R Community, I am pleased to announce the release of a new package called 'dlnm', now available on CRAN (version 0.2.1). The package dlnm provides some facilities to run distributed lag models (DLM's) and their non-linear extension (DLNM's), a modelling framework to describe simultaneously non-linear and delayed effects between predictors and an outcome in time-series data. The package includes a vignette giving an extended overview of its capabilities together with the theory underlying DLNM's, including an detailed summary of the functions and some examples of application to real data, in order to get new users started easily. I hope that this package will be useful to your work. Any kind of feedback (questions, suggestions, bug-reports, etc.) is appreciated. Sincerely, Antonio Gasparrini Public and Environmental Health Research Unit (PEHRU) London School of Hygiene & Tropical Medicine Keppel Street, London WC1E 7HT, UK Office: 0044 (0)20 79272406 - Mobile: 0044 (0)79 64925523 Skype contact: a.gasparrini http://www.lshtm.ac.uk/people/gasparrini.antonio ( http://www.lshtm.ac.uk/pehru/ ) [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Another SEM question
You don't appear to be defining Z here. Might that be the problem? Or, I, M, and R may not be defined either. It is unclear. What does mod.cov look like? On Jul 20, 2009, at 11:11 PM, Stein, Luba (AIM SE) wrote: Thank you for your advice. So I am sending the whole code data.dir <- file.path(home.dir, "Data") file <- file.path(data.dir, "data4.csv") SEM <- read.csv(file) print(SEM) library(sem) SEM1 <- as.matrix(cbind(SEM$R1, SEM$I1, SEM$M1)) print(SEM1) mod.cov <- cov(SEM1) print(mod.cov) I <- SEM$I1 M <- SEM$M1 R <- SEM$R1 model <- specify.model() Z -> M Z -> I Z -> R M <-> M I <-> I R <-> R Z <-> Z sem.mod <- sem(model, mod.cov, N=109) summary(sem.mod) All vectors have a length of 109. Thank you for your help once again. Best wishes, Luba -Urspr?ngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] Im Auftrag von Jarrett Byrnes Gesendet: Montag, 20. Juli 2009 18:25 An: Stein, Luba (AIM SE) Cc: r-help@r-project.org Betreff: Re: [R] Another SEM question Luba, If you could provide the code you ran, perhaps the listserv can be of help. On Jul 20, 2009, at 7:55 AM, Stein, Luba (AIM SE) wrote: Hello, I use the function sem the following way sem.mod <- sem(model, mod.cov, N=109) where the variables are modelled: Z -> M Z -> I Z -> R M <-> M I <-> I R <-> R Z <-> Z The output is ... Normalized Residuals Min. 1st Qu. Median Mean 3rd Qu. Max. -7.3300 -0.2750 -0.2670 -0.1290 -0.0369 9.0300 Parameter Estimates Estimate Std Error z value Pr(>|z|) 0.0021625 0.00017037 12.693 0 M <--- Z Iterations = 13 In "Structural Equation Modeling With the sem Package in R" by John Fox is stated that there should be an output for each external variable. Where is my fault, that I receive the output only for the first variable? Thanks for your help, Luba [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Another SEM question
Thank you for your advice. So I am sending the whole code data.dir <- file.path(home.dir, "Data") file <- file.path(data.dir, "data4.csv") SEM <- read.csv(file) print(SEM) library(sem) SEM1 <- as.matrix(cbind(SEM$R1, SEM$I1, SEM$M1)) print(SEM1) mod.cov <- cov(SEM1) print(mod.cov) I <- SEM$I1 M <- SEM$M1 R <- SEM$R1 model <- specify.model() Z -> M Z -> I Z -> R M <-> M I <-> I R <-> R Z <-> Z sem.mod <- sem(model, mod.cov, N=109) summary(sem.mod) All vectors have a length of 109. Thank you for your help once again. Best wishes, Luba -Urspr?ngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Jarrett Byrnes Gesendet: Montag, 20. Juli 2009 18:25 An: Stein, Luba (AIM SE) Cc: r-help@r-project.org Betreff: Re: [R] Another SEM question Luba, If you could provide the code you ran, perhaps the listserv can be of help. On Jul 20, 2009, at 7:55 AM, Stein, Luba (AIM SE) wrote: > Hello, > > I use the function sem the following way > sem.mod <- sem(model, mod.cov, N=109) where the variables are > modelled: > > Z -> M > Z -> I > Z -> R > M <-> M > I <-> I > R <-> R > Z <-> Z > > The output is > ... > > Normalized Residuals > Min. 1st Qu. Median Mean 3rd Qu. Max. > -7.3300 -0.2750 -0.2670 -0.1290 -0.0369 9.0300 > > Parameter Estimates > Estimate Std Error z value Pr(>|z|) > 0.0021625 0.00017037 12.693 0 M <--- Z > > Iterations = 13 > > > In "Structural Equation Modeling With the sem Package in R" by John > Fox is stated that there should be an output for each external > variable. > > Where is my fault, that I receive the output only for the first > variable? > > > Thanks for your help, > Luba > > > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simulate residuals with different properties for a linear model (regression)
Thank you both for your responses and the hints for help! Greetings, Friedericksen Friedericksen Hope wrote: Hey guys, for educational purposes I wonder if it is possible to simulate different data sets (or specifically residuals) for a linear regression. I would like to show my students residuals with different means, variances and distributions (normal, but also not normal) in the plots created with the plot command for a lm-object. In addition it would be nice to simulate although influencal values (high cooks distance and leverage) lm.results <- lm(y~x,data) plot(lm.results) Is there an easy way to do this? Or can this be done at all (and if yes, any hints?:-) Thanks and Greetings! Friedericksen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Show representation of a data structure
I'm currently working with some large complex data structures eg list of lists of data_frames containing lots more variables and lists etc. Sometimes, I'd like to be able to bring up a simple representation of the structure I'm working with, minus all of the values it contains (so simply printing the variable doesn't work as its too hard to see structure when there are 1000s of values being printed). I know there is a function in R that allows you to do something like this but I cannot remember what it is and my searching has turned up nothing. Does anyone know the function I'm talking about or have any other useful suggestions as to what I can do? Thanks -- View this message in context: http://www.nabble.com/Show-representation-of-a-data-structure-tp24581814p24581814.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re gression for loop test HELP! URGENT!
Hi, first, your initial statement of what you wanted to do was obviously ambiguous enough to confuse the responders. Therefore, clarity helps greatly in getting an accurate response. If I understand correctly, you have run ONE model on whatever data (also often called testing sample). Now you want to assess how well this ONE estimate derived from the testing sample predicts data from five (or any other arbitrary number of) holdout samples. In order to do that, the example I have provided works perfectly fine. The only thing you do not do is run multiple regressions in the first place. Instead you run only one initial regression on the testing sample and predict into the holdout samples. This, however, is only a slight change of the procedure I have outlined. The fit to the holdout samples is assessed with measures that any statistics/econometrics book deals with if it has a section on prediction. Best, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Rbeginner Gesendet: Monday, July 20, 2009 10:50 PM An: r-help@r-project.org Betreff: Re: [R] Re gression for loop test HELP! URGENT! I think the problem is that I've been getting replies about how to make new regressions, when in fact, I need to use the one I've produced already to fit new data, 5 rows at a time, to see if it is also a good representation of further data. From the replies, I'm getting the impression that the only way I can do that is bye producing more regressions and calculating the error, but I'm not sure how I should do that, if I get hundreds of new regressions. I'm thinking, in my primitive programming terms, that I should ask the system to run through the new data 5 rows at a time and produce some indication of deviation (error) from the original regression, which would help me decide whether the original regression is is a good representation of the new data. Does this make sense? fm <- lm(M ~ D + O + S)#this is my original regression, and I need to use this to fit the test data. test = data.frame(Mtest,Dtest,Otest,Stest) #data frame of the test data attach(test) for (i in 1:1184){ fmtest <- lm(Mtest ~ Dtest + Otest + Stest, subset=(1:5), data=test) print(summary(fmtest)) } #this would only produce a long string of summaries. My data is in the form of M D OS 1 2 ... 1184 Any suggestions? Richard Cotton wrote: > >> I'm new to R, and I've sent this message as a non-member, but since >> it's pretty urgent, I'm sending it again now I'm on the mailing list >> (Thanks Daniel for your suggestion nevertheless). >> >> I have calculated a regression in the form of M ~ D + O + S, and I >> would like to take this regression and test it with other samples, 5 >> sets of > M, D, >> O, and S at a time(I actually have 2000 sets, so it's probably not > efficient >> to make each a separate set and then index). Since I'll need to test >> the regression for 400 groups, I thought a for loop might be >> necessary. I've > put >> everything into a data frame already. Can anyone tell me how to write > the >> code? I'm especially not sure about how to do the for loop. >> And then how would I calculate the error of how well the test samples > fit >> the original regression? >> This is for my internship, so it's very urgent. > > Take a deep breath, and think calm thoughts. Take a look at the > posting guide (http://www.r-project.org/posting-guide.html) - it has > useful ideas on thinking through your problem. If you can provide > some code then we can see what you want more clearly. > > Show us how you've done your regression what form your data is in. > Tell us which tests you'd like to do on the samples. > > If you are stuck with for loops, then take a look at section 9.2.2 in > the Intro to R guide that comes with R. (Click Help -> Manuals -> an > Introduction to R in RGui.) > > Regards, > Richie. > > Mathematical Sciences Unit > HSL > > > -- > -- > ATTENTION: > > This message contains privileged and confidential > inform...{{dropped:22}} > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > - > Regards, > Richie. > > Mathematical Sciences Unit > HSL > -- View this message in context: http://www.nabble.com/Regression-for-loop-test-HELP%21-URGENT%21-tp24564236p 24580889.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/po
[R] geom_histogram help
Hi, I have a histogram.But I need seperate colours for fixed range of values.for eg. between 2-3 on the x axis a colour.3-4 another colour etc. and the legend has to say what each colour is.How can this be done in geom_histogram? -- Rajesh.J [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to change the "quantile" method in bwplot
Hi, everyone, Since quantile calculation has nine different methods in R, I wonder how I specify a method when calling the bwplot() in lattice. I couldn't find any information in the documentation. Thanks. -- Jun Shen PhD PK/PD Scientist BioPharma Services Millipore Corporation 15 Research Park Dr. St Charles, MO 63304 Direct: 636-720-1589 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] clim.pact question (annual cycle removal)
I'm using the clim.pact package, I'm particularly interested in the EOF computation. I've noticed that whether I used the option to remove the annual cycle or not I get the same results. Am I missing something or the option hasn't been implemented yet? Thank you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re gression for loop test HELP! URGENT!
Hi, I think the problem is that I've been getting replies about how to make new regressions, when in fact, I need to use the one I've produced already to fit new data, 5 rows at a time, to see if it is also a good representation of further data. From the replies, I'm getting the impression that the only way I can do that is bye producing more regressions and calculating the error, but I'm not sure how I should do that, if I get hundreds of new regressions. So ... I haven't read the replies in this thread, but I'd be surprised if you haven't been directed to the "predict" function. The call to "lm" will return you an object of class "lm". Calling "predict" on that object on *new* data will actually call the predict.lm function, and does exactly what it seems like you're asking to do, which is to "fit new data." I think having a look through the documentation in ?predict.lm should make this clear, no? Is this what you're after? HTH, -steve -- Steve Lianoglou Graduate Student: Physiology, Biophysics and Systems Biology Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re gression for loop test HELP! URGENT!
I think the problem is that I've been getting replies about how to make new regressions, when in fact, I need to use the one I've produced already to fit new data, 5 rows at a time, to see if it is also a good representation of further data. From the replies, I'm getting the impression that the only way I can do that is bye producing more regressions and calculating the error, but I'm not sure how I should do that, if I get hundreds of new regressions. I'm thinking, in my primitive programming terms, that I should ask the system to run through the new data 5 rows at a time and produce some indication of deviation (error) from the original regression, which would help me decide whether the original regression is is a good representation of the new data. Does this make sense? fm <- lm(M ~ D + O + S)#this is my original regression, and I need to use this to fit the test data. test = data.frame(Mtest,Dtest,Otest,Stest) #data frame of the test data attach(test) for (i in 1:1184){ fmtest <- lm(Mtest ~ Dtest + Otest + Stest, subset=(1:5), data=test) print(summary(fmtest)) } #this would only produce a long string of summaries. My data is in the form of M D OS 1 2 ... 1184 Any suggestions? Richard Cotton wrote: > >> I'm new to R, and I've sent this message as a non-member, but since it's >> pretty urgent, I'm sending it again now I'm on the mailing list (Thanks >> Daniel for your suggestion nevertheless). >> >> I have calculated a regression in the form of M ~ D + O + S, and I would >> like to take this regression and test it with other samples, 5 sets of > M, D, >> O, and S at a time(I actually have 2000 sets, so it's probably not > efficient >> to make each a separate set and then index). Since I'll need to test the >> regression for 400 groups, I thought a for loop might be necessary. I've > put >> everything into a data frame already. Can anyone tell me how to write > the >> code? I'm especially not sure about how to do the for loop. >> And then how would I calculate the error of how well the test samples > fit >> the original regression? >> This is for my internship, so it's very urgent. > > Take a deep breath, and think calm thoughts. Take a look at the posting > guide (http://www.r-project.org/posting-guide.html) - it has useful ideas > on thinking through your problem. If you can provide some code then we > can see what you want more clearly. > > Show us how you've done your regression what form your data is in. Tell > us which tests you'd like to do on the samples. > > If you are stuck with for loops, then take a look at section 9.2.2 in the > Intro to R guide that comes with R. (Click Help -> Manuals -> an > Introduction to R in RGui.) > > Regards, > Richie. > > Mathematical Sciences Unit > HSL > > > > ATTENTION: > > This message contains privileged and confidential inform...{{dropped:22}} > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > > - > Regards, > Richie. > > Mathematical Sciences Unit > HSL > -- View this message in context: http://www.nabble.com/Regression-for-loop-test-HELP%21-URGENT%21-tp24564236p24580889.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simulate residuals with different properties for a linear model (regression)
> for educational purposes I wonder if it is possible to simulate > different data sets (or specifically residuals) for a linear regression. > I would like to show my students residuals with different means, > variances and distributions (normal, but also not normal) in the plots > created with the plot command for a lm-object. In addition it would be > nice to simulate although influencal values (high cooks distance and > leverage) > > lm.results <- lm(y~x,data) > plot(lm.results) > > Is there an easy way to do this? Or can this be done at all (and if yes, > any hints?:-) Check out some neat ideas here: http://www4.stat.ncsu.edu/~stefanski/NSF_Supported/Hidden_Images/stat_res_plots.html Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re gression for loop test HELP! URGENT!
Thanks Dr. Zuur for your reply. I've followed your suggestion, but it seems that this would only produce more regressions instead of use the one I produced originally to see if the original regression would fit new data? Is error analysis the only way i can make this happen? And how should I write it within the loop so that 5 rows can be iterated every time? Alain Zuur wrote: > > > Rbeginner wrote: >> >> Hi everyone! >> I'm new to R, and I've sent this message as a non-member, but since it's >> pretty urgent, I'm sending it again now I'm on the mailing list (Thanks >> Daniel for your suggestion nevertheless). >> >> I have calculated a regression in the form of M ~ D + O + S, and I would >> like to take this regression and test it with other samples, 5 sets of M, >> D, >> O, and S at a time(I actually have 2000 sets, so it's probably not >> efficient >> to make each a separate set and then index). Since I'll need to test the >> regression for 400 groups, I thought a for loop might be necessary. I've >> put >> everything into a data frame already. Can anyone tell me how to write the >> code? I'm especially not sure about how to do the for loop. >> And then how would I calculate the error of how well the test samples fit >> the original regression? >> This is for my internship, so it's very urgent. >> >> >> >> >> One option (out of the many): >> >> for (i in 1:2000) { >> >> M <- lm(M ~ D + O + S, subset = blah blah, data = YourData) >> print(summary(M)) >> } >> >> The "blah blah" select your rows of data for iteration i. >> >> See also: >> >> A Beginner's Guide to R (2009). Zuur, Ieno, Meesters. >> >> for something very similar. You can dump everything in a text file, or >> just extract the required info from the summary function (like R^2 etc). >> >> Alain >> >> >> Dr. Alain F. Zuur >> First author of: >> >> 1. Analysing Ecological Data (2007). >> Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p. >> >> 2. Mixed effects models and extensions in ecology with R. (2009). >> Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer. >> >> 3. A Beginner's Guide to R (2009). >> Zuur, AF, Ieno, EN, Meesters, EHWG. Springer >> >> >> >> >> >> >> >> >> >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> > > -- View this message in context: http://www.nabble.com/Regression-for-loop-test-HELP%21-URGENT%21-tp24564236p24580748.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] class export in package creation / setClass / namespace?
L L writes: > Ok, I could solve also the latter problem by defining show.myclass function in > the zzz.R file and adding the line 'S3method(show,myclass)' into NAMESPACE > file. Now the package passes all checks. I would have, in NAMESPACE, importFrom(methods, show) exportMethods(show) and in some file in R/ setMethod(show, "myclass", function(object) { cat("here I am\n") }) Do not try to make an S3 method on an S4 generic, or to create a new S4 generic for show. Since you've defined a method on show, you need to add documentation in a file in man/ (your choice; I'd add the documentation to the myclass documentation page). You only get one \alias{show,myclass-method}. Martin > The information on how to exactly extend existing methods and include new > methods/classes into a package is available but rather scattered in the web. A > step-by-step tutorial written by an experienced user who is aware of best > practices etc. would be rather useful for a beginner. > best regards > Leo > > > On Mon, Jul 20, 2009 at 7:09 PM, L L <[[lmla...@gmail.com]]> wrote: > > Thanks, the issue was solved by adding class definitions to the > zzz.R file in the R code directory. However, this led to a new > problem. > The zzz.R now contains class definition: > > setClass("myclass", contains = "list") > and method definition for the new class, extending the generic > show': > > setGeneric("show",function(x,...){standardGeneric("show")}) > > setMethod("show", "myclass",function(x, ...) {cat("myclass object > \n")}) > I get two warnings. The first one: > * checking Rd files ... WARNING Rd files with duplicated alias > show,myclass-method': myclass-class.Rd show-methods.Rd > I get this one because the alias row for the method > (\alias{show,myclass-method}) is in both myclass-class.Rd file and > show-methods.Rd file (created by promptMethods function). This is > likely related to the second warning: > * checking for missing documentation entries ... WARNING Undocumented > code objects: show > I thought that the show method would've been documented correctly as > I put 'show-methods.Rd' file in the 'man' directory. This does not > seem to be the case, however. > Any help on how I should document the extended show method in this > case, or are there some mistakes in my original definition for > extended 'show'? I could not find suitable examples from the > web/mailing lists. > br Leo > > > > > > On Fri, Jul 10, 2009 at 5:37 AM, Martin Morgan > <[[mtmor...@fhcrc.org]]> wrote: > > L L wrote: > Dear all, > > > > I have been trying to create an R package. This has been > successfull until I > tried to define classes. > > > > Currently, my procedure is the following: > > > Start R, load the function and class definition >> > tmp <- function (x) {x} >> setClass("rpa", > contains = "list", where=topenv(parent.frame())) > > > > Use package skeleton to create directory structure: >> > package.skeleton(name = "test",list=c("tmp")) > > > > I don't think package.skeleton knows to copy the class > definition to the R files; I think you have to do > that yourself -- is there a setClass("rpa", > contains="list") instruction in the R files created by > package.skeleton? > Martin > > > > Edit man files, add test/NAMESPACE > file with the following contents: >> export(tmp) > >> > exportClasses("rpa") > > Use R CMD check > and R CMD build to create tarball. > -> No error > messages. > > Start R, install the > created package: >> > install.packages("test_1.0.tar.gz",repos=NULL) > > > Test the new package: >> require(test) >> > my.object = new("rpa") > > This gives > the error message >> Error in getClass(Class, > where = topenv(parent.frame())) : >> "rpa" is not > a defined class > > Any tips on how to > define and export global classes in package creation? > > > > I also tried > - to replace the > topenv(parent.frame())' with '.GlobalEnv' in setClass. > > - place the setClass within function 'tmp' > - > exportClasses(rpa
Re: [R] Re al Time PCR data analysis help
I have looked at the package .it won't work for me since it requies us to read files with the format : The text file must have the following structure: 1st column = names denoting genes or primer pairs 2nd column = plate index of each gene or primer pair remaining columns = (replicate) Ct values. In my case the data I have is like following: WellSample Name DetectorTaskCt StdDev Ct Qty Mean QtyStdDev Qty Filtered Tm User Defined #1 User Defined #2 User Defined #3 A1 4490ADORA2A Unknown 27.5961 0.236 A2 4490ADORA2A Unknown 27.1953 0.236 A3 4490ADORA2A Unknown 27.6102 0.236 A4 5775ADORA2A Unknown 31.3386 0.296 Andrej Kastrin-3 wrote: > > Check out qpcR package. > > Andrej > > gauravbhatti wrote: >> Hi I need help since I have never worked on RT PCR data before . I have >> 8 >> data files each corresponding to a single pcr run. Each file also >> represent >> 10 samples(5 cancer and 5 healthy) belonging to a unique gene. I have 7 >> unique genes and 1 reference (total 8 files). Can any body help me with >> preproceesing and normalization? > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- View this message in context: http://www.nabble.com/Real-Time-PCR-data-analysis-help-tp24577344p24580247.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fama-Macbeth regression in R
Dear all. currently, i have been studied cross-sectional regression. how to conduct cross-sectional regression by using R. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Correction.
It has been pointed out to me that I erred in an earlier post. ``Go stick your head in a pig.'' is not the motto of the (entire) Sirius Cybernetics Corporation. It is the motto if the Sirius Cybernetics Corporation ***Complaints Division***. My apologies for the misinformation. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 frame from list of lists with unequal lengths
Try this: r <- strsplit(as.character(x$v1), "/") cbind(unlist(r), rep(x$v2, sapply(r, length))) On Mon, Jul 20, 2009 at 5:46 PM, Ben Mazzotta wrote: > Hello, > > I have a dataset with multiple entries in one field separated by "/" > characters. (The true dataset has long names, 20-odd variables, and > hundreds of observations.) > > > v1 v2 > 1 A L > 2 A/B M > 3 C N > 4 D/E/F O > 5 A P > 6 C L > > > What I would like is to have a dataset that looks like this instead: > > > my.df > v1 v2 > 1 A L > 2 A M > 3 B M > 4 C N > 5 D O > 6 E O > 7 F O > 8 A P > 9 C L > > > My original thought was to break the string into variables using > strsplit(), create new columns in the data frame using cbind(), and then > reshape the dataset with the melt() function. > > > v1.new <- as.character(my.df$v1) > > v1.new <- strsplit(v1.new, "/") > > v1.new > [[1]] > [1] "A" > > [[2]] > [1] "A" "B" > > [[3]] > [1] "C" > > [[4]] > [1] "D" "E" "F" > > [[5]] > [1] "A" > > [[6]] > [1] "C" > > My next thought was to coerce the list into a data frame, but I ran > into an error because the list output from strsplit() does not contain > equal length vectors. > > > v1.cols <- data.frame(v1.new, check.rows=FALSE) > Error in data.frame("A", c("A", "B"), "C", c("D", "E", "F"), "A", "C", : > arguments imply differing number of rows: 1, 2, 3 > > > How can I create a data frame from the unequal length vectors that > result from strsplit(my.df$v1)? > > Am I going about this the wrong way? I have also tried to use > colsplit{reshape} without success. > > Thank you for any advice you can offer. I hope the answer to this > question is not too obvious. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R package creation: 'show' extension not imported correctly
On 20/07/2009 7:53 PM, L L wrote: Dear List, I have a problem related to R package creation. I extended the 'show' method to cover a new class with the following lines in the zzz.R file in the R directory while creating an R package. setClass("rpa", contains="list") show.rpa <- function (...) {cat("rpa object \n")} The corresponding lines were also added to NAMESPACE file: importMethodsFrom(methods,show) exportClasses(rpa) S3method(show,rpa) The CMD check and CMD build do not produce warning messages related to this issue (only warnings are about missing .Rd files). After installing the package ('test' is the package name) I start R and require the new package: require(test) Loading required package: test Warning message: found an S4 version of 'show' so it has not been imported correctly So it seems that the show method is S4 version although in the package definition it is an S3 version. I would prefer not defining an S4 version for show at this point, the main goal at the moment is simply to get the package working and S3 seems to provide a quick-and-dirty way for this. Any solutions / workarounds would be appreciated. If you only want to use S3, then don't use setClass (or anything else in the methods package). If you're using setClass, use setMethod to define an S4 method. I don't know if methods makes an attempt to support mixed styles as you used, but it really looks like a bad idea. Duncan Murdoch thanks in advance Leo [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R package creation: 'show' extension not imported correctly
Dear List, I have a problem related to R package creation. I extended the 'show' method to cover a new class with the following lines in the zzz.R file in the R directory while creating an R package. >setClass("rpa", contains="list") >show.rpa <- function (...) {cat("rpa object \n")} The corresponding lines were also added to NAMESPACE file: >importMethodsFrom(methods,show) >exportClasses(rpa) >S3method(show,rpa) The CMD check and CMD build do not produce warning messages related to this issue (only warnings are about missing .Rd files). After installing the package ('test' is the package name) I start R and require the new package: > require(test) Loading required package: test Warning message: found an S4 version of 'show' so it has not been imported correctly So it seems that the show method is S4 version although in the package definition it is an S3 version. I would prefer not defining an S4 version for show at this point, the main goal at the moment is simply to get the package working and S3 seems to provide a quick-and-dirty way for this. Any solutions / workarounds would be appreciated. thanks in advance Leo [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Accessing list object from within a function as a list element
Hi - I have a list (call it 'mylist') with the following elements: (i) a function (call it 'myfunc' and expressed as 'mylist$myfunc') and (ii) a variable (call it 'myvar' and expressed as 'mylist$myvar'). Since I use mylist as a pseudo-class (I assign mylist to multiple different R objects), I would like to access the mylist R object from within the 'myfunc' function to use 'myvar.' Here is a simple example: mylist <- list(); mylist$myvar <- "~/file.out"; mylist$myfunc <- function (mymsg="hello world") { cat(mymsg,mylist$myvar); }; If I perform the following: myclassobj_1 <- myclassobj_2 <- myclassobj_3 <- mylist; myclassobj_1 <- "~/file_1.out"; myclassobj_2 <- "~/file_2.out"; myclassobj_3 <- "~/file_3.out"; I cannot use myclassobj_1$myfunc() as it will place "hello world" into "~/file.out" instead of "~/file_1.out." Unless I want to make the myclassobj_? lists an argument to the 'myfunc' function, I need an object reference to the appropriate 'mylist.' For instance: mylist$myfunc <- function (mymsg="hello world") { objref <- ; cat(mymsg,objref$myvar); }; I had some success with the sys.call() function, though the implementation is sloppy and inconsistent as it relies on the environment frame in which the call is made as opposed to an attribute of the 'myfunc' function. Any suggestions as to this specific issue or preferred implementation of user-defined classes in R? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] class export in package creation / setClass / namespace?
Ok, I could solve also the latter problem by defining show.myclass function in the zzz.R file and adding the line 'S3method(show,myclass)' into NAMESPACE file. Now the package passes all checks. The information on how to exactly extend existing methods and include new methods/classes into a package is available but rather scattered in the web. A step-by-step tutorial written by an experienced user who is aware of best practices etc. would be rather useful for a beginner. best regards Leo On Mon, Jul 20, 2009 at 7:09 PM, L L wrote: > Thanks, the issue was solved by adding class definitions to the zzz.R file > in the R code directory. However, this led to a new problem. > > The zzz.R now contains class definition: > > > setClass("myclass", contains = "list") > > and method definition for the new class, extending the generic 'show': > > > setGeneric("show",function(x,...){standardGeneric("show")}) > > setMethod("show", "myclass",function(x, ...) {cat("myclass object \n")}) > > I get two warnings. The first one: > > * checking Rd files ... WARNING > Rd files with duplicated alias 'show,myclass-method': > myclass-class.Rd show-methods.Rd > > I get this one because the alias row for the method > (\alias{show,myclass-method}) is in both myclass-class.Rd file and > show-methods.Rd file (created by promptMethods function). This is likely > related to the second warning: > > * checking for missing documentation entries ... WARNING > Undocumented code objects: > show > > I thought that the show method would've been documented correctly as I put > 'show-methods.Rd' file in the 'man' directory. This does not seem to be the > case, however. > > Any help on how I should document the extended show method in this case, or > are there some mistakes in my original definition for extended 'show'? I > could not find suitable examples from the web/mailing lists. > > br > Leo > > > > On Fri, Jul 10, 2009 at 5:37 AM, Martin Morgan wrote: > >> L L wrote: >> > Dear all, >> > >> > I have been trying to create an R package. This has been successfull >> until I >> > tried to define classes. >> > >> > Currently, my procedure is the following: >> > >> > Start R, load the function and class definition >> >> tmp <- function (x) {x} >> >> setClass("rpa", contains = "list", where=topenv(parent.frame())) >> > >> > Use package skeleton to create directory structure: >> >> package.skeleton(name = "test",list=c("tmp")) >> >> I don't think package.skeleton knows to copy the class definition to the >> R files; I think you have to do that yourself -- is there a >> setClass("rpa", contains="list") instruction in the R files created by >> package.skeleton? >> >> Martin >> > >> > Edit man files, add test/NAMESPACE file with the following contents: >> >> export(tmp) >> >> exportClasses("rpa") >> > >> > Use R CMD check and R CMD build to create tarball. >> > -> No error messages. >> > >> > Start R, install the created package: >> >> install.packages("test_1.0.tar.gz",repos=NULL) >> > >> > Test the new package: >> >> require(test) >> >> my.object = new("rpa") >> > >> > This gives the error message >> >> Error in getClass(Class, where = topenv(parent.frame())) : >> >> "rpa" is not a defined class >> > >> > Any tips on how to define and export global classes in package creation? >> > >> > I also tried >> > - to replace the 'topenv(parent.frame())' with '.GlobalEnv' in setClass. >> > - place the setClass within function 'tmp' >> > - exportClasses(rpa) in the namespace (without suffixes "") >> > >> > I paged through the related mailing list discussions but could not find >> a >> > solution. Any tips and tricks would be worthwhile now; I guess this >> should >> > be a standard issue but it seems a bit tricky to come up with a quick >> > solution with the little programming experience that I have. >> > >> > kind regards >> > Leo Lahti >> > >> > [[alternative HTML version deleted]] >> > >> > __ >> > R-help@r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> >> > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] S_alloc or Calloc for return value
On 20 July 2009 at 16:06, Dan Kelley wrote: | I am trying to write a C function to create a vector of integers that can be | used by the R calling function. I do not know the size of the vector in the | R calling function. (Well, actually, I have an upper limit on the size, but | that is so large that R cannot allocate it. What I'm doing in the function | is to do a sieving procedure, and the result will be small enough to fit | into my machine's memory.) | | My reading of sections 6.1.1 and 6.1.2 of the guide on writing R extensions | has left me a bit confused. Under R_alloc, I read "R will reclaim the | memory at the end of the call" which seems to suggest the storage won't be | made available afterwards, so that's not what I should use. As for the | alterntaive, under Calloc, I read "This memory lasts until freed by the | user", and it's clear that this is to be done within the C function in | question. | | Summary question: how can I allocate memory withing a C function, making it | available to an R function that calls the C function? You want R_alloc(). Here, "end of the call" is the call of the R function that calls your C function. This is what you want---the data will be available for the caller of your C code. FWIW R_alloc() is also the only allocation function used in Rcpp (which provides an interface between R and C++). Hth, Dirk -- Three out of two people have difficulties with fractions. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simulate residuals with different properties for a linear model (regression)
Here are a couple of examples. # residuals not normal n <- 100; x = seq(n) y = 10 + 10 *x + 20 * rchisq(n,df=2) non_normal_lm = lm(y~x) #non-constant variance n <- 100; x = seq(n) y = 100 + 3 * x + rnorm(n,0,3) * x; het_var_lm = lm(y~x) #For each of these try: plot(non_normal_lm) plot(het_var_lm) #or specify which one you want plot(non_normal_lm,which=1) Best, Juliet On Mon, Jul 20, 2009 at 2:16 PM, Friedericksen Hope wrote: > Hey guys, > > for educational purposes I wonder if it is possible to simulate > different data sets (or specifically residuals) for a linear regression. > I would like to show my students residuals with different means, > variances and distributions (normal, but also not normal) in the plots > created with the plot command for a lm-object. In addition it would be > nice to simulate although influencal values (high cooks distance and > leverage) > > lm.results <- lm(y~x,data) > plot(lm.results) > > Is there an easy way to do this? Or can this be done at all (and if yes, > any hints?:-) > > Thanks and Greetings! > Friedericksen > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] S_alloc or Calloc for return value
On Jul 20, 2009, at 7:06 PM, Dan Kelley wrote: I am trying to write a C function to create a vector of integers that can be used by the R calling function. I do not know the size of the vector in the R calling function. (Well, actually, I have an upper limit on the size, but that is so large that R cannot allocate it. What I'm doing in the function is to do a sieving procedure, and the result will be small enough to fit into my machine's memory.) My reading of sections 6.1.1 and 6.1.2 of the guide on writing R extensions has left me a bit confused. Under R_alloc, I read "R will reclaim the memory at the end of the call" which seems to suggest the storage won't be made available afterwards, so that's not what I should use. As for the alterntaive, under Calloc, I read "This memory lasts until freed by the user", and it's clear that this is to be done within the C function in question. Summary question: how can I allocate memory withing a C function, making it available to an R function that calls the C function? Thanks. Dan. -- You might look at the package bigmemory to see how they attacked the problem. In fact if my reading of their documentation is correct they may have already done your work for you: http://www.stat.yale.edu/~jay/bigmemory David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] S_alloc or Calloc for return value
I am trying to write a C function to create a vector of integers that can be used by the R calling function. I do not know the size of the vector in the R calling function. (Well, actually, I have an upper limit on the size, but that is so large that R cannot allocate it. What I'm doing in the function is to do a sieving procedure, and the result will be small enough to fit into my machine's memory.) My reading of sections 6.1.1 and 6.1.2 of the guide on writing R extensions has left me a bit confused. Under R_alloc, I read "R will reclaim the memory at the end of the call" which seems to suggest the storage won't be made available afterwards, so that's not what I should use. As for the alterntaive, under Calloc, I read "This memory lasts until freed by the user", and it's clear that this is to be done within the C function in question. Summary question: how can I allocate memory withing a C function, making it available to an R function that calls the C function? Thanks. Dan. -- View this message in context: http://www.nabble.com/S_alloc-or-Calloc-for-return-value-tp24579062p24579062.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re al Time PCR data analysis help
On Jul 20, 2009, at 6:43 PM, Andrej Kastrin wrote: Check out qpcR package. Andrej gauravbhatti wrote: Hi I need help since I have never worked on RT PCR data before . I have 8 data files each corresponding to a single pcr run. Each file also represent 10 samples(5 cancer and 5 healthy) belonging to a unique gene. I have 7 unique genes and 1 reference (total 8 files). Can any body help me with preproceesing and normalization? Also, try asking this question again on the bioconductor list, as you'll likely find a higher density of people there doing related work. Some other packages that might help: * http://bioconductor.org/packages/2.4/bioc/html/qpcrNorm.html * http://bioconductor.org/packages/2.4/bioc/html/SLqPCR.html -steve -- Steve Lianoglou Graduate Student: Physiology, Biophysics and Systems Biology Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re al Time PCR data analysis help
Check out qpcR package. Andrej gauravbhatti wrote: Hi I need help since I have never worked on RT PCR data before . I have 8 data files each corresponding to a single pcr run. Each file also represent 10 samples(5 cancer and 5 healthy) belonging to a unique gene. I have 7 unique genes and 1 reference (total 8 files). Can any body help me with preproceesing and normalization? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re gression using age and Duration of disease as a continous factors
On Jul 20, 2009, at 5:30 PM, 1Rnwb wrote: I have read that multiple times without understanding anything. If that's the case, then perhaps you should follow Greg's first piece of advice: Greg Snow-2 wrote: If you need an explanation of what regression means, then you need to take a course or 2 at your local university, or at least hire a statistical consultant. We're not trying to be rude, but your question is quite ill formed, and no one can really help you: Please explain me as what it means and how this analysis can be done using R and which library(ies) are needed. It's not clear what you do/don't understand, and your problem statement is too vague for anyone to tell you more. It seems like you're saying you don't understand what "regression" is, in which case a simple email will not help you. "Simply put" regression is a method to predict a (typically) "continuous" output by some combination of inputs, eg. predicting someone's height by knowing their weight and shoe size (these are continuous variables, too). It looks like in your case, your "inputs" are the "continuous factors" of your email subject, which are age and duration of disease? You haven't even mentioned what it is you are trying to predict. Survival? The thing is, as soon as one puts something in "simple terms," it's often wrong -- which is why Greg suggested taking a class or hiring someone to help you. Anyway, I'm assuming you must know what regression is, otherwise you wouldn't be looking to know how to do it. One way to perform linear regression in R is using the "lm" function. Type ?lm at the R prompt for help. I thought this forum is for help. now i know what the statistician in my dept does all day long It is for help -- you'll see it's quite active around here. It's *not* for soliciting other people to do your analysis for you, which is how your email comes across. All of us have our own work to do, but are here to help if you're stuck on something *in particular* ... perhaps you can do a bit more legwork and rephrase your question in a more meaningful way. -steve -- Steve Lianoglou Graduate Student: Physiology, Biophysics and Systems Biology Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] data frame from list of lists with unequal lengths
try this: > x v1 v2 1 A L 2 A/B M 3 C N 4 D/E/F O 5 A P 6 C L > as.data.frame(do.call(rbind, apply(x, 1, function(.row){ + cbind(strsplit(.row[1], '/')[[1]], .row[2]) + })),row.names='') V1 V2 1 A L 2 A M 3 B M 4 C N 5 D O 6 E O 7 F O 8 A P 9 C L > On Mon, Jul 20, 2009 at 4:46 PM, Ben Mazzotta wrote: > Hello, > > I have a dataset with multiple entries in one field separated by "/" > characters. (The true dataset has long names, 20-odd variables, and > hundreds of observations.) > > > v1 v2 > 1 A L > 2 A/B M > 3 C N > 4 D/E/F O > 5 A P > 6 C L > > > What I would like is to have a dataset that looks like this instead: > >> my.df > v1 v2 > 1 A L > 2 A M > 3 B M > 4 C N > 5 D O > 6 E O > 7 F O > 8 A P > 9 C L > > > My original thought was to break the string into variables using > strsplit(), create new columns in the data frame using cbind(), and then > reshape the dataset with the melt() function. > >> v1.new <- as.character(my.df$v1) >> v1.new <- strsplit(v1.new, "/") >> v1.new > [[1]] > [1] "A" > > [[2]] > [1] "A" "B" > > [[3]] > [1] "C" > > [[4]] > [1] "D" "E" "F" > > [[5]] > [1] "A" > > [[6]] > [1] "C" > > My next thought was to coerce the list into a data frame, but I ran > into an error because the list output from strsplit() does not contain > equal length vectors. > >> v1.cols <- data.frame(v1.new, check.rows=FALSE) > Error in data.frame("A", c("A", "B"), "C", c("D", "E", "F"), "A", "C", : > arguments imply differing number of rows: 1, 2, 3 > > > How can I create a data frame from the unequal length vectors that > result from strsplit(my.df$v1)? > > Am I going about this the wrong way? I have also tried to use > colsplit{reshape} without success. > > Thank you for any advice you can offer. I hope the answer to this > question is not too obvious. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re gression using age and Duration of disease as a continous factors
I thought this forum is for help. now i know what the statistician in my dept does all day long Rolf Turner-3 wrote: > > > On 21/07/2009, at 5:30 AM, 1Rnwb wrote: > >> >> Please explain me as what it means and how this analysis can be >> done using R >> and which library(ies) are needed. >> Thanks > > Go stick your head in a pig! (***) > > cheers, > > Rolf Turner > > > (***) Motto of the Sirius Cybernetics Corporation --- see ``The > Hitchhiker's > Guide to the Galaxy''. > > ## > Attention:\ This e-mail message is privileged and confid...{{dropped:9}} > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- View this message in context: http://www.nabble.com/Regression-using-age-and-Duration-of-disease-as-a-continous-factors-tp24574133p24577992.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re gression using age and Duration of disease as a continous factors
I have read that multiple times without understanding anything. Greg Snow-2 wrote: > > If you need an explanation of what regression means, then you need to take > a course or 2 at your local university, or at least hire a statistical > consultant. > > If you understand regression and just need the explanation of how to do it > using R, then read section 11 (as well as everything else) of "An > Introduction to R". > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Center > Intermountain Healthcare > greg.s...@imail.org > 801.408.8111 > > >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- >> project.org] On Behalf Of 1Rnwb >> Sent: Monday, July 20, 2009 11:30 AM >> To: r-help@r-project.org >> Subject: [R] Re gression using age and Duration of disease as a >> continous factors >> >> >> Please explain me as what it means and how this analysis can be done >> using R >> and which library(ies) are needed. >> Thanks >> >> -- >> View this message in context: http://www.nabble.com/Regression-using- >> age-and-Duration-of-disease-as-a-continous-factors- >> tp24574133p24574133.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting- >> guide.html >> and provide commented, minimal, self-contained, reproducible code. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- View this message in context: http://www.nabble.com/Regression-using-age-and-Duration-of-disease-as-a-continous-factors-tp24574133p24577937.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] moving columns on a stripchart closer together
Greetings I have a very simple question that I have not been able to solve by reading the manual. When I produce a stripchart with two straight columns of dots representing individual observations, one representing one group of subjects and the other representing another, the columns wind up at the far left and far right sides of the plot, and I'd like them to be closer together, about as far apart as they'd be if I used the boxplot function. I would also like to add a short horizontal line where the mean is for each of the columns, so that my readers can see the results of my significant t test graphically. Any assistance in moving my columns together and adding just a short horizontal line for the mean of each would be great. Sincerely, Dr. Leslie J. Seltzer University of Wisconsin-Madison 382 Waisman Center 1500 Highland Ave Madison, WI 53705 PHONE: (608) 886 6067 www.waisman.wisc.edu/childemotion __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] I need to obtain all the rows in m1 in which m2 the elements of m2 are present
Try this also: m1[as.logical(rowSums(matrix(m1 %in% m2, ncol = ncol(m1,] On Mon, Jul 20, 2009 at 5:09 PM, Alberto Lora M wrote: > Hi could you yelp me please with this > > Suppose that we have the following matrix > > m1<-matrix(c("a","7","a","i","o","u","i","1","2","3","4","5","6","7"), > ncol=2) > m1 > [,1] [,2] > [1,] "a" "1" > [2,] "7" "2" > [3,] "a" "3" > [4,] "i" "4" > [5,] "o" "5" > [6,] "u" "6" > [7,] "i" "7" > m2<-c("a","7") > I need to obtain all the rows in m1 in which m2 the elements of m2 are > present > [,1] [,2] > [1,] "a" "1" > [2,] "7" "2" > [3,] "a" "3" > [7,] "i" "7" > > Thx again > > > -- > Alberto Lora Michiels > Rue du Progrès, 6B > 7860 Lessines > GSM 32(0)496659457 > >[[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] I need to obtain all the rows in m1 in which m2 the elements of m2 are present
Hi Alberto, One way would be index <- apply(m1, 1, function(x) any(x %in% m2)) m1[ index, ] See ?apply, ?any and ?"%in%" for more details. HTH, Jorge On Mon, Jul 20, 2009 at 4:09 PM, Alberto Lora M wrote: > Hi could you yelp me please with this > > Suppose that we have the following matrix > > m1<-matrix(c("a","7","a","i","o","u","i","1","2","3","4","5","6","7"), > ncol=2) > m1 > [,1] [,2] > [1,] "a" "1" > [2,] "7" "2" > [3,] "a" "3" > [4,] "i" "4" > [5,] "o" "5" > [6,] "u" "6" > [7,] "i" "7" > m2<-c("a","7") > I need to obtain all the rows in m1 in which m2 the elements of m2 are > present > [,1] [,2] > [1,] "a" "1" > [2,] "7" "2" > [3,] "a" "3" > [7,] "i" "7" > > Thx again > > > -- > Alberto Lora Michiels > Rue du Progrès, 6B > 7860 Lessines > GSM 32(0)496659457 > >[[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] I need to obtain all the rows in m1 in which m2 the elements of m2 are present
Hi could you yelp me please with this Suppose that we have the following matrix m1<-matrix(c("a","7","a","i","o","u","i","1","2","3","4","5","6","7"), ncol=2) m1 [,1] [,2] [1,] "a" "1" [2,] "7" "2" [3,] "a" "3" [4,] "i" "4" [5,] "o" "5" [6,] "u" "6" [7,] "i" "7" m2<-c("a","7") I need to obtain all the rows in m1 in which m2 the elements of m2 are present [,1] [,2] [1,] "a" "1" [2,] "7" "2" [3,] "a" "3" [7,] "i" "7" Thx again -- Alberto Lora Michiels Rue du Progrès, 6B 7860 Lessines GSM 32(0)496659457 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Re al Time PCR data analysis help
Hi I need help since I have never worked on RT PCR data before . I have 8 data files each corresponding to a single pcr run. Each file also represent 10 samples(5 cancer and 5 healthy) belonging to a unique gene. I have 7 unique genes and 1 reference (total 8 files). Can any body help me with preproceesing and normalization? -- View this message in context: http://www.nabble.com/Real-Time-PCR-data-analysis-help-tp24577344p24577344.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RODBC results from stored procedure
tradenet wrote: > > Thanks Dieter. > > The date argument isn't a problem. When I invoke the stored proc > execution with the date arguments the stored proc runs fine, but RODBC > doesn't wait for the stored proc to finish and return results. > > Don't understand that one. How do you know that is did not wait to finish? Did the call I showed you work with the Northwind database? Dieter -- View this message in context: http://www.nabble.com/RODBC-results-from-stored-procedure-tp24503096p24577372.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mahalanobis distance
Thank you..this is what i needed... Rolf Turner wrote: On 21/07/2009, at 7:57 AM, Michael Knudsen wrote: On Mon, Jul 20, 2009 at 9:37 PM, ekinakoglu wrote: Could you please help me with a pseudo matrix of 4x4 that is gonna work with mahalanobis? Please speak English. ``gonna'' is not appropriate for written communication. Hmmm ... I have been trying some different matrices myself now, but I keep getting the same error. Even if det(S) is very far from zero. Maybe I just don't get the point of the mahalanobis() function in R. It looks quite weird to me :-( Huh? Try: > set.seed(42) > X <- matrix(rnorm(100),25,4) > S <- var(X) > x <- rnorm(4) > mahalanobis(x,rep(1,4),S) [1] 6.082543 cheers, Rolf Turner ## Attention:This e-mail message is privileged and confidential. If you are not theintended recipient please delete the message and notify the sender.Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshalwww.marshalsoftware.com ## -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] data frame from list of lists with unequal lengths
Hello, I have a dataset with multiple entries in one field separated by "/" characters. (The true dataset has long names, 20-odd variables, and hundreds of observations.) v1 v2 1 A L 2 A/B M 3 C N 4 D/E/F O 5 A P 6 C L What I would like is to have a dataset that looks like this instead: > my.df v1 v2 1 A L 2 A M 3 B M 4 C N 5 D O 6 E O 7 F O 8 A P 9 C L My original thought was to break the string into variables using strsplit(), create new columns in the data frame using cbind(), and then reshape the dataset with the melt() function. > v1.new <- as.character(my.df$v1) > v1.new <- strsplit(v1.new, "/") > v1.new [[1]] [1] "A" [[2]] [1] "A" "B" [[3]] [1] "C" [[4]] [1] "D" "E" "F" [[5]] [1] "A" [[6]] [1] "C" My next thought was to coerce the list into a data frame, but I ran into an error because the list output from strsplit() does not contain equal length vectors. > v1.cols <- data.frame(v1.new, check.rows=FALSE) Error in data.frame("A", c("A", "B"), "C", c("D", "E", "F"), "A", "C", : arguments imply differing number of rows: 1, 2, 3 How can I create a data frame from the unequal length vectors that result from strsplit(my.df$v1)? Am I going about this the wrong way? I have also tried to use colsplit{reshape} without success. Thank you for any advice you can offer. I hope the answer to this question is not too obvious. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mahalanobis distance
On 21/07/2009, at 7:57 AM, Michael Knudsen wrote: On Mon, Jul 20, 2009 at 9:37 PM, ekinakoglu wrote: Could you please help me with a pseudo matrix of 4x4 that is gonna work with mahalanobis? Please speak English. ``gonna'' is not appropriate for written communication. Hmmm ... I have been trying some different matrices myself now, but I keep getting the same error. Even if det(S) is very far from zero. Maybe I just don't get the point of the mahalanobis() function in R. It looks quite weird to me :-( Huh? Try: > set.seed(42) > X <- matrix(rnorm(100),25,4) > S <- var(X) > x <- rnorm(4) > mahalanobis(x,rep(1,4),S) [1] 6.082543 cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] EM Clustering
Look at the "mclust" package. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Douglas Sousa Sent: Monday, July 20, 2009 4:21 PM To: r help Subject: [R] EM Clustering Hi all, could someone send me examples of the EM Clustering algorithm and/or some pdf describing it? Thanks, Douglas Sousa. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] S4 method dispatch with inheritance
> "MH" == Michael Hahsler > on Mon, 20 Jul 2009 08:57:28 -0500 writes: MH> Hi, I'm trying to create a new S4 class (myMatrix) which MH> for now just extends dgCMatrix (from package MH> Matrix). Then I want to use "[" which is defined in MH> Matrix. MH> Out of the box with "[" (defined in Matrix) I lose the MH> class information and the result is an object of class MH> dgCMatrix. Yes, and that's the case for all such methods for "extended" classes, for S3 / S4 methods alike. Yes, this is sometimes not what you would like, and on R-devel we recently had proposals on definining special attributes (for dataframe / matrix like objects) that would automatically be preserved in "[i,j]" subsetting so others had had similar wishes / dreams. As I have learned in similar experience, it's not a good idea to expect that this happens automatically. Assume "myMatrix" was meant to always be a square matrix, or always a symmetric matrix. Then, only *some* "[i,j]" operations would return a valid "myMatrix"... For such reasons, indeed, it's you who must provide methods for your class. Of couese these methods will typically call the "upper class" method, possibly via callNextMethod(.), or {my historical preference} directly. MH> If I specify a "["-method for myMatrix, it is MH> not used because a signature from Matrix seems to fit MH> better. Yes, Matrix" has many methods for "[", for good reasons, but if you define your methods "correctly", things are solved easily, see below MH> However, the most important part of the MH> signature is the class of x (all else have ANY). Is MH> there a way to specify a single "["-method do make it MH> work for myClass? a single method is not sufficient; "[" is a generic function with several signauture arguments, on which dispatch can happen. And note, that "[" is particularly delicate : The code (well, the one in "Matrix") must be able to distinguish between M[ i,] and M[ i ] Here's a working solution: --- library("Matrix") setClass("myMatrix", contains="dgCMatrix") M <- as(Diagonal(x = 1:7), "CsparseMatrix") (my <- as(as(M, "dgCMatrix"), "myMatrix")) ## here I lose the class "myMatrix" class(my[1:2,]) ## [1] "dgCMatrix" ## make sure [ keeps the class if(FALSE)# not really needed setMethod("[", signature(x = "myMatrix"), ## (ANY,ANY...) function(x, i, j, ..., drop) as(as(x,"dgCMatrix")[i, j, ..., drop], "myMatrix")) setMethod("[", signature(x = "myMatrix", i="index", j="index", drop="logical"), function(x, i, j, ..., drop) as(as(x,"dgCMatrix")[i, j, drop=drop], "myMatrix")) setMethod("[", signature(x = "myMatrix", i="index", j = "missing", drop="logical"), function(x, i, j, ..., drop) as(as(x,"dgCMatrix")[i, , drop=drop], "myMatrix")) setMethod("[", signature(x = "myMatrix", i = "missing", j="index",drop="logical"), function(x, i, j, ..., drop) as(as(x,"dgCMatrix")[ , j, drop=drop], "myMatrix")) head(my, 2) ## perfect my[3,3,drop=FALSE] # ditto my[, 2:4] # ditto --- Note that the three method definitions use slightly different function bodies: When an argument is "missing", it's not a good idea to pass it again to the generic "[" which then again would like to do method dispatch on that missing... Also, if you replace "index" (the indexing class introduced in 'Matrix", but more generally interesting) by "ANY", you need another methods definition in order to match to you "myMatrix" class first, before any of the many specific methods in "Matrix". Note further, that at the DSC 2007, I already noted a similar situation and had prposed back then, that it would be desirable to allow the programmer to more closely to specify method dispatch in a case like yours: We would want to specify that for method dispatch, the class of "x" (i.e. "myMatrix" in your case) should weight much more than the classes of (i,j,drop). But something like this has to wait for the future, . I hope this helped so far. >> library("Matrix") [...] >> >> setClass("myMatrix", MH> + contains="dgCMatrix" MH> + ) {{why 3 lines instead of 1 ?}} MH> [1] "myMatrix" >> >> my <- as(as(rbind(1:10,1:10,1:10), "dgCMatrix"), "myMatrix") >> >> ## here I lose the class "myMatrix" >> class(my[1:2,]) MH> [1] "dgCMatrix" MH> attr(,"package") MH> [1] "Matrix" >> >> ## make sure [ keeps the class >> setMethod("[", signature(x = "myMatrix", i = "ANY", j = "ANY", MH> + drop = "ANY"), MH> + function(x, i, j, ..., drop) { MH> + x<- as(x, "dgCMatrix")[i, j, ..., drop] MH> + as(x, "myMatrix") MH> + }) MH> [1] "[" >> >> ## and now it does n
Re: [R] EM Clustering
Hi, On Jul 20, 2009, at 4:21 PM, Douglas Sousa wrote: Hi all, could someone send me examples of the EM Clustering algorithm and/or some pdf describing it? Wikipedia: http://en.wikipedia.org/wiki/Expectation-maximization_algorithm You'll find useful links in the references and external links sections, with claims of being intuitive/gentle intros to EM: A Gentle Tutorial of the EM Algorithm and its Application to Parameter Estimation for Gaussian Mixture and Hidden Markov Models http://citeseer.ist.psu.edu/bilmes98gentle.html The Expectation Maximization Algo http://www.cc.gatech.edu/~dellaert/em-paper.pdf HTH, -steve -- Steve Lianoglou Graduate Student: Physiology, Biophysics and Systems Biology Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re gression using age and Duration of disease as a continous factors
On 21/07/2009, at 5:30 AM, 1Rnwb wrote: Please explain me as what it means and how this analysis can be done using R and which library(ies) are needed. Thanks Go stick your head in a pig! (***) cheers, Rolf Turner (***) Motto of the Sirius Cybernetics Corporation --- see ``The Hitchhiker's Guide to the Galaxy''. ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] EM Clustering
Hi all, could someone send me examples of the EM Clustering algorithm and/or some pdf describing it? Thanks, Douglas Sousa. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RODBC results from stored procedure
Thanks Dieter. The date argument isn't a problem. When I invoke the stored proc execution with the date arguments the stored proc runs fine, but RODBC doesn't wait for the stored proc to finish and return results. Regards, Andrew Dieter Menne wrote: > > > > tradenet wrote: >> >> Short of uploading a SQL server database, I don't think I can make this >> example reproducible, but I hope it's not so complicated as to require >> reproducibility >> >> I can call a parametrized stored procedure without a problem and the proc >> does indeed execute successfully. >> > > This works for me with the popular Northwind database > > channel = odbcConnect("northwind") # Assume this is configured correctly > sqlQuery(channel,"EXEC CustOrderHist @CustomerID=ALFKI") > > Try with a non-date query first, the switch to the tricky date format in > the parameter. > > Dieter > > > -- View this message in context: http://www.nabble.com/RODBC-results-from-stored-procedure-tp24503096p24576806.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mahalanobis distance
On Mon, Jul 20, 2009 at 9:37 PM, ekinakoglu wrote: > Could you please help me with a pseudo matrix of 4x4 > that is gonna work with mahalanobis? Hmmm ... I have been trying some different matrices myself now, but I keep getting the same error. Even if det(S) is very far from zero. Maybe I just don't get the point of the mahalanobis() function in R. It looks quite weird to me :-( -- Michael Knudsen micknud...@gmail.com http://lifeofknudsen.blogspot.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] kmeans.big.matrix
Hi, I'm playing around with the 'bigmemory' package, and I have finally managed to create some really big matrices. However, only now I realize that there may not be functions made for what I want to do with the matrices... I would like to perform a cluster analysis based on a big.matrix. Googling around I have found indications that a certain kmeans.big.matrix() function should exist. It is mentioned, among other places, in this document: http://www.stat.yale.edu/~jay/662/bm-nojss.pdf Unfortunately, on my computer the following happens: > require(bigmemory) Loading required package: bigmemory > kmeans.big.matrix Error: object 'kmeans.big.matrix' not found Does anybody know how to get the kmeans.big.matrix() function? Are there other cluster algorithms out there ready to accept a big.matrix as input? Thanks! -- Michael Knudsen micknud...@gmail.com http://lifeofknudsen.blogspot.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mahalanobis distance
Thank you for your help... I try other data from my sampling but the determinant is very close to zero. I also tried to generate random numbers using MATLAB and then calculate S=var(x) to no avail. Could you please help me with a pseudo matrix of 4x4 that is gonna work with mahalanobis? Thanks.. -- View this message in context: http://www.nabble.com/mahalanobis-distance-tp24569511p24576155.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a complicated merging task
Why not merge on ID, then delete the rows that don't match your second criterion? Seems easier than trying to do it in one step. Sarah On Mon, Jul 20, 2009 at 3:07 PM, tathta wrote: > > I would like to merge two dataframes, but i have a condition that needs to > used for the merge as well. > > the rows (observations) in each dataframe are identified by each person's ID > and by the date of the observation. > Basically I would like it to be merged based on both ID (exact match) and > date (a condition where one dataframe's date must be after the other > dataframe's date). > > > below I've given some sample dataframes to work with, described my > mysterious function, and constructed my ideas output. > > > #setting up my sample dataframes > dateA <- > as.Date(c("13/01/2001","14/02/2005","17/01/2005","27/06/2006"),"%d/%m/%Y") > dateB <- > as.Date(c("22/11/2002","13/02/2005","18/08/2005","18/01/2006","21/08/2007","21/04/2009","17/05/2009","17/05/2009"),"%d/%m/%Y") > dataA <- data.frame(id=c("A","B","C","B"),date=dateA, x=11:14,y=5:2) > dataB <- > data.frame(id=c("B","A","B","C","B","C","D","B"),date=dateB,m=27:20,n=22:29) > > > #mystery function, something like: > # data.merged <- merge(dataB,dataA,by.y=(id and date, where dataB's date > > dataA's date), all.x=TRUE) > > > #ideal final product would look like the dataframe created by the following > 5 lines > data.merged <- dataB[order(dataB$id),] > names(data.merged) <- c("id","date.b","m","n") > data.merged$date.a <- > as.Date(c("13/01/2001","14/02/2005","14/02/2005","27/06/2006","27/06/2006","17/01/2005","17/01/2005",NA),"%d/%m/%Y") > data.merged$x <- c(11,12,12,14,14,13,13,NA) > data.merged$y <- c(5,4,4,2,2,3,3,NA) > > > -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] calculating median with a condition
On 7/20/2009 2:59 PM, Manisha Brahmachary wrote: > Hello, > > > > I am trying to calculate the median of numbers across each row for the data > shown below , with the condition that if the number is negative, that it > should be ignored and the median should be taken of only the positive > numbers. > > > > For eg: data is in Column A,B,C. Column D and E demonstrates what I want to > get as answer > > > > A > > B > > C > > Median > > median value > > -13.6688115 > > -32.50914055 > > -50.54011892 > > all negative, so ignore > > NA > > NA > > -53.65656268 > > 42.58599666 > > median C > > 42.58599666 > > 33.30683089 > > 18.93765489 > > -25.17024229 > > median A,B > > 26.12224289 > > > > The R script I have written is below( which doesnot do the job properly) > > > > median.value<- matrix(nrow=nrow(data),ncol=1) > > for(k in 1:nrow(data)){ > > median.value[k]<-median(data[which(data[k,]>0)])} > > > > Can someone suggest me the correct R script to do what I have explained > above. X <- as.data.frame(matrix(rnorm(100), ncol=10)) apply(X, 1, function(x){median(x[x > 0])}) [1] 0.2297943 0.6476565 0.4699609 0.8744830 [5] 1.0242502 0.7800703 0.6648436 0.2930191 [9] 0.6001506 1.0767194 > Thanks > > Manisha > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] calculating median with a condition
Hi Manisha, Manisha Brahmachary wrote: Hello, I am trying to calculate the median of numbers across each row for the data shown below , with the condition that if the number is negative, that it should be ignored and the median should be taken of only the positive numbers. For eg: data is in Column A,B,C. Column D and E demonstrates what I want to get as answer A B C Median median value -13.6688115 -32.50914055 -50.54011892 all negative, so ignore NA NA -53.65656268 42.58599666 median C 42.58599666 33.30683089 18.93765489 -25.17024229 median A,B 26.12224289 The R script I have written is below( which doesnot do the job properly) median.value<- matrix(nrow=nrow(data),ncol=1) for(k in 1:nrow(data)){ median.value[k]<-median(data[which(data[k,]>0)])} meds <- apply(data, 1, function(x) ifelse(median(x) < 0, median(x[x >= 0]), median(x))) I would normally avoid variable names like data, as you are masking a function by the same name. Best, Jim Can someone suggest me the correct R script to do what I have explained above. Thanks Manisha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- James W. MacDonald, M.S. Biostatistician Douglas Lab University of Michigan Department of Human Genetics 5912 Buhl 1241 E. Catherine St. Ann Arbor MI 48109-5618 734-615-7826 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Re gression using age and Duration of disease as a continous factors
If you need an explanation of what regression means, then you need to take a course or 2 at your local university, or at least hire a statistical consultant. If you understand regression and just need the explanation of how to do it using R, then read section 11 (as well as everything else) of "An Introduction to R". -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of 1Rnwb > Sent: Monday, July 20, 2009 11:30 AM > To: r-help@r-project.org > Subject: [R] Re gression using age and Duration of disease as a > continous factors > > > Please explain me as what it means and how this analysis can be done > using R > and which library(ies) are needed. > Thanks > > -- > View this message in context: http://www.nabble.com/Regression-using- > age-and-Duration-of-disease-as-a-continous-factors- > tp24574133p24574133.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] a complicated merging task
I would like to merge two dataframes, but i have a condition that needs to used for the merge as well. the rows (observations) in each dataframe are identified by each person's ID and by the date of the observation. Basically I would like it to be merged based on both ID (exact match) and date (a condition where one dataframe's date must be after the other dataframe's date). below I've given some sample dataframes to work with, described my mysterious function, and constructed my ideas output. #setting up my sample dataframes dateA <- as.Date(c("13/01/2001","14/02/2005","17/01/2005","27/06/2006"),"%d/%m/%Y") dateB <- as.Date(c("22/11/2002","13/02/2005","18/08/2005","18/01/2006","21/08/2007","21/04/2009","17/05/2009","17/05/2009"),"%d/%m/%Y") dataA <- data.frame(id=c("A","B","C","B"),date=dateA, x=11:14,y=5:2) dataB <- data.frame(id=c("B","A","B","C","B","C","D","B"),date=dateB,m=27:20,n=22:29) #mystery function, something like: # data.merged <- merge(dataB,dataA,by.y=(id and date, where dataB's date > dataA's date), all.x=TRUE) #ideal final product would look like the dataframe created by the following 5 lines data.merged <- dataB[order(dataB$id),] names(data.merged) <- c("id","date.b","m","n") data.merged$date.a <- as.Date(c("13/01/2001","14/02/2005","14/02/2005","27/06/2006","27/06/2006","17/01/2005","17/01/2005",NA),"%d/%m/%Y") data.merged$x <- c(11,12,12,14,14,13,13,NA) data.merged$y <- c(5,4,4,2,2,3,3,NA) -- View this message in context: http://www.nabble.com/a-complicated-merging-task-tp24575713p24575713.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] calculating median with a condition
Hello, I am trying to calculate the median of numbers across each row for the data shown below , with the condition that if the number is negative, that it should be ignored and the median should be taken of only the positive numbers. For eg: data is in Column A,B,C. Column D and E demonstrates what I want to get as answer A B C Median median value -13.6688115 -32.50914055 -50.54011892 all negative, so ignore NA NA -53.65656268 42.58599666 median C 42.58599666 33.30683089 18.93765489 -25.17024229 median A,B 26.12224289 The R script I have written is below( which doesnot do the job properly) median.value<- matrix(nrow=nrow(data),ncol=1) for(k in 1:nrow(data)){ median.value[k]<-median(data[which(data[k,]>0)])} Can someone suggest me the correct R script to do what I have explained above. Thanks Manisha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Write in file matrices of sifferent size
Dear Julien, Try sink(): matrixA <- matrix(0,5,4) matrixB <- matrix(1,7,13) matrixList <- list(matrixA,matrixB) names(matrixList) <- c("matrixA", "matrixB") sink("yourname.txt") matrixList sink() See ?sink for more information. HTH, Jorge On Mon, Jul 20, 2009 at 1:02 PM, julien cuisinier wrote: > > Hi list, > > > > > > > > How to save a list content into a text file? > > > > Please consider example below, I have two numeric matrices that I bundle > into a list & give each list element a name > > > > Example: > > > matrixA <- matrix(0,5,4) > > matrixB <- matrix(1,7,13) > > matrixList <- list(matrixA,matrixB) > > > names <- c("Matrix A","Matrix B") > > > names <- names(matrixList) > > > > How could I get the list in a txt as below: > > " > > Matrix A > > (Matrix A element 1,1), (Matrix A element 1,2), ... > > (Matrix A element 2,1), (Matrix A element 2,2), ... > > ... > > > > Matrix B > > (Matrix B element 1,1), (Matrix B element 1,2), ... > > (Matrix B element 2,1), (Matrix B element 2,2), ... > > ... > > " > > > > > > Write or write.table or write.csv did not help as it complains the matrices > are not of equal size > > > > Any help/direction appreciated > > > > > > many thanks > > > > regards, > > Julien Cuisinier > > > > > > > > > > > > " > > > > _ > [[elided Hotmail spam]] > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Re gression using age and Duration of disease as a continous factors
Please explain me as what it means and how this analysis can be done using R and which library(ies) are needed. Thanks -- View this message in context: http://www.nabble.com/Regression-using-age-and-Duration-of-disease-as-a-continous-factors-tp24574133p24574133.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Tinn-R - problem with hotkeys
I've just installed R on my new laptop. Then, I've installed the latest version of Tinn-R. It works but - when I go to R-hotkeys, it does not alllow me to specify any hotkeys. I click in the field that says "None" (on top), try to change it, but it does not allow me to do anything. Has anyone encountered such a problem? Thank you! -- Dimitri Liakhovitski __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Write in file matrices of sifferent size
use capture.output > matrixA <- matrix(0,5,4) > matrixB <- matrix(1,7,13) > matrixList <- list(matrixA,matrixB) > names(matrixList) <- c("matrixA", "matrixB") > matrixList $matrixA [,1] [,2] [,3] [,4] [1,]0000 [2,]0000 [3,]0000 [4,]0000 [5,]0000 $matrixB [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [1,]111111111 1 1 1 1 [2,]111111111 1 1 1 1 [3,]111111111 1 1 1 1 [4,]111111111 1 1 1 1 [5,]111111111 1 1 1 1 [6,]111111111 1 1 1 1 [7,]111111111 1 1 1 1 > capture.output(matrixList, file='myMatrix.txt') #here is the text file created: $matrixA [,1] [,2] [,3] [,4] [1,]0000 [2,]0000 [3,]0000 [4,]0000 [5,]0000 $matrixB [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [1,]111111111 1 1 1 1 [2,]111111111 1 1 1 1 [3,]111111111 1 1 1 1 [4,]111111111 1 1 1 1 [5,]111111111 1 1 1 1 [6,]111111111 1 1 1 1 [7,]111111111 1 1 1 1 On Mon, Jul 20, 2009 at 1:02 PM, julien cuisinier wrote: > > Hi list, > > > > > > > > How to save a list content into a text file? > > > > Please consider example below, I have two numeric matrices that I bundle into > a list & give each list element a name > > > > Example: > >> matrixA <- matrix(0,5,4) >> matrixB <- matrix(1,7,13) >> matrixList <- list(matrixA,matrixB) > >> names <- c("Matrix A","Matrix B") > >> names <- names(matrixList) > > > > How could I get the list in a txt as below: > > " > > Matrix A > > (Matrix A element 1,1), (Matrix A element 1,2), ... > > (Matrix A element 2,1), (Matrix A element 2,2), ... > > ... > > > > Matrix B > > (Matrix B element 1,1), (Matrix B element 1,2), ... > > (Matrix B element 2,1), (Matrix B element 2,2), ... > > ... > > " > > > > > > Write or write.table or write.csv did not help as it complains the matrices > are not of equal size > > > > Any help/direction appreciated > > > > > > many thanks > > > > regards, > > Julien Cuisinier > > > > > > > > > > > > " > > > > _ > [[elided Hotmail spam]] > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Write in file matrices of sifferent size
Hi, On Jul 20, 2009, at 1:02 PM, julien cuisinier wrote: Hi list, How to save a list content into a text file? Please consider example below, I have two numeric matrices that I bundle into a list & give each list element a name Example: matrixA <- matrix(0,5,4) matrixB <- matrix(1,7,13) matrixList <- list(matrixA,matrixB) names <- c("Matrix A","Matrix B") names <- names(matrixList) How could I get the list in a txt as below: " Matrix A (Matrix A element 1,1), (Matrix A element 1,2), ... (Matrix A element 2,1), (Matrix A element 2,2), ... ... Matrix B (Matrix B element 1,1), (Matrix B element 1,2), ... (Matrix B element 2,1), (Matrix B element 2,2), ... ... " I reckon you can do this with two separate calls to write.table using (.., append=TRUE). Not the most elegant, but: outfile <- open('output.txt', 'w') cat("Matrix A\n", file=outfile) close(outfile) write.table(matrixA, file='output.txt', append=TRUE, ...) outfile <- open('output.txt', 'a') cat("\nMatrix B\n", file=outfile) close(outfile) write.table(matrixB, file='output.txt', append=TRUE, ...) Hope that helps, -steve -- Steve Lianoglou Graduate Student: Physiology, Biophysics and Systems Biology Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] heatmap plot
since heatmap is a graphic image it needs the "graphics" library. you can see these two in the examples for heatmap. require(graphics); require(grDevices) Markus Mühlbacher wrote: > > Dear R community! > > I am trying to create a heatmap based on the following data. As you can > see the diagonal (0,0 to 10,10) is always 0). If I run the heatmap command > like i posted it I get a graph with horizontal lines. > > What is my mistake? > >> heatmap(activity.matrix, Rowv = NA, Colv = NA, scale="column", xlab="x >> Compounds", ylab="y Compounds", col=topo.colors(100)) >> activity.matrix > [,1] [,2] [,3][,4] [,5] [,6] > [1,] 0.000 -0.1017802 0.3635007 0.62522118 0.8869417 -0.4652809 > [2,] 0.1017802 0.000 0.4652809 0.72700138 0.9887219 -0.3635007 > [3,] -0.3635007 -0.4652809 0.000 0.26172050 0.5234410 -0.8287816 > [4,] -0.6252212 -0.7270014 -0.2617205 0. 0.2617205 -1.0905021 > [5,] -0.8869417 -0.9887219 -0.5234410 -0.26172050 0.000 -1.356 > [6,] 0.4652809 0.3635007 0.8287816 1.09050206 1.356 0.000 > [7,] -0.2471805 -0.3489607 0.1163202 0.37804072 0.6397612 -0.7124613 > [8,] 1.0032619 0.9014817 1.3667626 1.62848308 1.8902036 0.5379810 > [9,] -0.6833813 -0.7851615 -0.3198806 -0.05816011 0.2035604 -1.1486622 > [10,] 1.0759620 0.9741818 1.4394627 1.70118322 1.9629037 0.6106812 > [,7][,8][,9] [,10] > [1,] 0.2471805 -1.00326190 0.68338129 -1.07596204 > [2,] 0.3489607 -0.90148171 0.78516149 -0.97418184 > [3,] -0.1163202 -1.36676259 0.31988061 -1.43946272 > [4,] -0.3780407 -1.62848308 0.05816011 -1.70118322 > [5,] -0.6397612 -1.89020358 -0.20356039 -1.96290371 > [6,] 0.7124613 -0.53798102 1.14866217 -0.61068116 > [7,] 0.000 -1.25044237 0.43620083 -1.32314250 > [8,] 1.2504424 0. 1.68664319 -0.07270014 > [9,] -0.4362008 -1.68664319 0. -1.75934333 > [10,] 1.3231425 0.07270014 1.75934333 0. > > Thanks in advance. > > Greets, > Markus > > > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- View this message in context: http://www.nabble.com/heatmap-plot-tp24572168p24574102.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can I use "mcnemar.test" for 3*3 tables (or is there a bug in the command?)
Hello David, Thank you for your patience with the amount of ignorance I am revealing of myself in my questions, and for your willingness to help. My replies to your e-mail are bellow, prefaced with "T:" for ease of navigation. On Mon, Jul 20, 2009 at 9:02 PM, David Winsemius wrote: > > On Jul 20, 2009, at 5:22 AM, Tal Galili wrote: > > Hello David Winsemius and the rest of the R help group, >> >> David, I tried to answer your question to the best of my abilities, If I >> was unclear or still am leaving some things out, please help me in focusing >> my situation even further. here are my answers to the questions you posed: >> 1) Please define "better" - >> "better" is the one that is able to handle the questions at hand (marginal >> homogenity and symmetry) while giving meaningful results although the data >> is sometimes sparse (with Zeros in it) and the sample size is somewhat small >> (around 25 kids) >> > > Frankly, the phrases "marginal homogeneity" and "symmetry" are, for me > anyway, not particularly evocative of an interpretable sort of difference. I > try to express my findings in terms I think my audience may have some chance > of understanding: odds ratios or risk ratios or difference in mean effects > ... T: Understood and agreed, yet to the audience I am working with, OR and RR and the sorts are not of the field (as is the case in epidemiology), so I am not using them at the moment. > > 2) And now ... define "right" >> What I meant with "right" is "what test did each of these procedures just >> perform" and also "what can I learn from each of the P's if they where to >> pass the significance bar (of let's say .05)" >> > > 3) "Perhaps from the perspective of a statistically naive reviewer." >> Thank you for pointing to this being superficial, I would love for any >> help you could give in deepening my understanding. >> > > It appeared from context (which was snipped) that you thought one was > "better" because its p-value was lower. If the criterion by which you > choose one statistical test over another is whether or not it happens to > produce a signal p <0.05, then I think you are dredging rather than > analyzing. I think the question should be instead whether the test is the > most powerful for the particular hypothesis and data situation. T: I don't consider one test better then the other just because of having a P value that is smaller. I was meaning better in the same sense of a fisher test being "better" to a chi square test in cases of very few observations. The P's will be different, but the "better" is in the sense of "a better suited/valid test to the type of data we are handling". I was not referring to the power factor, but rather to the validity. > > > >> 4) "The problem I am trying to solve" is for the following situation: >> >> The data set: >> I am analyzing a data set with subjects (kids) listening to the same music >> two times (randomized, and on different times and so on), the condition of >> the experiment is a bit different the first time the kids listens (X=1) then >> the second time (X=2). >> And the response (Y) the kid is making for the experiment is recorded as >> an ordered number of three levels: -1, 0, 1 >> > > So you would certainly want a test that properly handles ordinal effects. I > am not sure that was clear at all from your earlier questions. Tests of > hypotheses regarding ordered alternatives are often more powerful than ones > that evaluate less specific alternatives. T: Thank you David, I agree with that. But it will require me a learning curve that I won't be able to climb before my upcoming deadline (but for my future work, it is definitely on my to-study list!) > > > >> The (statistical) question: did the difference in the experiment >> conditions yielded different rankings from the kids? and if so, was there a >> specific direction? >> e.g: did kids who by now (in part one of the experiment) answered mostly >> -1 and 0, now (in part two of the experiment) started answering more 0 and >> 1? Or, did kids who by now mostly answered 0 now started answering -1 and 1 >> ? and so on. >> >> Analyses approach: >> There are two basic ways to do this. >> 1) The first one is a Willcox test, to see if there was change in answers >> (Y) between the two situations (X=1, X=2) >> > > I am here puzzled. Is the Willcox test a well known one in your academic > domain? If it is I apologize for my lack of breadth in named tests. Or > could you be referring to what is invoked in R with wilcox.test()? I am > guessing from context that you might be asking about the Wilcoxon > signed-rank test for paired data situations. It would in fact address the > ordering of your paired outcomes, but all of the Wilcoxon tests are based on > the measures being from a continuous distribution and statistical validity > for your situation would be questionable. T: I was indeed referring to the "wilcox.test", sorry for not referring to it in that way. Regarding
Re: [R] dot plot with several points for 2 categories
I use the long way, you might have to play around with my script to get is correct. once you get it to work, you can add as many points to reflect, median, percentile etc. ## generatiing vectors for Group1 a<-LMMP8[Self_T1D=="N"] w <- a[!is.na(a)] length(w) c<-mean(a, na.rm=TRUE) c n<-as.integer(length(w)/7) n n4<- length(w)-6*n n4 ###Generating vectors for T1D b<-LMMP8[Self_T1D=="Y"] x <- b[!is.na(b)] length(x) d<-mean (b, na.rm=TRUE) d m<-as.integer(length(x)/7) m m4<- length(x)-6*m m4 u<-append(w, x, after = length(w)) length(u) x<-c(rep(1:6,n),rep(7,n4), rep(11:16,m),rep(17,m4)) length(x) #Plotting the data plot(x,u, ylab="Log MMP8",pch=19,cex.lab=1.5,lty=2,cex=1.1, cex.axis=1.25,xaxt="n") points(4,c,pch=25,col="red",lwd=5) points(14,d,pch=25,col="red",lwd=5) jaregi wrote: > > I'm trying to wean myself off the very limited capabilities of Excel and > Oo. Currently, I am trying to make a plot showing several values for 2 > categories in a dot blot (see > http://www.nabble.com/file/p24538360/Picture%2B1.png Picture+1.png except > that the x axis should contain the category not a number, which was the > only way to coax Excel into displaying a plot like this). I started > working through some tutorials but the example didn't quite fit what I was > looking for. The closest was the car and mpg example but it 1 value per > name whereas I need several value per category. Does anybody know this of > the top of your expert heads? This would be a great help. I already burned > a few hours without getting closer to the solution.. > > Best, j > -- View this message in context: http://www.nabble.com/dot-plot-with-several-points-for-2-categories-tp24538360p24573397.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] assign question
I don't think you want assign() here. > x1 = rnorm(20) > min(x1) [1] -0.9723398 > min(eval(paste("x",1,sep=""))) # not the solution [1] "x1" > min(eval(as.name(paste("x",1,sep="" # a solution [1] -0.9723398 try: for(i in 1:27) { xener[i] <- min(eval(as.name((paste("sa",i,sep="") } albyn On Mon, Jul 20, 2009 at 01:26:05PM -0500, Erin Hodgess wrote: > Dear R People: > > I have several vectors, sa1, sa2,...sa27 of varying lengths. > > I want to produce one vector xener[1:27] which has the minimum of each sa[i]. > > I'm trying to set up a loop and use the assign statement, but here are > my results: > > > for(i in 1:27) { > + xener[i] <- min(assign(paste("sa",i,sep=""))) > + } > Error in assign(paste("sa", i, sep = "")) : > element 2 is empty; >the part of the args list of '.Internal' being evaluated was: >(x, value, envir, inherits) > > > > Any suggestions would be most welcome. > > Thanks in advance, > Erin > > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodg...@gmail.com > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Write in file matrices of sifferent size
Hi list, How to save a list content into a text file? Please consider example below, I have two numeric matrices that I bundle into a list & give each list element a name Example: > matrixA <- matrix(0,5,4) > matrixB <- matrix(1,7,13) > matrixList <- list(matrixA,matrixB) > names <- c("Matrix A","Matrix B") > names <- names(matrixList) How could I get the list in a txt as below: " Matrix A (Matrix A element 1,1), (Matrix A element 1,2), ... (Matrix A element 2,1), (Matrix A element 2,2), ... ... Matrix B (Matrix B element 1,1), (Matrix B element 1,2), ... (Matrix B element 2,1), (Matrix B element 2,2), ... ... " Write or write.table or write.csv did not help as it complains the matrices are not of equal size Any help/direction appreciated many thanks regards, Julien Cuisinier " _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] assign question
How about: sapply ( 1:27 , function ( i ) { min ( get ( paste ( "sa" , i , sep = "" ) ) ) } ) See ?get david -- David - David Huffer, Ph.D. Senior Statistician CSOSA/Washington, DC david.huf...@csosa.gov - -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess Sent: Monday, July 20, 2009 2:26 PM To: R help Subject: [R] assign question Dear R People: I have several vectors, sa1, sa2,...sa27 of varying lengths. I want to produce one vector xener[1:27] which has the minimum of each sa[i]. I'm trying to set up a loop and use the assign statement, but here are my results: > for(i in 1:27) { + xener[i] <- min(assign(paste("sa",i,sep=""))) + } Error in assign(paste("sa", i, sep = "")) : element 2 is empty; the part of the args list of '.Internal' being evaluated was: (x, value, envir, inherits) > Any suggestions would be most welcome. Thanks in advance, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simulate residuals with different properties for a linear model (regression)
Hey guys, for educational purposes I wonder if it is possible to simulate different data sets (or specifically residuals) for a linear regression. I would like to show my students residuals with different means, variances and distributions (normal, but also not normal) in the plots created with the plot command for a lm-object. In addition it would be nice to simulate although influencal values (high cooks distance and leverage) lm.results <- lm(y~x,data) plot(lm.results) Is there an easy way to do this? Or can this be done at all (and if yes, any hints?:-) Thanks and Greetings! Friedericksen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] I might be dumb : a simple question about "foreach"
A user in Japan reported a similar problem on the Revolutions blog ( http://bit.ly/FKP2I ), and my best guess is that it's an (unintended!) effect of using locales. The developers in New Haven are looking at it, and I expect they'll be able to post an update to CRAN soon. # David Smith On Mon, Jul 20, 2009 at 5:48 AM, Olivier ETERRADOSSI < olivier.eterrado...@ema.fr> wrote: > Hi list, > My attention was drawn to the foreach package by recent posts...I decided > to have a look... > I'm using R.2.9.1 on Windows, I have downloaded the foreach package today > (v 1.2.1), together with iterators (v. 1.0.1) and codetools (v.0.2-2). > Full of hope I try the most simple thing of all out of the package vignette > : > >> x <- foreach(i = 1:3) %do% sqrt(i) >> > and get : > >> Erreur dans sqrt(i) : indice hors limites ( i.e. "error in sqrt(i) : index >> out of bounds") >> > but when trying : > > x<-foreach(i = 1:3) %do% print(sqrt(i)) >> > I get : > > [1] 1 >> [1] 1.414214 >> [1] 1.732051 >> Erreur dans print(sqrt(i)) : indice hors limites >> > Probably I didn't drink enough coffee this morning and I'm still asleep : > it is obvious that I miss a point... but I am unable to see which one. > Any help appreciated ! Many thanks, and very best regards Olivier > > -- > Olivier ETERRADOSSI > Maître-Assistant > CMGD / Equipe "Propriétés Psycho-Sensorielles des Matériaux" > Ecole des Mines d'Alès > Hélioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9 > tel std: +33 (0)5.59.30.54.25 > tel direct: +33 (0)5.59.30.90.35 fax: +33 (0)5.59.30.63.68 > http://www.ema.fr > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- David M Smith Director of Community, REvolution Computing www.revolution-computing.com Tel: +1 (206) 577-4778 x3203 (San Francisco, USA) Check out our upcoming events schedule at www.revolution-computing.com/events [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] assign question
Dear R People: I have several vectors, sa1, sa2,...sa27 of varying lengths. I want to produce one vector xener[1:27] which has the minimum of each sa[i]. I'm trying to set up a loop and use the assign statement, but here are my results: > for(i in 1:27) { + xener[i] <- min(assign(paste("sa",i,sep=""))) + } Error in assign(paste("sa", i, sep = "")) : element 2 is empty; the part of the args list of '.Internal' being evaluated was: (x, value, envir, inherits) > Any suggestions would be most welcome. Thanks in advance, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Normalize data
Start by using the Help docs and functionality, not this list. ?help.search help.search("scale") ?scale Bert Gunter Genentech Nonclinical Biostatistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Noah Silverman Sent: Monday, July 20, 2009 11:04 AM Cc: r help Subject: [R] Normalize data Hello, I'm coming from RapidMiner, so some of the "easy" things there are a bit difficult for me to find in R How do I normalize data in a data frame. Ideally I want to scale the values for each column in the range of (-1,1) Thank You, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Normalize data
require(vegan) library(help=vegan) :-) On Mon, Jul 20, 2009 at 2:03 PM, Noah Silverman wrote: > Hello, > > I'm coming from RapidMiner, so some of the "easy" things there are a bit > difficult for me to find in R > > How do I normalize data in a data frame. Ideally I want to scale the > values for each column in the range of (-1,1) > > > Thank You, > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Normalize data
Hello, I'm coming from RapidMiner, so some of the "easy" things there are a bit difficult for me to find in R How do I normalize data in a data frame. Ideally I want to scale the values for each column in the range of (-1,1) Thank You, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Can I use "mcnemar.test" for 3*3 tables (or is there a bug in the command?)
On Jul 20, 2009, at 5:22 AM, Tal Galili wrote: Hello David Winsemius and the rest of the R help group, David, I tried to answer your question to the best of my abilities, If I was unclear or still am leaving some things out, please help me in focusing my situation even further. here are my answers to the questions you posed: 1) Please define "better" - "better" is the one that is able to handle the questions at hand (marginal homogenity and symmetry) while giving meaningful results although the data is sometimes sparse (with Zeros in it) and the sample size is somewhat small (around 25 kids) Frankly, the phrases "marginal homogeneity" and "symmetry" are, for me anyway, not particularly evocative of an interpretable sort of difference. I try to express my findings in terms I think my audience may have some chance of understanding: odds ratios or risk ratios or difference in mean effects ... 2) And now ... define "right" What I meant with "right" is "what test did each of these procedures just perform" and also "what can I learn from each of the P's if they where to pass the significance bar (of let's say .05)" 3) "Perhaps from the perspective of a statistically naive reviewer." Thank you for pointing to this being superficial, I would love for any help you could give in deepening my understanding. It appeared from context (which was snipped) that you thought one was "better" because its p-value was lower. If the criterion by which you choose one statistical test over another is whether or not it happens to produce a signal p <0.05, then I think you are dredging rather than analyzing. I think the question should be instead whether the test is the most powerful for the particular hypothesis and data situation. 4) "The problem I am trying to solve" is for the following situation: The data set: I am analyzing a data set with subjects (kids) listening to the same music two times (randomized, and on different times and so on), the condition of the experiment is a bit different the first time the kids listens (X=1) then the second time (X=2). And the response (Y) the kid is making for the experiment is recorded as an ordered number of three levels: -1, 0, 1 So you would certainly want a test that properly handles ordinal effects. I am not sure that was clear at all from your earlier questions. Tests of hypotheses regarding ordered alternatives are often more powerful than ones that evaluate less specific alternatives. The (statistical) question: did the difference in the experiment conditions yielded different rankings from the kids? and if so, was there a specific direction? e.g: did kids who by now (in part one of the experiment) answered mostly -1 and 0, now (in part two of the experiment) started answering more 0 and 1? Or, did kids who by now mostly answered 0 now started answering -1 and 1 ? and so on. Analyses approach: There are two basic ways to do this. 1) The first one is a Willcox test, to see if there was change in answers (Y) between the two situations (X=1, X=2) I am here puzzled. Is the Willcox test a well known one in your academic domain? If it is I apologize for my lack of breadth in named tests. Or could you be referring to what is invoked in R with wilcox.test()? I am guessing from context that you might be asking about the Wilcoxon signed-rank test for paired data situations. It would in fact address the ordering of your paired outcomes, but all of the Wilcoxon tests are based on the measures being from a continuous distribution and statistical validity for your situation would be questionable. I would think that a proportional odds model for ordinal repeated responses would fit the data situation and the hypothesis of interest. You may want to search out Laura Thompson's R/S companion to Agresti's text. She has some worked examples. 2) The second one is to produce a 3 by 3 table, with the rows indicating what the kids answered to setting 1 of the experiment, and the columns indicating the kids answers to setting 2. Now the question is: was there marginal homogenity? if not, then that is an indicator that the general response to the experimental settings was different for the kids. Can you put into natural language what you will explain to your audience once you determine the presence or absence of "marginal homogeneity"? Challenges: 1) what about symmetry ? As Peter pointed out - you can easily check that the following two matrices have the same homogeneous margins, but only one is symmetric: 3 2 1 2 3 2 1 2 3 3 1 2 3 3 1 0 3 3 And running the two tests we have yields very interesting results (and if someone has an explanation for them, they would be greatly appreciated): > tt <- as.table(t(matrix(c(30,10,20, + 30,30 ,10, + 0 ,30 ,30) + , ncol [TRUNCATED] The
Re: [R] heatmap plot
2009/7/20 Markus Mühlbacher : > Gives the attached image. Again I am missing the white diagonal. Is there > some kind of sorting that I do not consider? Maybe col=c("white",heat.colors(100)) will do the trick? -- Michael Knudsen micknud...@gmail.com http://lifeofknudsen.blogspot.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Solving two nonlinear equations with two knowns
I just realized that the problem occurs when b becomes smaller than -1 during iterations, causing the integral to be divergent (it is infinite at u = tau). So, you have to constrain your exponent to be greater than -1. There is no way to constrain parameters in dfsane. However, you can do a parameter transform such that b + 1 is positive. Define b = exp(k) - 1, and work with "k" as your parameter. This might help. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of yh...@illinois.edu Sent: Sunday, July 19, 2009 9:39 PM To: Ravi Varadhan; Berend Hasselman; r-help@r-project.org Subject: Re: [R] Solving two nonlinear equations with two knowns I try to use integrate command to get theoretical mean and variance, and then solve for a and b. I have an error as follows, Iteration: 0 ||F(x0)||: 2.7096 Error in integrate(InverseF1, tau, 1, mu = mu2, sigma = sigma2, a = a, : non-finite function value Any suggestion? #R code: mu2=0.4 sigma2=4 tau=0.75 mean.diff=2 var.ratio=3 InverseF1<-function(u,mu,sigma,a,b,tau) { qnorm(u,mean=mu,sd=sigma)+a*(abs(u-tau))^b*(u>tau) } InverseF2<-function(u,mu,sigma) { qnorm(u,mean=mu,sd=sigma) } part1<-function(u,mu,sigma,a,b,tau) { (InverseF2(u,mu,sigma)+a*(abs(u-tau))^b*(u>tau))^2 } part2<-function(u,mu,sigma) { InverseF2(u,mu,sigma)^2 } parameter<- function(cons) { a<-cons[1] b<-cons[2] f <- rep(NA, 2) EX<-integrate(InverseF2,0,tau,mu=mu2,sigma=sigma2)$value+integrate(InverseF1 ,tau,1,mu=mu2,sigma=sigma2,a=a,b=b,tau=tau)$value EY<-integrate(InverseF2,0,1,mu=mu2,sigma=sigma2)$value VarX<-integrate(part2,0,tau,mu=mu2,sigma=sigma2)$value+integrate(part1,tau,1 ,mu=mu2,sigma=sigma2,a=a,b=b,tau=tau)$value-EX^2 VarY<-integrate(part2,0,1,mu=mu2,sigma=sigma2)$value-EY^2 f[1] <- abs(EX - EY) - mean.diff f[2] <- sqrt(VarX) - sqrt(var.ratio) * sqrt(VarY) f } library(BB) c0<-c(3,1) ans1 <- dfsane(par=c0, fn=parameter, method=3) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Solving two nonlinear equations with two knowns
As the error message tells you, the problem is in integrating InverseF1(). I would recommend that the you breakup the integrand into two terms, the first term with `qnorm(...)' and the second part involving the `a*(abs(u-tau))^b*(u>tau)' term. It is the second term that causes trouble . But you can integrate this term analytically. So, do that and plug it into the expression for EX and varX. This should work, I think. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of yh...@illinois.edu Sent: Sunday, July 19, 2009 9:39 PM To: Ravi Varadhan; Berend Hasselman; r-help@r-project.org Subject: Re: [R] Solving two nonlinear equations with two knowns I try to use integrate command to get theoretical mean and variance, and then solve for a and b. I have an error as follows, Iteration: 0 ||F(x0)||: 2.7096 Error in integrate(InverseF1, tau, 1, mu = mu2, sigma = sigma2, a = a, : non-finite function value Any suggestion? #R code: mu2=0.4 sigma2=4 tau=0.75 mean.diff=2 var.ratio=3 InverseF1<-function(u,mu,sigma,a,b,tau) { qnorm(u,mean=mu,sd=sigma)+a*(abs(u-tau))^b*(u>tau) } InverseF2<-function(u,mu,sigma) { qnorm(u,mean=mu,sd=sigma) } part1<-function(u,mu,sigma,a,b,tau) { (InverseF2(u,mu,sigma)+a*(abs(u-tau))^b*(u>tau))^2 } part2<-function(u,mu,sigma) { InverseF2(u,mu,sigma)^2 } parameter<- function(cons) { a<-cons[1] b<-cons[2] f <- rep(NA, 2) EX<-integrate(InverseF2,0,tau,mu=mu2,sigma=sigma2)$value+integrate(InverseF1 ,tau,1,mu=mu2,sigma=sigma2,a=a,b=b,tau=tau)$value EY<-integrate(InverseF2,0,1,mu=mu2,sigma=sigma2)$value VarX<-integrate(part2,0,tau,mu=mu2,sigma=sigma2)$value+integrate(part1,tau,1 ,mu=mu2,sigma=sigma2,a=a,b=b,tau=tau)$value-EX^2 VarY<-integrate(part2,0,1,mu=mu2,sigma=sigma2)$value-EY^2 f[1] <- abs(EX - EY) - mean.diff f[2] <- sqrt(VarX) - sqrt(var.ratio) * sqrt(VarY) f } library(BB) c0<-c(3,1) ans1 <- dfsane(par=c0, fn=parameter, method=3) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] randomForest - what is a 'good' pseudo r-squared?
Hi all I have been trying to use the randomForest package to model insect species abundance in different habitats and identify the key variables (landscape/climate etc) in determining abundance, which has all worked fine and I get nice variable importance plots etc. Many thanks to everyone on this help forum who has given tips/advice along the way. But the percentage variance explained /pseudo r squared reported when I call print(model) is quite low, depending on the species being modelled it ranges from a maximum of 23.69 right down to -2.08. I believe that the minus value represents a model that performs no better / worse than random and obviously the larger the R^2 gets the better the predictive ability but over what range does this r^2 operate? As it is not unexpected that some of these models would have poor predictive accuracy as part of the larger project around this work is to say finer resolution remotely sensed satellite imagery is needed to derive the climate variables etc being used to predict species abundance. My question is probably a bit like how long is a piece of string but if anyone could offer some guidance on what constitutes a good / very good / bad / very bad r-squared value for random forest it would be most appreciated and if there are any other accuracy measure that can be used with Random Forest in addition to the pseudo r^2 value? as this work will be presented to an entomology/ecology audience where machine learning is a bit outside their (and my) statistics comfort zone. Many thanks in advance Lara lara.har...@bbsrc.ac.uk [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Argument problem in function wrapper
Dear all, we are writing a wrapper for the nls function in library stats. We are having a problem with one of the arguments (weightsArgument) which seems not to reach nls even if we explicitly assign it in the function call. We are attaching the simplest code reproducing the error and the output calling the wrapper and calling nls directly. We are using R 2.9.0 library(stats) wrappernls <- function(modelArgument,dataArgument,startArgument,weightsArgument) { F.mod <-try(nls(formula=modelArgument,data=dataArgument,start=startArgument, weights=weightsArgument, control=nls.control(maxiter = 500, tol = 1e-05, minFactor = 1/102400)),silent=TRUE) return(F.mod) } F<-c(0.4091867,0.4060938,0.4032078,0.4089090,0.4138126,0.4183426,0.4073004,0.4145457,0.4137699, 0.4161127,0.4228770,0.4231176,0.4295189,0.4290417,0.4348761,0.4517475,0.4899147,0.5463731, 0.6273890,0.7458752,0.8960531,1.0280455,1.1753147,1.3122100,1.4370375,1.5610782,1.418, 1.7771591,1.8853868,1.9628042,2.0407750,2.1179830,2.1647203,2.2147800,2.2848194,2.3442066, 2.3706858,2.4121310,2.4508073,2.4767710) skipCycles=3; y00<-max(F); a0<- min(F)-y00; x00<-which.min(abs(F-(a0/2+y00))); derivativeAtc0= (F[x00+1]-F[x00-1])/2 b0=-4*x00*derivativeAtc0/a0 w<-c(rep(0,skipCycles), rep(1,length(F)-skipCycles)) x=1:length(F); modelArg=F ~ y0+D*x+a/(1+(x/x0)^b) dataArg=data.frame(F,x) startArg=list(y0 = y00, a=a0, x0=x00, b=b0, D=0) weightsArg=w F.modWrapper <- wrappernls(modelArg,dataArg,startArg,weightsArg) F.mod <- nls(formula=modelArg,data=dataArg,start=startArg,weights=weightsArg, control=nls.control(maxiter = 500, tol = 1e-05, minFactor = 1/102400)) *Output in R:* > F.mod Nonlinear regression model model: F ~ y0 + D * x + a/(1 + (x/x0)^b) data: dataArg y0 a x0 b D 2.891357 -2.434011 25.604522 5.880144 -0.007322 weighted residual sum-of-squares: 0.02664 Number of iterations to convergence: 8 Achieved convergence tolerance: 3.517e-06 > F.modWrapper [1] "Error in eval(expr, envir, enclos) : object 'weightsArgument' not found\n" attr(,"class") [1] "try-error" Any help about this will be welcome. Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Entire Organization Switching from SAS to R - Any experience?
Jeffrey J. Hallman wrote: Hmmm, I sense a story in the offing. Was that an accidental emergency, or one you created? Frank E Harrell Jr writes: I differ with Marc in one way. It is amazing what people can learn when you create an emergency for them to do so. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University Lots of little emergencies with good results. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Automatically assign symbol for statistical significance to x given value of x
On Mon, Jul 20, 2009 at 5:47 PM, Marc Schwartz wrote: > > The simple answer is to use symnum(), which is the function the generates > the symbology for those tables in R where the 'significance stars' are > included. For example, when printing a linear model summary where > printCoefmat() is used. See the last example in ?symnum for more > information. > > The philosophical challenge that you will face is that a lot of people are > not favorably disposed to the use of this symbology. So the use or non-use > of them may be dependent upon your own feelings and those of the consumers > of your output. See ?options and note 'show.signif.stars', which a lot of > folks, myself included, set to FALSE in .Rprofile. > > HTH, > > Marc Schwartz > Thank you very much Marc, the symnum function worked perfectly and I hadn't heard of it until now. With regards to the philosophical challenge; I don't really have an option since (most) journals (in social science) require such symbols. Thanks again! Best regrads, Tormod Bøe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Another SEM question
Luba, If you could provide the code you ran, perhaps the listserv can be of help. On Jul 20, 2009, at 7:55 AM, Stein, Luba (AIM SE) wrote: Hello, I use the function sem the following way sem.mod <- sem(model, mod.cov, N=109) where the variables are modelled: Z -> M Z -> I Z -> R M <-> M I <-> I R <-> R Z <-> Z The output is ... Normalized Residuals Min. 1st Qu. Median Mean 3rd Qu. Max. -7.3300 -0.2750 -0.2670 -0.1290 -0.0369 9.0300 Parameter Estimates Estimate Std Error z value Pr(>|z|) 0.0021625 0.00017037 12.693 0 M <--- Z Iterations = 13 In "Structural Equation Modeling With the sem Package in R" by John Fox is stated that there should be an output for each external variable. Where is my fault, that I receive the output only for the first variable? Thanks for your help, Luba [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] class export in package creation / setClass / namespace?
Thanks, the issue was solved by adding class definitions to the zzz.R file in the R code directory. However, this led to a new problem. The zzz.R now contains class definition: > setClass("myclass", contains = "list") and method definition for the new class, extending the generic 'show': > setGeneric("show",function(x,...){standardGeneric("show")}) > setMethod("show", "myclass",function(x, ...) {cat("myclass object \n")}) I get two warnings. The first one: * checking Rd files ... WARNING Rd files with duplicated alias 'show,myclass-method': myclass-class.Rd show-methods.Rd I get this one because the alias row for the method (\alias{show,myclass-method}) is in both myclass-class.Rd file and show-methods.Rd file (created by promptMethods function). This is likely related to the second warning: * checking for missing documentation entries ... WARNING Undocumented code objects: show I thought that the show method would've been documented correctly as I put 'show-methods.Rd' file in the 'man' directory. This does not seem to be the case, however. Any help on how I should document the extended show method in this case, or are there some mistakes in my original definition for extended 'show'? I could not find suitable examples from the web/mailing lists. br Leo On Fri, Jul 10, 2009 at 5:37 AM, Martin Morgan wrote: > L L wrote: > > Dear all, > > > > I have been trying to create an R package. This has been successfull > until I > > tried to define classes. > > > > Currently, my procedure is the following: > > > > Start R, load the function and class definition > >> tmp <- function (x) {x} > >> setClass("rpa", contains = "list", where=topenv(parent.frame())) > > > > Use package skeleton to create directory structure: > >> package.skeleton(name = "test",list=c("tmp")) > > I don't think package.skeleton knows to copy the class definition to the > R files; I think you have to do that yourself -- is there a > setClass("rpa", contains="list") instruction in the R files created by > package.skeleton? > > Martin > > > > Edit man files, add test/NAMESPACE file with the following contents: > >> export(tmp) > >> exportClasses("rpa") > > > > Use R CMD check and R CMD build to create tarball. > > -> No error messages. > > > > Start R, install the created package: > >> install.packages("test_1.0.tar.gz",repos=NULL) > > > > Test the new package: > >> require(test) > >> my.object = new("rpa") > > > > This gives the error message > >> Error in getClass(Class, where = topenv(parent.frame())) : > >> "rpa" is not a defined class > > > > Any tips on how to define and export global classes in package creation? > > > > I also tried > > - to replace the 'topenv(parent.frame())' with '.GlobalEnv' in setClass. > > - place the setClass within function 'tmp' > > - exportClasses(rpa) in the namespace (without suffixes "") > > > > I paged through the related mailing list discussions but could not find a > > solution. Any tips and tricks would be worthwhile now; I guess this > should > > be a standard issue but it seems a bit tricky to come up with a quick > > solution with the little programming experience that I have. > > > > kind regards > > Leo Lahti > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] heatmap plot
2009/7/20 Markus Mühlbacher : > What is my mistake? I don't know about the heatmap function, but I have often used 'image' with 'heat.colors' without any problems. There is a nice example here: http://addictedtor.free.fr/graphiques/graphcode.php?graph=20 It should be fairly easy to fit your data into that one. I guess that this should work: x = 1:length(activity.matrix) y = 1:length(activity.matrix) image(x, y, activity.matrix, col=heat.colors(100)) -- Michael Knudsen micknud...@gmail.com http://lifeofknudsen.blogspot.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] sweave output
Hi I am using sweave and have read somewhere a way of adding ... when printing vectors / dataframes which are longer then a given length, but I can't find this anymore. Could somebody point me into the right direction, where I could find it? Thanks Rainer -- Rainer M. Krug, Centre of Excellence for Invasion Biology, Stellenbosch University, South Africa __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Naming Conventions
partial answer: ?make.names Also ?UseMethod for S3 related names. Bert Gunter Genentech Nonclinical Biostatistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of escher2079 Sent: Monday, July 20, 2009 8:40 AM To: r-help@r-project.org Subject: [R] Naming Conventions Hi, I was wondering about naming conventions for functions in R. I wasn't able to find anything official, just this document, which seemed reasonable but you never know with things found on the internet: http://www1.maths.lth.se/help/R/RCC/ When submitting packages to CRAN, is there a commonly accepted way (specific to R) for naming functions? Thanks! -- View this message in context: http://www.nabble.com/Naming-Conventions-tp24572162p24572162.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] what is meaning of the bubbles in boxplots?
You may be looking for the range=0 argument to boxplot(). -thomas On Mon, 20 Jul 2009, Douglas Bates wrote: On Mon, Jul 20, 2009 at 5:18 AM, Jie TANG wrote: Hi ,everyone , I draw some boxplot figure with the command "boxplot".But in the figure,there are some bubbles at the top part of the figure. Can anyone tell me what the correct meaning of these bubbles?and how to remove it? Those are data points that are considered to be outliers. As to how to remove them, that's a tricky question, more as to why than how. The purpose of showing those points in a different way is to emphasize that those points deserve special attention. You do not want to just "make them go away". __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Automatically assign symbol for statistical significance to x given value of x
On Jul 20, 2009, at 10:36 AM, Tormod Bøe wrote: Dear r-help users, I am using Sweave and Latex to create tables with output from several statistical test. As an example: I have a grouping variable "group" with two levels ("x" and "y") which I compare on variables ("a" and "b"). I have created a table in which means, standard deviations, and the statistic and p.value resulting from a t.test is printed. The table looks something like: group(x) group(y) meansdmean sd t-value p-value sig. mean(x,a) sd(x,a) mean(y,a) sd(y,a)t.a p.a mean(x,b) sd(x,b) mean(y,b) sd(y,b)t.b p.b What I would like to be able to add to this table is an indication by means of asterisks ("*") the level of significance of the p.value(s). I am after an expression to put in column "sig." which evaluates the p.value and prints *, ** or *** depending on it's value (e.g. if it is less than .05 print "*", but if it is less than .01 print "**", but if it is less than .001 print "***", else print " "). I am able to use a simple function like if (p.value<0.5) print("*") else print(" "), but I have not been able to work out how to nest the "if" expressions correctly. Any help would be greatly appreciated. Best regards, Tormod Bøe The simple answer is to use symnum(), which is the function the generates the symbology for those tables in R where the 'significance stars' are included. For example, when printing a linear model summary where printCoefmat() is used. See the last example in ?symnum for more information. The philosophical challenge that you will face is that a lot of people are not favorably disposed to the use of this symbology. So the use or non-use of them may be dependent upon your own feelings and those of the consumers of your output. See ?options and note 'show.signif.stars', which a lot of folks, myself included, set to FALSE in .Rprofile. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] (-8)^(1/3) == NaN?
On Sun, 19 Jul 2009, jim holtman wrote: If the power that a number is being raised to is integer, then is does evaluate honoring the unary minus. (-2) ^ 5 #integer power [1] -32 (-2) ^ 5.1 [1] NaN Yes. 3 is representable exactly as a whole number, so (-2)^3 exists, but (1/3) is represented as a fraction whose denominator is 2^54, an even number, so (-8)^(1/3) does not exist (as a real number). More generally, since all floating point numbers are represented as fractions whose denominator is a power of 2, the only way a floating point number can be a legitimate exponent for a negative base is if it represents a whole number. -thomas -8^(1/3) is parsed as -(8^(1/3)) according to operator precedence. On Sun, Jul 19, 2009 at 4:49 PM, Liviu Andronic wrote: On Sun, Jul 19, 2009 at 12:28 AM, jim holtman wrote: First of all, read FAQ 7.31 to understand that 1/3 is not representable in floating point. Also a^b is actually exp(log(a) * b) and log(-8) is not valid (NaN). If this is so, why would the following evaluate as expected? (-8)^(3) [1] -512 Liviu -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Naming Conventions
Hi, I was wondering about naming conventions for functions in R. I wasn't able to find anything official, just this document, which seemed reasonable but you never know with things found on the internet: http://www1.maths.lth.se/help/R/RCC/ When submitting packages to CRAN, is there a commonly accepted way (specific to R) for naming functions? Thanks! -- View this message in context: http://www.nabble.com/Naming-Conventions-tp24572162p24572162.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] heatmap plot
Dear R community! I am trying to create a heatmap based on the following data. As you can see the diagonal (0,0 to 10,10) is always 0). If I run the heatmap command like i posted it I get a graph with horizontal lines. What is my mistake? > heatmap(activity.matrix, Rowv = NA, Colv = NA, scale="column", xlab="x > Compounds", ylab="y Compounds", col=topo.colors(100)) > activity.matrix [,1] [,2] [,3][,4] [,5] [,6] [1,] 0.000 -0.1017802 0.3635007 0.62522118 0.8869417 -0.4652809 [2,] 0.1017802 0.000 0.4652809 0.72700138 0.9887219 -0.3635007 [3,] -0.3635007 -0.4652809 0.000 0.26172050 0.5234410 -0.8287816 [4,] -0.6252212 -0.7270014 -0.2617205 0. 0.2617205 -1.0905021 [5,] -0.8869417 -0.9887219 -0.5234410 -0.26172050 0.000 -1.356 [6,] 0.4652809 0.3635007 0.8287816 1.09050206 1.356 0.000 [7,] -0.2471805 -0.3489607 0.1163202 0.37804072 0.6397612 -0.7124613 [8,] 1.0032619 0.9014817 1.3667626 1.62848308 1.8902036 0.5379810 [9,] -0.6833813 -0.7851615 -0.3198806 -0.05816011 0.2035604 -1.1486622 [10,] 1.0759620 0.9741818 1.4394627 1.70118322 1.9629037 0.6106812 [,7][,8][,9] [,10] [1,] 0.2471805 -1.00326190 0.68338129 -1.07596204 [2,] 0.3489607 -0.90148171 0.78516149 -0.97418184 [3,] -0.1163202 -1.36676259 0.31988061 -1.43946272 [4,] -0.3780407 -1.62848308 0.05816011 -1.70118322 [5,] -0.6397612 -1.89020358 -0.20356039 -1.96290371 [6,] 0.7124613 -0.53798102 1.14866217 -0.61068116 [7,] 0.000 -1.25044237 0.43620083 -1.32314250 [8,] 1.2504424 0. 1.68664319 -0.07270014 [9,] -0.4362008 -1.68664319 0. -1.75934333 [10,] 1.3231425 0.07270014 1.75934333 0. Thanks in advance. Greets, Markus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Automatically assign symbol for statistical significance to x given value of x
Dear r-help users, I am using Sweave and Latex to create tables with output from several statistical test. As an example: I have a grouping variable "group" with two levels ("x" and "y") which I compare on variables ("a" and "b"). I have created a table in which means, standard deviations, and the statistic and p.value resulting from a t.test is printed. The table looks something like: group(x) group(y) mean sd mean sd t-value p-value sig. mean(x,a) sd(x,a) mean(y,a) sd(y,a) t.a p.a mean(x,b) sd(x,b) mean(y,b) sd(y,b) t.b p.b What I would like to be able to add to this table is an indication by means of asterisks ("*") the level of significance of the p.value(s). I am after an expression to put in column "sig." which evaluates the p.value and prints *, ** or *** depending on it's value (e.g. if it is less than .05 print "*", but if it is less than .01 print "**", but if it is less than .001 print "***", else print " "). I am able to use a simple function like if (p.value<0.5) print("*") else print(" "), but I have not been able to work out how to nest the "if" expressions correctly. Any help would be greatly appreciated. Best regards, Tormod Bøe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Another SEM question
Hello, I use the function sem the following way sem.mod <- sem(model, mod.cov, N=109) where the variables are modelled: Z -> M Z -> I Z -> R M <-> M I <-> I R <-> R Z <-> Z The output is ... Normalized Residuals Min. 1st Qu. Median Mean 3rd Qu. Max. -7.3300 -0.2750 -0.2670 -0.1290 -0.0369 9.0300 Parameter Estimates Estimate Std Error z value Pr(>|z|) 0.0021625 0.00017037 12.693 0 M <--- Z Iterations = 13 In "Structural Equation Modeling With the sem Package in R" by John Fox is stated that there should be an output for each external variable. Where is my fault, that I receive the output only for the first variable? Thanks for your help, Luba [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] What is the Datasets License?
On Sat, Jul 18, 2009 at 6:28 PM, Duncan Murdoch wrote: > On 18/07/2009 6:06 PM, Skipper Seabold wrote: >> >> Hello, >> >> I saw that this question has been asked here before but couldn't find >> an answer. Are the raw datasets in R in the public domain? Most are >> based on quite old "classic" published results, so I would then assume >> that the raw data is public domain rather than GPL. Can anyone answer >> this definitively, or is this maybe a question for R-devel? > > The datasets package is part of R, so it is licensed under the GPL. Some > parts of it may come from sources with more permissive licenses. In Canada, > I believe the data itself (as opposed to the expression of it in the > datasets package or in the original sources) is generally not copyrightable, > but rules may differ where you live. > Ok, this is what I suspected. I don't mean the datasets package, but rather the columns of data used in the datasets package that have been taken from published papers. The Canadian position seems to make sense to me, and I will have a closer look at the law here. > The file docs/COPYRIGHTS lists a number of details of who owns copyright on > various bits and pieces, but I don't see anything about the datasets package > mentioned there. > > I think very little of R is in the public domain, but parts are likely based > on public domain materials. > > Duncan Murdoch > Thanks, Skipper __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] S4 method dispatch with inheritance
Hi, I'm trying to create a new S4 class (myMatrix) which for now just extends dgCMatrix (from package Matrix). Then I want to use "[" which is defined in Matrix. Out of the box with "[" (defined in Matrix) I lose the class information and the result is an object of class dgCMatrix. If I specify a "["-method for myMatrix, it is not used because a signature from Matrix seems to fit better. However, the most important part of the signature is the class of x (all else have ANY). Is there a way to specify a single "["-method do make it work for myClass? Thanks, Michael > library("Matrix") Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from package:stats : xtabs The following object(s) are masked from package:base : rcond > > setClass("myMatrix", + contains="dgCMatrix" + ) [1] "myMatrix" > > my <- as(as(rbind(1:10,1:10,1:10), "dgCMatrix"), "myMatrix") > > ## here I lose the class "myMatrix" > class(my[1:2,]) [1] "dgCMatrix" attr(,"package") [1] "Matrix" > > ## make sure [ keeps the class > setMethod("[", signature(x = "myMatrix", i = "ANY", j = "ANY", + drop = "ANY"), + function(x, i, j, ..., drop) { + x<- as(x, "dgCMatrix")[i, j, ..., drop] + as(x, "myMatrix") + }) [1] "[" > > ## and now it does not use the method defined above. > class(my[1:2,]) Note: Method with signature "Matrix#index#missing#missing" chosen for function "[", target signature "myMatrix#integer#missing#missing". "myMatrix#ANY#ANY#ANY" would also be valid Note: Method with signature "sparseMatrix#index#missing#logical" chosen for function "[", target signature "myMatrix#integer#missing#logical". "myMatrix#ANY#ANY#ANY" would also be valid [1] "dgCMatrix" attr(,"package") [1] "Matrix" > sessionInfo() R version 2.9.1 (2009-06-26) i486-pc-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Matrix_0.999375-29 lattice_0.17-25 loaded via a namespace (and not attached): [1] grid_2.9.1 -- Michael Hahsler email: mich...@hahsler.net web: http://michael.hahsler.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mahalanobis distance
On Mon, Jul 20, 2009 at 3:08 PM, ekinakoglu wrote: > Error in solve.default(cov, ...) : > system is computationally singular: reciprocal condition number = > 1.65972e-18 Try calculating the determinant of the S matrix: > det(S) [1] 2.825397e-06 It's very close to zero, and I guess that the matrix is therefore considered non-invertible by R. Recall that S must be invertible http://en.wikipedia.org/wiki/Mahalanobis_distance to work as a covarinace matrix in the definition of the Mahalanobis distance. -- Michael Knudsen micknud...@gmail.com http://lifeofknudsen.blogspot.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.