[R] Cann't assign NULL to a vector
Due to over-sized matrix from combn(letters,13), I tried to only output one selection which is satisfied with the criteria in if clause. This is how my code looks like and the ERROR message shows: > li<-combn(letters,13,function(x)(if(apply(( (as.matrix(t(letters%in% x))) %*% > as.matrix(z) )**2,1,sum)==balance){x}else {x=NULL})) Error in matrix(r, nrow = len.r, ncol = count) : attempt to set an attribute on NULL Can anybody know how to solve this problem? Thanks in advance! Snow [[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] Problems with intersections between two charcter vectors
I'm a beginner with R. I have two vectors in character format. I tried to get the intersection of these two vectors using intersect£¨£©. But there is no result. The process is below: > a<-c("CREB2¡± ,¡°ELK1¡± ,¡°ELK4¡± ,¡°MYC¡± ,¡°NR4A1¡± ,¡°FOS¡± ,¡°SRF¡± > ,¡°TAU¡± ,¡°STMN1¡± ,¡°CPLA2")> a[1] "CREB2¡± ,¡°ELK1¡± ,¡°ELK4¡± ,¡°MYC¡± > ,¡°NR4A1¡± ,¡°FOS¡± ,¡°SRF¡± ,¡°TAU¡± ,¡°STMN1¡± ,¡°CPLA2"> > b<-c("CAMK2¡±,¡°CPKC¡±,¡°CBL¡±,¡°STAT5A¡±,¡°FAK¡±,¡°ABL1¡±,¡°JUN¡±,¡°ELK1¡±,¡°MYC")> > b[1] > "CAMK2¡±,¡°CPKC¡±,¡°CBL¡±,¡°STAT5A¡±,¡°FAK¡±,¡°ABL1¡±,¡°JUN¡±,¡°ELK1¡±,¡°MYC"> > intersect(a,b)character(0) However when I tried intersect£¨£©with another two vectors, it works. The example is like this: > c<-c("a", "b", "e", "c", "e", "f")> c[1] "a" "b" "e" "c" "e" "f"> d<-c("a", > "g", "f", "b", "e")> d[1] "a" "g" "f" "b" "e"> intersect(c,d)[1] "a" "b" "e" > "f" I think something must be wrong in my way with first two vectors(a,b). Could anyone give me a kind help to tell me the reason for that? Thank you very much. Hui Xue [[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] reply: Problems with intersections between two charcter vectors
Dec 04, 2013; 4:14pm Berend Hasselman" wrote: On 04-12-2013, at 07:52, snow <[hidden email]> wrote: > I'm a beginner with R. > > I have two vectors in character format. I tried to get the intersection of > these two vectors using intersectï¼ï¼. But there is no result. The process > is below: >> a<-c("CREB2â ,âELK1â ,âELK4â ,âMYCâ ,âNR4A1â ,âFOSâ >> ,âSRFâ ,âTAUâ ,âSTMN1â ,âCPLA2")> a[1] "CREB2â ,âELK1â >> ,âELK4â ,âMYCâ ,âNR4A1â ,âFOSâ ,âSRFâ ,âTAUâ >> ,âSTMN1â ,âCPLA2"> >> b<-c("CAMK2â,âCPKCâ,âCBLâ,âSTAT5Aâ,âFAKâ,âABL1â,âJUNâ,âELK1â,âMYC")> >> b[1] >> "CAMK2â,âCPKCâ,âCBLâ,âSTAT5Aâ,âFAKâ,âABL1â,âJUNâ,âELK1â,âMYC"> >> intersect(a,b)character(0) > However when I tried intersectï¼ï¼with another two vectors, it works. The > example is like this: >> c<-c("a", "b", "e", "c", "e", "f")> c[1] "a" "b" "e" "c" "e" "f"> d<-c("a", >> "g", "f", "b", "e")> d[1] "a" "g" "f" "b" "e"> intersect(c,d)[1] "a" "b" "e" >> "f" > I think something must be wrong in my way with first two vectors(a,b). Could > anyone give me a kind help to tell me the reason for that? Thank you very > much. > What is displayed in Apple Mail is a mess since you posted in html. It seems that some of your double quotes â have been converted somewhere to typographic double quotes (or however they should be called). Some of your output is weird: a[1] would display âCREB2â only and not what you show in your mail. Doing it like this using proper ascii double quotes: a<-c("CREB2" ,"ELK1" ,"ELK4" ,"MYC" ,"NR4A1" ,"FOS" ,"SRF" ,"TAU" ,"STMN1" ,"CPLA2") b<-c("CAMK2","CPKC","CBL","STAT5A","FAK","ABL1","JUN","ELK1","MYC") intersect(a,b) displays: [1] "ELK1" âMYC" which is what you expected? Berend Thank you very much, Berend. I have tried your way and it did work. I think that something wrong in my word setting cause that probelm. I really appreciated the warm hearted help from you and jholtman. sincerely, Hui Xue [[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] Copy text from Script syntax into .txt
Look at the spin and stitch functions in the knitr package if you want to process an existing script into an output that mixes the code run with the output. Look at the txtStart and related functions in the TeachingDemos package if you want the code and output saved in a file from a session where you are typing in commands. If in general you want text, code, and output mixed, learn the knitr and/or rmarkdown packages for how to write a file that can be processed into a report. Also consider learning about RStudio notebook documents where you can have the output mixed into the "script" file. On Tue, Apr 24, 2018 at 3:23 AM, P. Roberto Bakker wrote: > Hi everybody, > > How can I get text from RScript (e.g. syntax, reminder) into the result > text. > Sink() does not do that - I only read the results and therefore I have to > 'guess' which syntax was used where - reminders I wrote are lost. > > Bw and thank you in advance, > > Roberto > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot Arrows with Angle and length
You can also look at the my.symbols and ms.arrows functions in the TeachingDemos package. On Wed, Mar 29, 2017 at 7:44 AM, julio cesar oliveira wrote: > Dears, > > The arrows command uses the start and end coordinates of each vector, but I > have the starting coordinates, azimuth, and length. > > So, There are package that plot this arrows? > > Example: > >> x<- c(1,2,4) >> y<- c(2,3,5) >> Azimuth<- c(45,90,180) >> Length<- c(1,0.5,1) > > > Thanks, > > Julio > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Power test binominal GLM model
You may find the answers to this question on Cross Validated (along with the discussion) to be useful: https://stats.stackexchange.com/questions/35940/simulation-of-logistic-regression-power-analysis-designed-experiments On Tue, Oct 10, 2017 at 10:09 AM, davide cortellino wrote: > Dear All > > > I have run the following GLM binominal model on a dataset composed by the > following variables: > > TRAN_DURING_CAMP_FLG enviados bono_recibido > 01 benchmark > 01 benchmark > 01 benchmark > 01 benchmark > 01 benchmark > 01 benchmark > > >- tran_during_flag= redemption yes/no (1/0) >- enviados= counter variables, all 1's >- bono_recibido= benchmark(control group) or test groups (two type of >test groups) > > The model used has been > > glm(TRAN_DURING_CAMP_FLG~bono_recibido,exp2,family="binomial") > > Estimate Std. Error z value > Pr(>|z|)(Intercept) -1.4924117 0.01372190 -108.761315 > 0.00e+00 > bono_recibidoBONO3EUROS -0.8727739 0.09931119 -8.788274 1.518758e-18 > bono_recibidoBONO6EUROS 0.1069435 0.020438405.232480 1.672507e-07 > > The scope for this model was to test if there was significative difference > in the redemption rate between control group and test groups. Now, applying > the post hoc test: > >> Treat.comp<-glht(mod.binposthoc,mcp(bono_recibido='Tukey'))> >> summary(Treat.comp) # el modelo se encuentra en log odds aqui > > Simultaneous Tests for General Linear Hypotheses > Multiple Comparisons of Means: Tukey Contrasts > > Fit: glm(formula = TRAN_DURING_CAMP_FLG ~ bono_recibido, family = "binomial", > data = exp2) > Linear Hypotheses: > Estimate Std. Error z value Pr(>|z|) > BONO3EUROS - benchmark == 0 -0.872770.09931 -8.788 < 1e-09 *** > BONO6EUROS - benchmark == 0 0.106940.02044 5.232 3.34e-07 *** > BONO6EUROS - BONO3EUROS == 0 0.979720.09952 9.845 < 1e-09 > ***---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ > 1(Adjusted p values reported -- single-step method) > > It confirm that the differences are significatively differents, however, I > would check the power of the model in assessing these differences. I have > checked several time both on cross validates and on the web but it seems > there is no pre-made function which enable the user to compute the power of > glm models. Is it the case? Does anyone know of available packages or > methodologies to achive a power test in a glm binominal model? > > Bests > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] comparing two strings from data
The error is because the read.csv function converted both columns to factors. The simplest thing to do is to set stringsAsFactors=FALSE is the call to read.csv so that they are compared as strings. You could also call as.character on each of the columns if you don't want to read the data in again. Also, look at the match function, I think it will give you what you want without the explicit looping. On Thu, Oct 12, 2017 at 2:25 PM, Yasin Gocgun wrote: > Hi, > > I have two columns that contain numbers along with letters (as shown below) > and have different lengths. Each entry in the first column is likely to be > found in the second column at most once. > > For each entry of the first column, if that entry is found in the second > column, I would like to get the corresponding index. For instance, if the > first entry of the first column is 5th entry in the second column, I would > like to keep this index 5. > > AST201705534 TUR201701428 > CTS201779930CTS201771989 > CTS201779931 CTS201772015 > > In a loop, when I use the following code to get those indices, > > > data_2 = read.csv("excel_data.csv") > column_1 = data_2$data1 > column_2 = data_2$data2 > > match_list <- array(0,dim=c(310,1)); # 310 is the length of the first > column > > for (indx in 1: 310){ > for(indx2 in 1:713){ # 713 is the length of the second column > if(column_1[indx] == column_2[indx2] ){ > match_list[indx,1] = indx2; > break; > } > } > } > > > R provides the following error: > > Error in Ops.factor(column_1[indx], column_2[indx2]) : > level sets of factors are different > > So can someone explain me how I can resolve this issue? > > Thnak you, > > Yasin > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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's box() (exactly) doing?
You can use the grconvertX and grconvertY functions to find the coordinates (in user coordinates to pass to rect) of the figure region (or other regions). Probably something like: grconvertX(c(0,1), from='nfc', to='user') grconvertY(c(0,1), from='nfc', to='user') On Fri, Jun 24, 2016 at 8:19 PM, Marius Hofert wrote: > Hi Jim, > > Here is a follow-up question: How would you replicate box("figure") > (instead of box() = box("plot"))? > I tried to fill the plotted box but there seems to be no argument to > box("figure") that does that. If that's indeed the case, one could > work again with rect() (thus replicating box("figure")), but how can > one specify the exact location/width/height of the rectangle? (see > example below) > > Cheers, > M > > plot(NA, type = "n", ann = TRUE, axes = TRUE, xlim = 0:1, ylim = 0:1) > box("figure", col = "red", lwd = 2) # how to fill? > > par(xpd = TRUE) > width = 1.4 # obviously not correct... > height <- width > loc.x <- 0.5 > loc.y <- 0.5 > xleft <- loc.x-width/2 > xright <- loc.x+width/2 > ybottom <- loc.y-height/2 > ytop <- loc.y+height/2 > rect(xleft = xleft, ybottom = ybottom, xright = xright, ytop = ytop, > col = adjustcolor("grey80", alpha.f = 0.5)) > par(xpd = FALSE) > > On Fri, Jun 24, 2016 at 8:40 PM, Marius Hofert > wrote: >> Hi Jim, >> >> Thanks a lot, exactly what I was looking for. >> >> Cheers, >> Marius >> >> >> >> On Thu, Jun 23, 2016 at 11:06 PM, Jim Lemon wrote: >>> Hi Marius, >>> There are a few things that are happening here. First, the plot area >>> is not going to be the same as your x and y limits unless you say so: >>> >>> # run your first example >>> par("usr") >>> [1] -0.04 1.04 -0.04 1.04 >>> >>> # but >>> plot(NA, type = "n", ann = FALSE, axes = FALSE, >>> xlim = 0:1, ylim = 0:1,xaxs="i",yaxs="i") >>> box() >>> rect(xleft = 0, ybottom = 0, xright = 1, ytop = 1, col = "grey80") >>> par("usr") >>> [1] 0 1 0 1 >>> >>> Second, the "rect" function is automatically clipped to the plot area, >>> so you may lose a bit at the edges if you don't override this: >>> >>> par(xpd=TRUE) >>> rect(...) >>> par(xpd=FALSE) >>> >>> Finally your second example simply multiplies the first problem by >>> specifying a layout of more than one plot. Applying the "xaxs" and >>> "yaxs" parameters before you start plotting will fix this: >>> >>> par(xaxs="i",yaxs="i") >>> >>> Jim >>> >>> On Fri, Jun 24, 2016 at 12:29 PM, Marius Hofert >>> wrote: >>>> Hi, >>>> >>>> I would like to replicate the behavior of box() with rect() (don't ask >>>> why). >>>> However, my rect()angles are always too small. I looked a bit into the >>>> internal C_box but >>>> couldn't figure out how to solve the problem. Below is a minimal >>>> working (and a slightly bigger) example. >>>> >>>> Cheers, >>>> Marius >>>> >>>> ## MWE >>>> plot(NA, type = "n", ann = FALSE, axes = FALSE, xlim = 0:1, ylim = 0:1) >>>> rect(xleft = 0, ybottom = 0, xright = 1, ytop = 1, col = "grey80") # >>>> should match box() >>>> box() >>>> >>>> ## Extended example >>>> >>>> ## Basic plot >>>> my_rect <- function() >>>> { >>>> plot(NA, type = "n", ann = FALSE, axes = FALSE, xlim = 0:1, ylim = 0:1) >>>> rect(xleft = 0, ybottom = 0, xright = 1, ytop = 1, col = "grey80") >>>> # should match box() >>>> box() >>>> } >>>> >>>> ## Layout >>>> lay <- matrix(0, nrow = 3, ncol = 3, byrow = TRUE) >>>> lay[1,1] <- 1 >>>> lay[2,1] <- 2 >>>> lay[2,2] <- 3 >>>> lay[2,3] <- 4 >>>> lay[3,3] <- 5 >>>> layout(lay, heights = c(1, 10, 1), widths = c(10, 1, 10)) >>>> layout.show(5) # => no space between rectangles; calls box() to draw the >>>> boxes >>>> >>>> ## Fill layout >>>> par(oma = rep(0, 4), mar = rep(0, 4)) >>>> my_rect() >>>> my_rect() >>>> my_rect() >>>> my_rect() >>>> my_rect() >>>> ## => spaces between rectangles => why?/how to avoid? >>>> >>>> __ >>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Turning a variable name into a function argument
There are several options. The option that is most like search and replace is to use the `sub` or `gsub` function (or similar functions in added packages). But you may be able to accomplish what you want even simpler by using the `paste`, `paste0`, or `sprintf` functions. On Tue, Jun 28, 2016 at 12:10 PM, KMNanus wrote: > Thanks for getting back to me, I’m sorry if I was unclear. > > What I’m trying to figure out is the equivalent of “find and replace” in Word. > > I have a function - > > myfun <- function(z){ > ggplot(df, aes(x,y)+ > geom_point() + > ggtitle (“___ quick brown fox jumped over the lazy dog”)} > > Calling myfun(z) works perfectly. What I’m trying to do is add a string to > myfun so that it would read: function(z, “string”){ > > Then I could call myfun(z, “string”) to replace the space in ggtitle. Is > there a straightforward way to do that? > > Ken > kmna...@gmail.com > 914-450-0816 (tel) > 347-730-4813 (fax) > > > >> On Jun 28, 2016, at 12:20 PM, David Winsemius wrote: >> >>> >>> On Jun 27, 2016, at 6:12 PM, KMNanus wrote: >>> >>> I’m inexperience but am trying to get my head around using functions to >>> make a number of ggplots easier to do. >>> >>> I have a function that creates a ggplot taking one input variable as an >>> argument. The variable name is shorthand for the actual variable (variable >>> name = tue, Actual name = Tuesday). Since I want to use the actual >>> variable name in ylab and ggtitle, I’d like to add a second argument, >>> new.name, to the function which would allow me to utilize both inputs as >>> arguments but have not been successful. I tried creating a function within >>> the function to accomplish this, using deparse(substitute(new.name))and >>> also using the code you see below. >>> >>> >>> myfun <- function(myvar, new.name){ >>> function(new.name){return(as.character(substitute(new.name)))} >>> ggplot(b12.2, aes(x= games, y = myvar, col = Group))+ >>> geom_point() + >>> geom_line()+ >>> xlab("Minimum Games" ) + >>> ylab(paste(new.name, “Average Change"))+ >>> ggtitle(new.name, "Change \n as a Function of Minimum Number of Games”)+ >>> theme_bw() >>> >>> When call myfun(myvar, new.name), I get an error msg “new.name is not >>> found” whether I call new.name or Tuesday. >> >> Q1: At the moment we have no idea _how_ you might be "calling" this >> function. We also do not know what might be assigned to `myvar` or >> `new.name` in the calling environment. Sounds unlikely that you are typing: >> >> myfun(myvar, new.name) ## ?, so was there a loop/lapply calling method? >> >> >> Q2: You should not imagine that the inner anonymous function would be >> altering the value of `new.name`. (That function is only defined and never >> called, and even if it were called, it would not change the value of the >> `new.name` in the calling environment.) >> >> Since more than 12 hours have passed with no response, we can surmise that >> many people have passed the question over after concluding there was an >> incomplete problem description. You should post code that can be cut-pasted >> into a session and produce the error you are getting. It would include data >> setup and a loop or loop equivalent to show how the function is being called. >> >> -- >> David. >> >> >>> >>> I want ggplot to automatically insert Tuesday into ylab and ggtitle. >>> >>> Can anyone help me with this? Thanks for your patience. >>> >>> Ken >>> kmna...@gmail.com <mailto:kmna...@gmail.com> >>> 914-450-0816 (tel) >>> 347-730-4813 (fax) >>> >>> >>> >>> __ >>> R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To >>> UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> <https://stat.ethz.ch/mailman/listinfo/r-help> >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> <http://www.r-project.org/posting-guide.html> >>> and provide commented, minimal, self-contained, reproducible code. >> >> David Winsemius >> Alameda, CA, USA > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Sampe numbers
I think that you need to reconsider your conditions. The smallest number in your candidate set is 1, so if you sample 100 1's they will add to 100 which is greater than 50. So to have a set of numbers that sums to 50 you will need to either include negative numbers, 0's, or sample fewer than 50 values. If you really meant sum to 500 or sample 10 numbers (still selecting any single number over 50 will make the sum to large) then this becomes possible. There are a few ways to do it, which is best depends on what you are really trying to accomplish (and note that with the constraint, the values will not be iid). One option is rejection sampling: take a sample, if it sums correctly then you are done, if not then throw out that sample and try a new one. This will be very inefficient, but is easy enough to code and with a fast enough computer may be acceptable. Another option is adjustment: take a sample and compute the sum, if it is to low then add the difference to one of your values (lowest, chosen at random, other) or split it up and add to multiple values. If the sum is too high, then subtract from your numbers until the sum is correct (checking that you don't go below any lower bounds). Another option is to round values generated from a Dirichlet distribution multiplied by your total (you may need to round one value differently than the default). Another option is to consider it a balls and urns problem: You have 500 balls (assuming the true sum is to be 500) that you want distributed into 100 urns. If each urn needs at least 1 ball (minimum value of 1) then put 1 ball in each urn, then for the remaining 400 balls, randomly choose an urn to put each into. Then count the number of balls in each urn and those are your 100 numbers that sum to 500 (as long as no balls bounced off the lip of the urn and rolled under the couch). There are probably other ways, but these are some things to get you started. On Tue, Jul 19, 2016 at 11:41 AM, Frederic Ntirenganya wrote: > Hi Guys, > I am trying to sample 100 numbers from 1:100 > i did it like this: > > sample(1:100,100, replace= TRUE) > but i want again include a constraint that their sum must be equal to 50 > > How could I do it? > > Cheers > > Frederic Ntirenganya > Maseno University, > African Maths Initiative, > Kenya. > Mobile:(+254)718492836 > Email: fr...@aims.ac.za > https://sites.google.com/a/aims.ac.za/fredo/ > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] pairs: adjusting margins and labeling axes
If you want square plots on a rectangular plotting region, then where do you want the extra space to go? One option would be to add outer margins to use up the extra space. The calculations to figure out exactly how much space to put in the outer margins will probably not be trivial. Another option would be to not use `pairs`, but use the `layout` function directly and loops to do your plots (and use the `respect` argument to `layout`). On Tue, Jul 19, 2016 at 11:29 AM, michael young wrote: > The default shape for this correlation scatterplot is rectangle. I changed > it to square, but then the x-axis spacing between squares are off. Is > there an easy way to change x-axis spacing between squares to that of the > y-axis spacing size? > > I decided to hide the name values of the diagonal squares. I want them > along the x and y axis instead, outside of the fixed number scale I have. > I haven't seen any online example of 'pairs' with this and all my searches > have yielded nothing. Any ideas? Thanks > > par(pty="s") > panel.cor <- function(x, y, digits = 2, prefix="", cex.cor, ...) > { > usr <- par("usr"); on.exit(par(usr)) > par(usr = c(0, 1, 0, 1),xlog=FALSE,ylog=FALSE) > # correlation coefficient > r <- cor(x, y) > txt <- format(c(r, 0.123456789), digits = digits)[1] > txt <- paste("r= ", txt, sep = "") > if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) > text(0.5, 0.6, txt, cex=cex.cor * r) > > # p-value calculation > p <- cor.test(x, y)$p.value > txt2 <- format(c(p, 0.123456789), digits = digits)[1] > txt2 <- paste("p= ", txt2, sep = "") > if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "") > text(0.5, 0.4, txt2) > } > > pairs(iris, upper.panel = panel.cor,xlim=c(0.1,10), > ylim=c(0.1,10),log="xy",text.panel = NULL,pch=".") > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] multiple-line plot
Most attachments get stripped off, so your data did not make it through. But try: matplot(for_jhon$ID, for_jhon[,2:73], type='l') On Tue, Jul 19, 2016 at 12:24 PM, John Wasige wrote: > Dear all, > > This is to kindly request for your help. I would like to plot my data. > > The R script below gives some plot that is not clear. How can I get a clear > multiple-line plot. The data is attached herewith. > > ##R Script > for_jhon = read.csv("C:/LVM_share/for_ jhon.csv", header=TRUE, sep=";") > matplot(for_jhon$ID, cbind(for_jhon[,2:73])) > > Thanks for your help > > John > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Label multiple-line plot
with 72 lines to label it will be crowded whatever you do. Here is one option (though I am showing with fewer lines): x <- sapply(1:15, function(i) cumsum(rnorm(100))) par(mar=c(5,4,4,3)+0.1) matplot(1:100, x, type='l', lty=1) mtext(LETTERS[1:15], side=4, at=x[100,], las=1, line=1) One way to spread out the labels is: library(TeachingDemos) new.y <- spread.labs(x[100,], mindiff = 1.2*strheight('A'), min=min(x), max=max(x)) mtext(LETTERS[1:15], side=4, at=new.y, las=1, line=2) There is also another label spreading function in the plotrix package and another option for finding space in a plot for labeling lines in either the rms or Hmisc package. There are probably other packages with tools available now as well, but those are the ones that I am familiar with. On Tue, Jul 19, 2016 at 1:36 PM, John Wasige wrote: > Thanks! It worked for me. > matplot(for_jhon$ID, for_jhon[,2:73], type='l') > > Any I dea on how I can label multiple-line plot based on column names? > > Thanks for your help > > John > > On Tue, Jul 19, 2016 at 8:46 PM, Greg Snow <538...@gmail.com> wrote: >> >> Most attachments get stripped off, so your data did not make it through. >> >> But try: >> >> matplot(for_jhon$ID, for_jhon[,2:73], type='l') >> >> >> On Tue, Jul 19, 2016 at 12:24 PM, John Wasige >> wrote: >> > Dear all, >> > >> > This is to kindly request for your help. I would like to plot my data. >> > >> > The R script below gives some plot that is not clear. How can I get a >> > clear >> > multiple-line plot. The data is attached herewith. >> > >> > ##R Script >> > for_jhon = read.csv("C:/LVM_share/for_ jhon.csv", header=TRUE, sep=";") >> > matplot(for_jhon$ID, cbind(for_jhon[,2:73])) >> > >> > Thanks for your help >> > >> > John >> > __ >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> >> >> >> -- >> Gregory (Greg) L. Snow Ph.D. >> 538...@gmail.com > > > > > -- > John Wasige > "There are no REGRATES in LIFE, just lessons (Jennifer Aniston)” -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] txtProgressBar()
You need to figure out how to tell txtProgressBar what the progress is. One simple option would be that if you are installing 10 packages, then create the bar with a range of values from 0 to 10 and initialize it at 0, then after the first package installs update it to show 1, after the 2nd installs update it to show 2, etc. until all 10 are installed. This is the simplest from the programming side, but the packages may take different amounts of time to install. If you have a feel for how long they take to install (relative to each other) then you can incorporate this with a percentage, e.g. after the 1st package installs you may set the bar to 28%, after the second installs you may then update it to 31%, etc. with the jumps proportional to expected time to install. On Wed, Jul 20, 2016 at 2:00 AM, Ivan Calandra wrote: > Dear useRs, > > In a script that will be source()d, I want to install the uninstalled > packages and follow the progression with a bar. So I looked at > txtProgressBar() but I cannot figure out how to use it to show the > progression of the installation. > > All the examples I have found just display the progress of... the progress > bar itself ? > > Any idea? > > Thanks in advance, > Ivan > > -- > Ivan Calandra, PhD > Scientific Mediator > University of Reims Champagne-Ardenne > GEGENAA - EA 3795 > CREA - 2 esplanade Roland Garros > 51100 Reims, France > +33(0)3 26 77 36 89 > ivan.calan...@univ-reims.fr > -- > https://www.researchgate.net/profile/Ivan_Calandra > https://publons.com/author/705639/ > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Why the order of parameters in a logistic regression affects results significantly?
Please post in plain text, the message is very hard to read with the reformatting that was done. Did you receive any warnings when you fit your models? The fact that the last coefficient is NA in both outputs suggests that there was some co-linearity in your predictor variables and R chose to drop one of the offending variables from the model (the last one in each case). Depending on the nature of the co-linearity, the interpretation (and therefore the estimates) can change. For example lets say that you have 3 predictors, red, green, and blue that are indicator variables (0/1) and that every subject has a 1 in exactly one of those variables (so they are co-linear with the intercept). If you put the 3 variables into a model with the intercept in the above order, then R will drop the blue variable and the interpretation of the coefficients is that the intercept is the average for blue subjects and the other coefficients are the differences between red/green and blue on average. If you refit the model with the order blue, green, red, then R will drop red from the model and now the interpretation is that the intercept is the mean for red subjects and the others are the differences from red on average, a very different interpretation and therefore different estimates. I expect something along those lines is going on here. On Thu, Jul 21, 2016 at 4:04 PM, Qinghua He via R-help wrote: > Using the same data, if I ran > fit2 > <-glm(formula=AR~Age+LumA+LumB+HER2+Basal+Normal,family=binomial,data=RacComp1)summary(fit2)exp(coef(fit2)) > I obtained: >> exp(coef(fit2))(Intercept) AgeLumALumBHER2 >> Basal Normal 0.24866935 1.00433781 0.10639937 0.31614001 >> 0.08220685 20.25180956 NA > while if I ran > > fit2 > <-glm(formula=AR~Age+LumA+LumB+Basal+Normal+HER2,family=binomial,data=RacComp1)summary(fit2)exp(coef(fit2)) > I obtained: >> exp(coef(fit2)) (Intercept) Age LumA LumB >> Basal Normal HER2 0.02044232 1.00433781 1.29428846 >> 3.84566516 246.35185956 12.16443690 NA > > Essentially they're the same model - I just moved HER2 to the last. But the > OR changed significantly. Can someone explain? > For the latter result, I don't even know how to interpret as all factors have > OR>1 (except Intercept), how could that possible? Can I eliminate the effect > of intercept? > Also, I cannot obtain OR for the last factor due to collinearity. However, I > know others obtained OR for all factors for the same dataset. Can someone > tell me how to obtain OR for all factors? All factors are categorical > variables (i.e., 0 or 1). > Thanks! > Peter > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Climate data in R
The rnoaa package has the function ncdc_stations which can be used to search for stations in a region. You could use that giving it an extent around the coordinates that you are interested in (add and subtract a small amount from the coordinates), then pass the results from that function (possibly subsetted) into the ncdc function. On Mon, Aug 1, 2016 at 8:06 AM, Miluji Sb wrote: > Dear all, > > I have a set of coordinates. Is it possible to extract climate data > (temperature and precipitation) by coordinates using the R packages such as > rnoaa? > > For example; > > out <- ncdc(datasetid='ANNUAL', stationid='GHCND:USW00014895', > datatypeid='TEMP') > > But instead of stationid can I pass a list of coordinates through it? > Thanks a lot! > > Sincerely, > > Milu > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] questions about co-linearity in logistic regression from Stefano Sofia
Stefano, It is usually best to keep these discussions on R-help. People there may be quicker to respond and could have better answers. Keeping the discussion on the list also means that if others in the future find your question, they will also find the answers and discussion. And some of us can spend some time answering questions on the list as a community stewardship contribution, but when asked directly it turns into consulting and we would need to start charging a fee (and I expect that sharing your answer with the community as a whole is lot cheaper than what my employer would insist that I charge you as a consultant). Quick answers to your questions: 1. an example of the data: > tmp.dat <- data.frame(color=factor(c('red','green','blue'), + levels=c('red','green','blue')) + ) > model.matrix(~color-1, data=tmp.dat) colorred colorgreen colorblue 11 0 0 20 1 0 30 0 1 attr(,"assign") [1] 1 1 1 attr(,"contrasts") attr(,"contrasts")$color [1] "contr.treatment" 2. There is co-linearity with the intercept because the intercept is represented by a column of 1's and you can see that if you add the 3 columns above you also will see a column of 1's. 3. There are 3 pieces of information (3 colors) so you need 3 columns to represent those, you can reconstruct the "blue" column by subtracting "red" and "green" from the column of 1's that represent the intercept. Dropping the last 2 columns only leaves 2 pieces left which will not contain all the information (just "red" and the intercept, "blue" and "green" would be combined in that case). Any column could be dropped (including the intercept), R/S just chose to drop the last one by default. 4. The full answer to this would involve studying the reparameterized cell-means model: Bryce, G. Rex, Del T. Scott, and M. W. Carter. "ESTIMATION AND HYPOTHESIS-TESTING IN LINEAR-MODELS-REPARAMETERIZATION APPROACH TO THE CELL MEANS MODEL." COMMUNICATIONS IN STATISTICS PART A-THEORY AND METHODS 9.2 (1980): 131-150. but the quick answer can be seen by the parameterization using the intercept and dropping a column for "blue": > tmp.dat <- data.frame(color=factor(c('red','green','blue'))) > model.matrix(~color, data=tmp.dat) (Intercept) colorgreen colorred 1 1 01 2 1 10 3 1 00 attr(,"assign") [1] 0 1 1 attr(,"contrasts") attr(,"contrasts")$color [1] "contr.treatment" > solve(.Last.value) 1 2 3 (Intercept) 0 0 1 colorgreen 0 1 -1 colorred 1 0 -1 You can see that the rows corresponding to "blue" have only the intercept as non-zero while the other rows have the intercept plus another column as 1's, In the contrast matrix (the result of `solve`) the intercept corresponds exactly to 3/blue and the others are the difference between blue and the other 2 colors. Even with the dummy variables you can see that when predicting red you take the intercept plus the coefficient for red, when predicting green you take the intercept plus the coefficient for green, and when predicting for blue you just use the intercept. This should intuitively suggest that the intercept is the mean/prediction for blue and the other coefficients are the differences to be added to "blue" to get the other values. 5. see answer to 4 On Mon, Aug 1, 2016 at 4:18 AM, Stefano Sofia wrote: > Dear Dr. Snow, > my name is Stefano Sofia (I am a meteorologist), I always read posts on the > r-mailing list. > > Few days ago I read with great interest your answer about "Why the order of > parameters in a logistic regression affects results significantly?" > > I am very interested in regression, I have some basis about it but not so > solid to understand the considerations you mentioned. > Therefore may I ask you some questions (only if you have got time), or a > reference text where I can find the answers? > > Sorry for the disturb, and thank you for your help. > Stefano Sofia PhD > > Here my questions. > > 1. Could you please give me a very short example of three predictors (red, > green and blue) that are indicators variables with a 1 in exactly one of > those variables? > 2. Why in this case there is co-linearity with the intercept? > 3. Why in case of co-linearity only the last variable is removed (the blue) > and not the last two ones? > 4. Why the intercept is the average for blue? > 5. And finally why the coefficients are the differences between red/green > and blue on average? > > Here there is your original e-mai
Re: [R] Accessing an object using a string
The names function is a primitive, which means that if it does not already do what you want, it is generally not going to be easy to coerce it to do it. However, the names of an object are generally stored as an attribute of that object, which can be accessed using the attr or attributes functions. If you change your code to not use the names function and instead use attr or attributes to access the names then it should work for you. You may also want to consider changing your workflow to have your data objects read into a list rather than global variables, then process using lapply/sapply (this would require a change in how your data is saved from your example, but if you can change that then everything after can be cleaner/simpler/easier/more fool proof/etc.) On Mon, Aug 15, 2016 at 2:49 AM, wrote: > Hi All, > > I would like to access an object using a sting. > > # Create example dataset > var1 <- c(1, 2, 3) > var2 <- c(4, 5, 6) > data1 <- data.frame(var1, var2) > > var3 <- c(7, 8, 9) > var4 <- c(10, 11, 12) > data2 <- data.frame(var3, var4) > > save(file = "c:/temp/test.RData", list = c("data1", "data2")) > > # Define function > t_load_dataset <- function(file_path, >file_name) { > file_location <- file.path(file_path, file_name) > > print(paste0('Loading ', file_location, " ...")) > cat("\n") > > object_list <- load(file = file_location, > envir = .GlobalEnv) > > print(paste(length(object_list), "dataset(s) loaded from", > file_location)) > cat("\n") > > print("The following objects were loaded:") > print(object_list) > cat("\n") > > for (i in object_list) { > print(paste0("Object '", i, "' in '", file_name, "' contains:")) > str(i) > names(i) # does not work > } > } > > I have only the character vector object_list containing the names of the > objects as strings. I would like to access the objects in object_list to > be able to print the names of the variables within the object (usuallly a > data frame). > > Is it possible to do this? How is it done? > > Kind regards > > Georg > > ______ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Accessing an object using a string
Hmm, names appears to be both primitive and generic, since when I look at the function definition (3.3.0) I see: > names function (x) .Primitive("names") This is what I was referring to as the primitive. I had originally intended to look at the code for names to see how it accessed the attribute, but did not want to delve into compiled code once I saw .Primitive (and did not think that would be the best approach in this case anyways). If typing the name would have given pure R code then it could have been somewhat simple to modify the function to work on the value of the variable passed as an object rather than the object (some functions like rm use NSE, but also have a list argument that will accept a vector of character). My suggestion of using attr or attributes more directly should still work. On Mon, Aug 15, 2016 at 1:10 PM, William Dunlap wrote: > 'names' is an S3-generic function. E.g., in R-3.3.0: > > > names.unnamed <- function(x) sprintf("#%0*d", ceiling(log10(length(x))), > seq_along(x)) > > u <- structure(letters, class="unnamed") > > names(u) >[1] "#01" "#02" "#03" "#04" "#05" "#06" "#07" >[8] "#08" "#09" "#10" "#11" "#12" "#13" "#14" > [15] "#15" "#16" "#17" "#18" "#19" "#20" "#21" > [22] "#22" "#23" "#24" "#25" "#26" > > There are a lot of C/C++ based functions that use an internal function to > get > the names of vectors and they may not use this method, but R code will use > it. > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Mon, Aug 15, 2016 at 11:33 AM, Greg Snow <538...@gmail.com> wrote: >> >> The names function is a primitive, which means that if it does not >> already do what you want, it is generally not going to be easy to >> coerce it to do it. >> >> However, the names of an object are generally stored as an attribute >> of that object, which can be accessed using the attr or attributes >> functions. If you change your code to not use the names function and >> instead use attr or attributes to access the names then it should work >> for you. >> >> >> You may also want to consider changing your workflow to have your data >> objects read into a list rather than global variables, then process >> using lapply/sapply (this would require a change in how your data is >> saved from your example, but if you can change that then everything >> after can be cleaner/simpler/easier/more fool proof/etc.) >> >> >> On Mon, Aug 15, 2016 at 2:49 AM, wrote: >> > Hi All, >> > >> > I would like to access an object using a sting. >> > >> > # Create example dataset >> > var1 <- c(1, 2, 3) >> > var2 <- c(4, 5, 6) >> > data1 <- data.frame(var1, var2) >> > >> > var3 <- c(7, 8, 9) >> > var4 <- c(10, 11, 12) >> > data2 <- data.frame(var3, var4) >> > >> > save(file = "c:/temp/test.RData", list = c("data1", "data2")) >> > >> > # Define function >> > t_load_dataset <- function(file_path, >> >file_name) { >> > file_location <- file.path(file_path, file_name) >> > >> > print(paste0('Loading ', file_location, " ...")) >> > cat("\n") >> > >> > object_list <- load(file = file_location, >> > envir = .GlobalEnv) >> > >> > print(paste(length(object_list), "dataset(s) loaded from", >> > file_location)) >> > cat("\n") >> > >> > print("The following objects were loaded:") >> > print(object_list) >> > cat("\n") >> > >> > for (i in object_list) { >> > print(paste0("Object '", i, "' in '", file_name, "' contains:")) >> > str(i) >> > names(i) # does not work >> > } >> > } >> > >> > I have only the character vector object_list containing the names of the >> > objects as strings. I would like to access the objects in object_list to >> > be able to print the names of the variables within the object (usuallly >> > a >> > data frame). >> > >> > Is it possible to do this? How is it done? >> > >> > Kind regards >> > >> > Georg >> > >> > __ >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> >> >> >> -- >> Gregory (Greg) L. Snow Ph.D. >> 538...@gmail.com >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Accessing an object using a string
Interestingly I just gave a presentation on this last Friday. Using load it is a little more complicated since load reads the object name from the file as well (which can lead to overwriting objects if loading from more than one file). So it is better to use another save format if possible. One alternative is to use the saveRDS and readRDS functions. Here is the example that I presented: First, create some sample data files on the disk (here saving as .csv files) data('Oxboys', package='nlme') obl <- split(Oxboys, Oxboys$Subject) for(d in obl) { write.csv(d, file=sprintf("OxBoys%02d.csv", d$Subject[1]), row.names=FALSE) } rm(Oxboys,obl) Now read the files into R into a single list (and add names to the list, optional but can be nice): fnames <- list.files(pattern='^OxBoys') ob.new <- lapply(fnames, read.csv) nms <- paste0('OxBoys', sapply(ob.new, function(df) df$Subject[1])) names(ob.new) <- nms head( ob.new$OxBoys1 ) The list.files function in the first line is one convenient way to create the vector of filenames, but other options would include paste0, sprintf, and others. Now perform the same analysis on each data frame in the list and nicely format the results (a simple regression in this case): slopes <- sapply(ob.new, function(df) { fit <- lm(height~age, data=df) coef(fit) }) head(t(slopes)) On Tue, Aug 16, 2016 at 12:43 AM, wrote: > Hi Greg > and all others who replied to my question, > > many thanks for all your answers and help. Currently I store all my > objects in .GlobalEnv = Workspace. I am not yet familiar working with > different environments nor did I see that this would be necessary for my > analysis. > > Could you explain why working with different environments would be > helpful? > > You suggested to read variables into lists rather than storing them in > global variables. This sounds interesting. Could you provide an example of > how to define and use this? > > Kind regards > > Georg > > > > Von:Greg Snow <538...@gmail.com> > An: g.maub...@weinwolf.de, > Kopie: r-help > Datum: 15.08.2016 20:33 > Betreff:Re: [R] Accessing an object using a string > > > > The names function is a primitive, which means that if it does not > already do what you want, it is generally not going to be easy to > coerce it to do it. > > However, the names of an object are generally stored as an attribute > of that object, which can be accessed using the attr or attributes > functions. If you change your code to not use the names function and > instead use attr or attributes to access the names then it should work > for you. > > > You may also want to consider changing your workflow to have your data > objects read into a list rather than global variables, then process > using lapply/sapply (this would require a change in how your data is > saved from your example, but if you can change that then everything > after can be cleaner/simpler/easier/more fool proof/etc.) > > > On Mon, Aug 15, 2016 at 2:49 AM, wrote: >> Hi All, >> >> I would like to access an object using a sting. >> >> # Create example dataset >> var1 <- c(1, 2, 3) >> var2 <- c(4, 5, 6) >> data1 <- data.frame(var1, var2) >> >> var3 <- c(7, 8, 9) >> var4 <- c(10, 11, 12) >> data2 <- data.frame(var3, var4) >> >> save(file = "c:/temp/test.RData", list = c("data1", "data2")) >> >> # Define function >> t_load_dataset <- function(file_path, >>file_name) { >> file_location <- file.path(file_path, file_name) >> >> print(paste0('Loading ', file_location, " ...")) >> cat("\n") >> >> object_list <- load(file = file_location, >> envir = .GlobalEnv) >> >> print(paste(length(object_list), "dataset(s) loaded from", >> file_location)) >> cat("\n") >> >> print("The following objects were loaded:") >> print(object_list) >> cat("\n") >> >> for (i in object_list) { >> print(paste0("Object '", i, "' in '", file_name, "' contains:")) >> str(i) >> names(i) # does not work >> } >> } >> >> I have only the character vector object_list containing the names of the >> objects as strings. I would like to access the objects in object_list to >> be able to print the names of the variables within the object (usuallly > a >> data frame). &g
Re: [R] Accessing an object using a string
Ista, The original poster did discover the get function and posted that (in a different thread). Personally I don't recommend get for things like this for similar reasons that I don't suggest a loaded pistol be used to swat a fly, it may be effective for the immediate problem, but has potential to lead to poor outcomes if used repeatedly or extended. People who discover "get" also tend to stumble across "assign" and my opinions on that function have become fortune(236) (fortune(174) could also be relevant). Now it is entirely possible that you and the original poster are both smarter than me and would not fall into that trap, but see fortune(181). On Tue, Aug 16, 2016 at 11:41 AM, Ista Zahn wrote: > I'm surprised no one has given what I consider to be the standard > answer to this questions, namely ?get. Won't > > for (i in object_list) { > print(paste0("Object '", i, "' in '", file_name, "' contains:")) > str(get(i)) > print(names(get(i))) # works > } > > do what you want? > > Best, > Ista > > On Tue, Aug 16, 2016 at 11:46 AM, Greg Snow <538...@gmail.com> wrote: >> Interestingly I just gave a presentation on this last Friday. >> >> Using load it is a little more complicated since load reads the object >> name from the file as well (which can lead to overwriting objects if >> loading from more than one file). So it is better to use another save >> format if possible. One alternative is to use the saveRDS and readRDS >> functions. >> >> Here is the example that I presented: >> >> First, create some sample data files on the disk (here saving as .csv files) >> >> data('Oxboys', package='nlme') >> obl <- split(Oxboys, Oxboys$Subject) >> for(d in obl) { >> write.csv(d, file=sprintf("OxBoys%02d.csv", >> d$Subject[1]), >> row.names=FALSE) >> } >> rm(Oxboys,obl) >> >> >> Now read the files into R into a single list (and add names to the >> list, optional but can be nice): >> >> fnames <- list.files(pattern='^OxBoys') >> ob.new <- lapply(fnames, read.csv) >> nms <- paste0('OxBoys', sapply(ob.new, >> function(df) df$Subject[1])) >> names(ob.new) <- nms >> head( ob.new$OxBoys1 ) >> >> The list.files function in the first line is one convenient way to >> create the vector of filenames, but other options would include >> paste0, sprintf, and others. >> >> Now perform the same analysis on each data frame in the list and >> nicely format the results (a simple regression in this case): >> >> slopes <- sapply(ob.new, function(df) { >> fit <- lm(height~age, data=df) >> coef(fit) >> }) >> head(t(slopes)) >> >> >> >> >> On Tue, Aug 16, 2016 at 12:43 AM, wrote: >>> Hi Greg >>> and all others who replied to my question, >>> >>> many thanks for all your answers and help. Currently I store all my >>> objects in .GlobalEnv = Workspace. I am not yet familiar working with >>> different environments nor did I see that this would be necessary for my >>> analysis. >>> >>> Could you explain why working with different environments would be >>> helpful? >>> >>> You suggested to read variables into lists rather than storing them in >>> global variables. This sounds interesting. Could you provide an example of >>> how to define and use this? >>> >>> Kind regards >>> >>> Georg >>> >>> >>> >>> Von:Greg Snow <538...@gmail.com> >>> An: g.maub...@weinwolf.de, >>> Kopie: r-help >>> Datum: 15.08.2016 20:33 >>> Betreff:Re: [R] Accessing an object using a string >>> >>> >>> >>> The names function is a primitive, which means that if it does not >>> already do what you want, it is generally not going to be easy to >>> coerce it to do it. >>> >>> However, the names of an object are generally stored as an attribute >>> of that object, which can be accessed using the attr or attributes >>> functions. If you change your code to not use the names function and >>> instead use attr or attributes to access the names then it should work >>> for you. >>> >>> >>> You may also want to consider changing your workflow to have your data >>> objects read into a list rather than globa
Re: [R] [R Survey Analysis] Problem counting number of responses
Lauren, The easier that you make it for us to help you, the more likely you are to get help and the more helpful the answers will be. First, please post in plain text (not HTML). Second, reproducible code (including sample data) helps us help you. Your code above is incorrect, the 3 lines with "ifelse" have more left parentheses than right parentheses. Is "survey" a data frame? or something else? Best guess from your code is that you want something like: survey$responses <- with(survey, !is.na(q1) + !is.na(q2) + !is.na(q3)) the "with" function just makes it so you don't have to prepend everything with "survey$", the "!" inverts logic so that it shows those that are not NA and when you sum logicals they are converted to 0/1. With 3 questions then you can subset your data like: survey[ survey$nesponses==3, ] to see those that answered (or did not result in NA) 3 questions. On Tue, Aug 16, 2016 at 12:51 PM, Lauren Bolger wrote: > M > y dataset includes a survey completed by research participants to evaluate > quality of life. A few things regarding the survey: > > >- > *not all questions must be answered for the total score * >- questions left blank are coded as "0" >- the number of questions answered must be determined in order to >compute the total score > > > *Sample Code* > >> q1 <- ifelse(is.na(survey, 0, survey$q1) > >> q2 <- ifelse(is.na(survey, 0, survey$q2) > >> q3 <- ifelse(is.na(survey, 0, survey$q3) > >> survey$sum.survey <- q1 + q2 + q3 > >> survey$responses <- # HELP ? > *> # HELP PART 1 --* > *> # need help determining number of questions the respondents answered* > >> *# HELP PART 2 ---* > *> # I want to look at the subset of the population that completed all the > questions* > > > > > Thanks for your help!! It means a lot :) > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Loop over rda list files and using the attach function
You can attach rda files directly with the attach function, no need to load them first (see the what argument in the help for attach). This may do what you want more directly. In general it is better to not use loops and attach for this kind of thing. It is better to store multiple data objects in a list, then use lapply/sapply to apply functions to each element. On Tue, Aug 30, 2016 at 9:43 AM, Juan Ceccarelli Arias wrote: > Hi. > I need to loop over rda files. > I generated the list of them. > That's ok. The problem is that the name of the files are as _mm (eg > 2010_01 is january or 2010, 2016_03 is march of 2016). > So, when i try to use the attach function to create a simple table(age, > sex) it fails. > The only way to attach a file as is using > attach(`2016_03`) > The text above i have no idea how to declare it in my code below > > > dd=list.files("C:/Users/Me/r", pattern="rda$", full.names=F) > for (i in 1:length(dd)) { > yyz=load(dd[i]) > attach(yyz) > table(age, sex) > rm(list=yyz) > > } > This is the error it declares the loop: > Error in attach(yyz) : file '2013_02' not found > > > Thanks for your help and time > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot with different symbols and colors according to the factor levels
And you can specify the symbols and colors using code like: with(lili, plot(y,conc, pch= c(16,18,17)[sample], col=c('red','green','blue')[sample], log="y")) modifying to meet your data and preferences, of course. On Tue, Aug 30, 2016 at 11:48 AM, Clint Bowman wrote: > > with(lili,plot(y,conc,pch=sample,col=sample,log="y")) > > gives a better plot > > > Clint BowmanINTERNET: cl...@ecy.wa.gov > Air Quality Modeler INTERNET: cl...@math.utah.edu > Department of Ecology VOICE: (360) 407-6815 > PO Box 47600FAX:(360) 407-7534 > Olympia, WA 98504-7600 > > USPS: PO Box 47600, Olympia, WA 98504-7600 > Parcels:300 Desmond Drive, Lacey, WA 98503-1274 > > On Tue, 30 Aug 2016, Clint Bowman wrote: > >> Hanna, >> >> lili<-read.table("lili.txt",header=T) # don't forget to label the row >> number if it's in your data >> >> with(lili,plot(y,conc,pch=sample,col=sample)) >> >> Clint >> >> >> Clint BowmanINTERNET: cl...@ecy.wa.gov >> Air Quality Modeler INTERNET: cl...@math.utah.edu >> Department of Ecology VOICE: (360) 407-6815 >> PO Box 47600FAX:(360) 407-7534 >> Olympia, WA 98504-7600 >> >> USPS: PO Box 47600, Olympia, WA 98504-7600 >> Parcels:300 Desmond Drive, Lacey, WA 98503-1274 >> >> On Tue, 30 Aug 2016, li li wrote: >> >>> Hi all, >>> I have the following data. I want to plot the data (y ~ conc) >>> with different symbols and colors corresponding to different levels of >>> the >>> factor sample. >>> I could create a column with color and pch and then do the plot, but I >>> am >>> sure there are much better ways. >>> Can anyone make suggestions? >>> Hanna >>> >>> >>> >>>y conc sample >>> 1 33 20.0 1 >>> 2 33 5.0 1 >>> 3 35 1.25000 1 >>> 4 43 0.31250 1 >>> 5 58 0.078125000 1 >>> 6 54 0.019531250 1 >>> 7 57 0.004882812 1 >>> 8 57 0.001220703 1 >>> 9 32 20.0 1 >>> 10 32 5.0 1 >>> 11 34 1.25000 1 >>> 12 52 0.31250 1 >>> 13 57 0.078125000 1 >>> 14 58 0.019531250 1 >>> 15 59 0.004882812 1 >>> 16 50 0.001220703 1 >>> 17 34 20.0 2 >>> 18 34 5.0 2 >>> 19 38 1.25000 2 >>> 20 53 0.31250 2 >>> 21 57 0.078125000 2 >>> 22 57 0.019531250 2 >>> 23 57 0.004882812 2 >>> 24 52 0.001220703 2 >>> 25 34 20.0 2 >>> 26 33 5.0 2 >>> 27 36 1.25000 2 >>> 28 48 0.31250 2 >>> 29 58 0.078125000 2 >>> 30 57 0.019531250 2 >>> 31 58 0.004882812 2 >>> 32 53 0.001220703 2 >>> 33 34 20.0 2 >>> 34 35 5.0 2 >>> 35 37 1.25000 2 >>> 36 49 0.31250 2 >>> 37 55 0.078125000 2 >>> 38 59 0.019531250 2 >>> 39 57 0.004882812 2 >>> 40 54 0.001220703 2 >>> 41 36 20.0 3 >>> 42 33 5.0 3 >>> 43 36 1.25000 3 >>> 44 51 0.31250 3 >>> 45 57 0.078125000 3 >>> 46 57 0.019531250 3 >>> 47 59 0.004882812 3 >>> 48 56 0.001220703 3 >>> 49 33 20.0 3 >>> 50 32 5.0 3 >>> 51 35 1.25000 3 >>> 52 47 0.31250 3 >>> 53 57 0.078125000 3 >>> 54 56 0.019531250 3 >>> 55 57 0.004882812 3 >>> 56 53 0.001220703 3 >>> 57 33 20.0 3 >>> 58 34 5.0 3 >>> 59 38 1.25000 3 >>> 60 52 0.31250 3 >>> 61 56 0.078125000 3 >>> 62 61 0.019531250 3 >>> 63 56 0.004882812 3 >>> 64 55 0.001220703 3 >>> >>> [[alternative HTML version deleted]] >>> >>> ______ >>> R-help@r-project.org mailin
Re: [R] Drill down reports in R
As has been mentioned, this really requires a GUI tool beyond just R. Luckily there are many GUI tools that have been linked to R and if Shiny (the shiniest of them) does not have something like this easily available so far then you may want to look elsewhere in the meantime. One option is the tcltk package which interfaces with the Tk GUI tools (and the tcl language) which does have the pieces to build in the expandable/drill down interface. One implementation of this is the TkListView function in the TeachingDemos package which can be used to view list objects in this manner (it starts with the top level list objects, then when you click on a + symbol it will open that piece and show one level down). One possibility would be to create all of your results in a list, then view it with TkListView (this will require all computations up front, whether anyone looks at them or not). Another option would be to start with TkListView and rewrite it to do things more dynamically and with the output that you want to show. There is also the shinyTree package on CRAN that allows a tree type object in shiny that may do what you want (I don't know what all options it allows and what it can display beyond what is in the Readme). On Tue, Sep 13, 2016 at 4:46 AM, Manohar Reddy wrote: > Hi, > > > > How to generate “Drill down reports ” (like please refer below url) in R > using any package ? I did lot of research in google but I didn’t found > suitable link . > > Can anyone help how to do that in R ? > > > > url : http://bhushan.extreme-advice.com/drilldown-report-in-ssrs/ > > > > Thanks in Advance ! > > Manu. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to plot the regression line of multivariable linear model?
You might consider the Predict.Plot and TkPredict functions in the TeachingDemos package. These help you explore multiple linear regression models by plotting the "line" relating the response to one of the predictors at given values of the other predictors. These lines can be combined in a single plot (Predict.Plot) or changed interactively (TkPredict). See the examples in the help page. On Sun, Sep 18, 2016 at 9:26 AM, mviljamaa wrote: > I'm having a bit of trouble plotting the regression line of multivariable > linear model. > > Specifically my model has one response and two predictors, i.e. it's of the > form > > Y = b_0+b_1*X_1+b_2*X_2 > > Plotting the regression line for a single predictor model > > Y = b_0+b_1*X_1 > > is simple enough, just call abline() with the coefficients returned by lm(). > > However, I don't know if this can be adapted to multivariable linear models. > > I also know about curve(), but I don't know how am I supposed to input the > multivariable model's coefficients into it. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] about data problem
This indicates that your Discharge column has been stored/converted as a factor (run str(df) to verify and check other columns). This usually happens when functions like read.table are left to try to figure out what each column is and it finds something in that column that cannot be converted to a number (possibly an oh instead of a zero, an el instead of a one, or just a letter or punctuation mark accidentally in the file). You can either find the error in your original data, fix it, and reread the data, or specify that the column should be numeric using the colClasses argument to read.table or other function. On Tue, Sep 20, 2016 at 3:46 PM, lily li wrote: > Hi R users, > > I have a problem in reading data. > For example, part of my dataframe is like this: > > df > month day year Discharge >31 20106.4 >32 2010 7.58 >33 2010 6.82 >34 2010 8.63 >35 2010 8.16 >36 2010 7.58 > > Then if I type summary(df), why it converts the discharge data to levels? I > also met the same problem when reading some other csv files. How to solve > this problem? Thanks. > > Discharge > 7.58 :2 > 6.4 :1 > 6.82 :1 > 8.63 :1 > 8.16 :1 > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] curve() doesn't seem to use the whole range of x? And Error: longer object length is not a multiple of shorter object length
If your goal is to visualize the predicted curve from an lm fit (or other model fit) then you may want to look at the Predict.Plot and TkPredict functions from the TeachingDemos package. On Sun, Sep 25, 2016 at 7:01 AM, Matti Viljamaa wrote: > I’m trying to plot regression lines using curve() > > The way I do it is: > > bs <- coef(fit2) > > and then for example: > > curve(bs["(Intercept)"]+bs["mies"]*0+bs["kouluB"]+bs["lka"]*x+bs["kouluB:clka"]*clka, > from=min(lka), to=max(lka), add=TRUE, col='red') > > This above code runs into error: > > Error in curve(bs["(Intercept)"] + bs["mies"] * 0 + bs["kouluB"] + bs["lka"] > * : > 'expr' did not evaluate to an object of length 'n' > In addition: Warning message: > In bs["(Intercept)"] + bs["mies"] * 0 + bs["kouluB"] + bs["lka"] * : > longer object length is not a multiple of shorter object length > > Which I’ve investigated might be related to the lengths of the different > objects being multiplied or summed. > Taking length(g$x) or length(g$y) of > > g <- curve(bs["(Intercept)"]+bs["mies"]*0+bs["kouluB"]+bs["lka"]*x, > from=min(lka), to=max(lka), add=TRUE, col='red') > > returns 101. > > However length(lka) is 375. But perhaps these being different is not the > problem? > > I however do see that the whole range of lka is not plotted, for some reason. > So how can I be sure > that it passes through all x-values in lka? And i.e. that the lengths of > objects inside curve() are correct? > > What can I do? > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to test a difference in ratios of count data in R
There are multiple ways of doing this, but here are a couple. To just test the fixed effect of treatment you can use the glm function: test <- read.table(text=" replicate treatment n X 1 A 32 4 1 B 33 18 2 A 20 6 2 B 21 18 3 A 7 0 3 B 8 4 ", header=TRUE) fit1 <- glm( cbind(X,n-X) ~ treatment, data=test, family=binomial) summary(fit1) Note that the default baseline value may differ between R and SAS, which would result in a reversed sign on the slope coefficient (and different intercept). To include replicate as a random effect you need an additional package, here I use lme4 and the glmer function: library(lme4) fit2 <- glmer( cbind(X, n-X) ~ treatment + (1|replicate), data=test, family=binomial) summary(fit2) On Tue, Sep 27, 2016 at 9:03 PM, Shuhua Zhan wrote: > Hello R-experts, > I am interested to determine if the ratio of counts from two groups differ > across two distinct treatments. For example, we have three replicates of > treatment A, and three replicates of treatment B. For each treatment, we have > counts X from one group and counts Y from another group. My understanding is > that that GLIMMIX procedure in SAS can calculate whether the ratio of counts > in one group (X/X+Y) significantly differs between treatments. > > I think this is the way you do it in SAS. The replicate and treatment > variables are self-explanatory. The first number (n) refers to the total > counts X + Y; the second number (X) refers to the counts X. Is there a way to > do this in R? Since we have 20,000 datasets to be tested, it may be easier to > retrive the significant test as the given dataset below and its p>F value and > mean ratios of treatments in R than SAS. > > > data test; > input replicate treatment$ n X; > datalines; > 1 A 32 4 > 1 B 33 18 > 2 A 20 6 > 2 B 21 18 > 3 A 7 0 > 3 B 8 4 > ; > > proc glimmix data=test; > class replicate treatment; > model X/n = treatment / solution; > random intercept / subject=replicate; > run; > > ods select lsmeans; > proc glimmix data=test; > class replicate treatment; > model X/n = treatment / solution; > random intercept / subject=replicate; > lsmeans treatment / cl ilink; > run; > > I appreciate your help in advance! > Joshua > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to test a difference in ratios of count data in R
It is usually best to keep these discussions on the list. Someone else may have a better answer than mine, or be able to respond quicker, and if I answer on R-help then it is community service/involvement. If I respond directly then it is consulting and then we need a contract and I have to charge you (not that I would see the money myself, but it would help my budget be a little less red). For your question, your fit4 and my fit2 are just 2 different ways of fitting the exact same model to the exact same data, so there is no surprise that the results match. Which one to use is personal preference. The line that starts with "treatmentB" is the coefficient (log-odds-ratio) for B compared to A, so that is the main line to look at for interpretation. The correlation of the fixed effects is mainly there for diagnostics, if it is too close to -1 or 1 then that indicates that assumptions may not hold, or computations may be in doubt. Your value is not of concern. On Wed, Sep 28, 2016 at 2:14 PM, Shuhua Zhan wrote: > Hi Greg, > Thank you very much for your help! > I'd like to use glmer. From the output of summary(fit2) as below, Could I > draw a conclusion that the treatment B > significantly increases the counts of x group (p=6.11e-07)? I'm wondering if > I could know that the treatment B > significantly increases the ratio of x group (X/n) and how I could obtain > the mean ratios of treatment A and B. > To this end, should I fit the model using the ratio of X group (X/n)? I > tried it as > fit4 <- glmer( X/n ~ treatment + (1|replicate), data=test, family=binomial, > weights=n) > but summary(fit4) is the same as summary(fit2). > I also don't know how to interpret "Correlation of Fixed Effects: treatmentB > -0.568 in the output. >> summary(fit2) > Generalized linear mixed model fit by maximum likelihood (Laplace > Approximation) [glmerMod] > Family: binomial ( logit ) > Formula: cbind(X, n - X) ~ treatment + (1 | replicate) >Data: test > > AIC BIC logLik deviance df.resid > 30.1 29.4-12.0 24.13 > > Scaled residuals: > Min 1Q Median 3Q Max > -0.88757 -0.35065 -0.03137 0.26897 0.67505 > > Random effects: > GroupsNameVariance Std.Dev. > replicate (Intercept) 0.4123 0.6421 > Number of obs: 6, groups: replicate, 3 > > Fixed effects: > Estimate Std. Error z value Pr(>|z|) > (Intercept) -1.7442 0.5438 -3.208 0.00134 ** > treatmentB2.3647 0.4741 4.988 6.11e-07 *** > --- > Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > > Correlation of Fixed Effects: >(Intr) > treatmentB -0.568 > > Thanks again, > Joshua > > > From: Greg Snow <538...@gmail.com> > Sent: Wednesday, September 28, 2016 12:49:49 PM > To: Shuhua Zhan > Cc: r-help@R-project.org > Subject: Re: [R] How to test a difference in ratios of count data in R > > There are multiple ways of doing this, but here are a couple. > > To just test the fixed effect of treatment you can use the glm function: > > test <- read.table(text=" > replicate treatment n X > 1 A 32 4 > 1 B 33 18 > 2 A 20 6 > 2 B 21 18 > 3 A 7 0 > 3 B 8 4 > ", header=TRUE) > > fit1 <- glm( cbind(X,n-X) ~ treatment, data=test, family=binomial) > summary(fit1) > > Note that the default baseline value may differ between R and SAS, > which would result in a reversed sign on the slope coefficient (and > different intercept). > > To include replicate as a random effect you need an additional > package, here I use lme4 and the glmer function: > > library(lme4) > fit2 <- glmer( cbind(X, n-X) ~ treatment + (1|replicate), data=test, > family=binomial) > summary(fit2) > > > > On Tue, Sep 27, 2016 at 9:03 PM, Shuhua Zhan wrote: >> Hello R-experts, >> I am interested to determine if the ratio of counts from two groups differ >> across two distinct treatments. For example, we have three replicates of >> treatment A, and three replicates of treatment B. For each treatment, we >> have counts X from one group and counts Y from another group. My >> understanding is that that GLIMMIX procedure in SAS can calculate whether >> the ratio of counts in one group (X/X+Y) significantly differs between >> treatments. >> >> I think this is the way you do it in SAS. The replicate and treatment >> variables are self-explanatory. The first number (n) refers to the total >> counts X + Y; the second number (X) refers to the counts X. Is there a way >> to do this in R? Since we have 20,000 datasets to be tested, it may be >> easier to retrive the si
Re: [R] Simulating data from a nested design
The examples on the help page for the function "simfun" in the TeachingDemos package have some examples of simulating data from nested designs with some terms fixed and some random. I don't think any of the examples match your conditions exactly, but could be modified to do so (changing a random effect to a fixed effect just means using a specified mean for each level rather than choosing a random value for each level). On Sat, Jun 6, 2015 at 9:04 PM, Jim Silverton wrote: > Hi, > I am trying to 'create' a nested design with A, B nested in A and C nested > in B. C is random and the others are fixed. > Does anyone have any idea how to do this? > I would also like to try the other nested designs with all random and all > effects fixed. > > -- > Thanks, > Jim. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to assign value to a variable dynamically constructed
This is FAQ 7.21. The most important part of the answer in FAQ 7.21 is the last section where it states that it is often easier to use a list rather than messing around with trying to dynamically name global variables. If you tell us what you are trying to accomplish then we may have better advice. The route you are headed down now usually leads to inefficient code and hard to find bugs. On Tue, Jul 7, 2015 at 2:53 PM, Jun Shen wrote: > Dear list, > > Let's say we have a variable (id), whose name is dynamically constructed. > This variable represents a vector or data frame with many elements. Now I > want to specifically assign a value to one of the elements. I couldn't get > it right. > > test <- 'id' # "id" is dynamically constructed through paste() > > id <- 1:4 > > # I can get the element by doing > > get(test)[2] > > # Now I want to assign a value to the second element of this dynamical > variable. > > get(test)[2] <- 5 # doesn't work. > > Thanks a lot. > > Jun Shen > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] tcltk2 entry box
If you want you script to wait until you have a value entered then you can use the tkwait.variable or tkwait.window commands to make the script wait before continuing (or you can bind the code to a button so that you enter the value, then click on the button to run the code). On Wed, Jul 8, 2015 at 7:58 PM, Matthew McCormack wrote: > Wow ! Very nice. Thank you very much, John. This is very helpful and just > what I need. > Yes, I can see that I should have paid attention to tcltk before going to > tcltk2. > > Matthew > > > On 7/8/2015 8:37 PM, John Fox wrote: >> >> Dear Matthew, >> >> For file selection, see ?tcltk::tk_choose.files or ?tcltk::tkgetOpenFile . >> >> You could enter a number in a tk entry widget, but, depending upon the >> nature of the number, a slider or other widget might be a better choice. >> >> For a variety of helpful tcltk examples see >> <http://www.sciviews.org/_rgui/tcltk/>, originally by James Wettenhall but >> now maintained by Philippe Grosjean (the author of the tcltk2 package). >> (You >> probably don't need tcltk2 for the simple operations that you mention, but >> see ?tk2spinbox for an alternative to a slider.) >> >> Best, >> John >> >> --- >> John Fox, Professor >> McMaster University >> Hamilton, Ontario, Canada >> http://socserv.socsci.mcmaster.ca/jfox/ >> >> >> >> >>> -Original Message- >>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Matthew >>> Sent: July-08-15 8:01 PM >>> To: r-help >>> Subject: [R] tcltk2 entry box >>> >>> Is anyone familiar enough with the tcltk2 package to know if it is >>> possible to have an entry box where a user can enter information (such >>> as a path to a file or a number) and then be able to use the entered >>> information downstream in a R script ? >>> >>> The idea is for someone unfamiliar with R to just start an R script that >>> would take care of all the commands for them so all they have to do is >>> get the script started. However, there is always a couple of pieces of >>> information that will change each time the script is used (for example, >>> a different file will be processed by the script). So, I would like a >>> way for the user to input that information as the script ran. >>> >>> Matthew McCormack >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting- >>> guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> >> --- >> This email has been checked for viruses by Avast antivirus software. >> https://www.avast.com/antivirus >> > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to simulate informative censoring in a Cox PH model?
I think that the Cox model still works well when the only information in the censoring is conditional on variables in the model. What you describe could be called non-informative conditional on x. To really see the difference you need informative censoring that depends on something not included in the model. One option would be to use copulas to generate dependent data and then transform the values using your Weibul. Or you could generate your event times and censoring times based on x1 and x2, but then only include x1 in the model. On Wed, Jul 22, 2015 at 2:20 AM, Daniel Meddings wrote: > I wish to simulate event times where the censoring is informative, and to > compare parameter estimator quality from a Cox PH model with estimates > obtained from event times generated with non-informative censoring. However > I am struggling to do this, and I conclude rather than a technical flaw in > my code I instead do not understand what is meant by informative and > un-informative censoring. > > My approach is to simulate an event time T dependent on a vector of > covariates x having hazard function h(t|x)=lambda*exp(beta'*x)v*t^{v-1}. > This corresponds to T~ Weibull(lambda(x),v), where the scale parameter > lambda(x)=lambda*exp(beta'*x) depends on x and the shape parameter v is > fixed. I have N subjects where T_{i}~ Weibull(lambda(x_{i}),v_{T}), > lambda(x_{i})=lambda_{T}*exp(beta_{T}'*x_{i}), for i=1,...,N. Here I assume > the regression coefficients are p-dimensional. > > I generate informative censoring times C_i~ Weibull(lambda(x_i),v_C), > lambda(x_i)=lambda_C*exp(beta_C'*x_i) and compute Y_inf_i=min(T_i,C_i) and > a censored flag delta_inf_i=1 if Y_inf_i <= C_i (an observed event), and > delta_inf_i=0 if Y_inf_i > C_i (informatively censored: event not > observed). I am convinced this is informative censoring because as long as > beta_T~=0 and beta_C~=0 then for each subject the data generating process > for T and C both depend on x. > > In contrast I generate non-informative censoring times > D_i~Weibull(lambda_D*exp(beta_D),v_D), and compute Y_ninf_i=min(T_i,D_i) > and a censored flag delta_ninf_i=1 if Y_ninf_i <= D_i (an observed event), > and delta_ninf_i=0 if Y_ninf_i > D_i (non-informatively censored: event not > observed). Here beta_D is a scalar. I "scale" the simulation by choosing > the lambda_T, lambda_C and lambda_D parameters such that on average T_i and T_i Y_ninf_i. > > The problem is that even for say 30% censoring (which I think is high), the > Cox PH parameter estimates using both Y_inf and Y_ninf are unbiased when I > expected the estimates using Y_inf to be biased, and I think I see why: > however different beta_C is from beta_T, a censored subject can presumably > influence the estimation of beta_T only by affecting the set of subjects at > risk at any time t, but this does not change the fact that every single > Y_inf_i with delta_inf_i=1 will have been generated using beta_T only. Thus > I do not see how my simulation can possibly produce biased estimates for > beta_T using Y_inf. > > But then what is informative censoring if not based on this approach? > > Any help would be greatly appreciated. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] interactive Map: Popups
You might be interested in the HWidentify and HTKidentify functions in the TeachingDemos package. They currently don't do maps, but since the functions are pure R code it would not be hard to modify them. On Wed, Jul 22, 2015 at 5:35 PM, Marie-Louise wrote: > Hello, > I am trying to build a map of a country which shows informations to its > regions in a popup window as soon as someone clicks on a region. > Thank you > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/interactive-Map-Popups-tp4710226.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to simulate informative censoring in a Cox PH model?
As models become more complex it becomes harder to distinguish different parts and their effects. Even for a straight forward linear regression model if X1 and X2 are correlated with each other then it becomes difficult to distinguish between the effects of X1^2, X2^2, and X1*X2. In your case the informative censoring and model misspecification are becoming hard to distinguish (and it could be argued that having informative censoring is really just a form of model misspecification). So I don't think so much that you are doing things wrong, just that you are learning that the models are complex. Another approach to simulation that you could try is to simulate the event time and censoring time using copulas (and therefore they can be correlated to give informative censoring, but without relying on a term that you could have included in the model) then consider the event censored if the censoring time is shorter. On Fri, Jul 24, 2015 at 10:14 AM, Daniel Meddings wrote: > Hi Greg > > Many thanks for taking the time to respond to my query. You are right about > pointing out the distinction between what variables are and are not included > in the event times process and in the censoring process. I clearly forgot > this important aspect. I amended my code to do as you advise and now I am > indeed getting biased estimates when using the informatively censored > responses. The problem is now that the estimates from the independently > censored responses are the same - i.e. they are just as biased. Thus the > bias seems to be due entirely to model mis-specification and not the > informative censoring. > > > To give a concrete example I simulate event times T_i and censoring times > C_i from the following models; > > > T_i~ Weibull(lambda_t(x),v_t),lambda_t(x)=lambda_t*exp( beta_t_0 + > (beta_t_1*Treat_i) + (beta_t_2*Z_i) + (beta_t_3*Treat_i*Z_i) ) > > C_i~ Weibull(lambda_c(x),v_c),lambda_c(x)=lambda_c*exp( beta_c_0 + > (beta_c_1*Treat_i) + (beta_c_2*Z_i) + (beta_c_3*Treat_i*Z_i) ) > > D_i~Weibull(lambda_d(x),v_D), lambda_d(x)=lamda_d*exp( beta_d_0) > > where ; > > beta_t_0 = 1, beta_t_1 = -1, beta_t_2 = 1, beta_t_3 = -2, lambda_t=0.5 > > beta_c_0 = 0.2, beta_c_1 = -2, beta_c_2 = 2, beta_c_3 = -2, > lambda_c=0.5 > > beta_d_0 = -0.7, lambda_d=0.1 > > When I fit the cox model to both the informatively censored responses and > the independent censored responses I include only the Treatment covariate in > the model. > > I simulate Treatment from a Bernoulli distribution with p=0.5 and Z_i from a > beta distribution so that Z ranges from 0 to 1 (I like to think of Z as a > "poor" prognosis probability where Z_i=1 means a subject is 100% certain to > have a poor prognosis and Z_i=0 means zero chance). These parameter choices > give approximately 27% and 25% censoring for the informatively censored > responses (using C_i) and the independent censored responses (using D_i) > respectively. I use N=2000 subjects and 2000 simulation replications. > > The above simulation I get estimates of beta_t_2 of -1.526 and -1.537 for > the informatively censored responses and the independent censored responses > respectively. > > Furthermore when I fit a cox model to the full responses (no censoring at > all) I get an estimate of beta_t_2 of -1.542. This represents the best that > can possibly be done given that Z and Treat*Z are not in the model. Clearly > censoring is not making much of a difference here - model mis-specification > dominates. > > I still must be doing something wrong but I cannot figure this one out. > > Thanks > > Dan > > > > On Thu, Jul 23, 2015 at 12:33 AM, Greg Snow <538...@gmail.com> wrote: >> >> I think that the Cox model still works well when the only information >> in the censoring is conditional on variables in the model. What you >> describe could be called non-informative conditional on x. >> >> To really see the difference you need informative censoring that >> depends on something not included in the model. One option would be >> to use copulas to generate dependent data and then transform the >> values using your Weibul. Or you could generate your event times and >> censoring times based on x1 and x2, but then only include x1 in the >> model. >> >> On Wed, Jul 22, 2015 at 2:20 AM, Daniel Meddings >> wrote: >> > I wish to simulate event times where the censoring is informative, and >> > to >> > compare parameter estimator quality from a Cox PH model with estimates >> > obtained from event times generated with non-informative censoring. >> > However >> > I am struggling to do this, and I conclude rather than a technical flaw >
Re: [R] How to simulate informative censoring in a Cox PH model?
censoring, but this time it does not attain the "best > possible". > > In conclusion it is clear to me that a stronger Z_i effect in the censoring > model causes the informative censoring to be worse than the non-informative > one (as expected), but a stronger Z_i effect in the event model does not > have this effect and even causes the independent censoring to be worse – > this in general may not hold but I nonetheless see it here. I am wondering > if this is because altering the treatment effect in the event model also > affects the independent censoring process and so it “muddies the waters” > whereas altering the treatment effect in the informative censoring model > obviously confines the changes to just the informative censoring process. > For a fixed treatment effect size in both the event and informative > censoring models the effect of Z_i having a wider range than is possible > under the beta distribution also appears to produce informative censoring > that is worse than the non-informative one. This makes sense I think because > the Z_i-response relationship must be more informative? > > > > Thanks for your suggestion of copulas – I have not come across these. Is > this similar to assuming a event model for censored subjects (this is > unobserved) – i.e. if the event model is different conditional on censoring > then if we could observe the events beyond censoring then clearly the > parameter estimates would be different compared to those obtained when > modelling only non-censored times? > > > > > On Wed, Jul 29, 2015 at 5:37 PM, Greg Snow <538...@gmail.com> wrote: >> >> As models become more complex it becomes harder to distinguish >> different parts and their effects. Even for a straight forward linear >> regression model if X1 and X2 are correlated with each other then it >> becomes difficult to distinguish between the effects of X1^2, X2^2, >> and X1*X2. In your case the informative censoring and model >> misspecification are becoming hard to distinguish (and it could be >> argued that having informative censoring is really just a form of >> model misspecification). So I don't think so much that you are doing >> things wrong, just that you are learning that the models are complex. >> >> Another approach to simulation that you could try is to simulate the >> event time and censoring time using copulas (and therefore they can be >> correlated to give informative censoring, but without relying on a >> term that you could have included in the model) then consider the >> event censored if the censoring time is shorter. >> >> On Fri, Jul 24, 2015 at 10:14 AM, Daniel Meddings >> wrote: >> > Hi Greg >> > >> > Many thanks for taking the time to respond to my query. You are right >> > about >> > pointing out the distinction between what variables are and are not >> > included >> > in the event times process and in the censoring process. I clearly >> > forgot >> > this important aspect. I amended my code to do as you advise and now I >> > am >> > indeed getting biased estimates when using the informatively censored >> > responses. The problem is now that the estimates from the independently >> > censored responses are the same - i.e. they are just as biased. Thus the >> > bias seems to be due entirely to model mis-specification and not the >> > informative censoring. >> > >> > >> > To give a concrete example I simulate event times T_i and censoring >> > times >> > C_i from the following models; >> > >> > >> > T_i~ Weibull(lambda_t(x),v_t),lambda_t(x)=lambda_t*exp( beta_t_0 + >> > (beta_t_1*Treat_i) + (beta_t_2*Z_i) + (beta_t_3*Treat_i*Z_i) ) >> > >> > C_i~ Weibull(lambda_c(x),v_c),lambda_c(x)=lambda_c*exp( beta_c_0 + >> > (beta_c_1*Treat_i) + (beta_c_2*Z_i) + (beta_c_3*Treat_i*Z_i) ) >> > >> > D_i~Weibull(lambda_d(x),v_D), lambda_d(x)=lamda_d*exp( beta_d_0) >> > >> > where ; >> > >> > beta_t_0 = 1, beta_t_1 = -1, beta_t_2 = 1, beta_t_3 = -2, >> > lambda_t=0.5 >> > >> > beta_c_0 = 0.2, beta_c_1 = -2, beta_c_2 = 2, beta_c_3 = -2, >> > lambda_c=0.5 >> > >> > beta_d_0 = -0.7, lambda_d=0.1 >> > >> > When I fit the cox model to both the informatively censored responses >> > and >> > the independent censored responses I include only the Treatment >> > covariate in >> > the model. >> > >> > I simulate Treatment from a Bernoulli distribution with p=
Re: [R] fuction to find outlier
Pushpa, To extend John Fox's answer a little. Look at the "outliers" dataset in the TeachingDemos package, see "?outliers" and run the examples on that help page. Then ask yourself if you are comfortable with the automatic outlier removal shown in the example. On Mon, Dec 29, 2014 at 12:39 PM, John Fox wrote: > Dear Pushpa Methekar, > > This apparently uses the outlierTest() function in the car package. I'm > afraid that I find your code incomprehensible and there's not enough > information here to reproduce what you've done. You're looping over the > index i in 1:10, explicitly incrementing the loop index at the end of the > loop (which, thankfully, will have no effect), and doing the same things in > each iteration -- i.e., repeatedly executing several commands without > modification. All this seems terribly confused and not clearly related to > locating and dealing with outliers. > > Furthermore, it's not clear to me that what you propose is sensible -- to > delete outliers after performing statistical tests, in each case for a > single outlier, apparently mechanically and without investigating what's > going on in each case. It would probably be a good idea to consult a > competent statistician to help you decide how to proceed. > > All that said, to answer your question directly, probably the easiest way > to > remove an observation from a fitted model is to use update() with the > subset > argument. For example model.1 <- update(model, subset = -6) would remove > case 6 from model and assign the result to model.1. > > Best, > John > > --- > John Fox, Professor > McMaster University > Hamilton, Ontario, Canada > http://socserv.socsci.mcmaster.ca/jfox/ > > > > > -Original Message- > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of > > Methekar, Pushpa (GE Transportation, Non-GE) > > Sent: Monday, December 29, 2014 7:37 AM > > To: r-help@r-project.org > > Subject: [R] fuction to find outlier > > > > Hi all, I am stuck on outlier, while doing regression analysis. I done > > up to modelling ,I got lm model for each y and x. > > Now I want to find out outlier in that models. How do I find out outlier > > and remove them. > > > > > > for(i in 1:10){ > > t1=print(outlierTest(fitted.modely1.temp.l ,cutoff=0.05, n.max=1, > > order=TRUE)) > > print(outlierTest(fitted.modely2.avg.pcp,cutoff=0.05, n.max=1, > > order=TRUE)) > > outlierTest(fitted.modely3.bshc,cutoff=0.05, n.max=1, order=TRUE ) > > > > outlierTest(fitted.modely4.bsco ,cutoff=0.05, n.max=1, order=TRUE) > > > > outlierTest(fitted.modely5.gets ,cutoff=0.05, n.max=1, order=TRUE) > > > > outlierTest(fitted.modely6.gimep,cutoff=0.05, n.max=1, order=TRUE ) > > > > outlierTest(fitted.modely7.ts ,cutoff=0.05, n.max=1, order=TRUE) > > > > outlierTest(fitted.modely8.imp ,cutoff=0.05, n.max=1, order=TRUE) > > outlierTest(fitted.modely9.maf ,cutoff=0.05, n.max=1, order=TRUE) > > i<-i+1 > > } > > fix(xsys) > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Approximation of a function from R^2 to R
Yes, there are several. Which is best and which subset to suggest depends on what you are trying to do, what your inputs look like (do you have the function, but want a simpler approximation? or do you have observations/datapoints?) If you can give us more detail about what you have to work with and what type of "approximation" you want then we can be of more help. On Wed, Jan 14, 2015 at 10:32 AM, rala wrote: > Hello, > I am a beginner and I wanted to know if there is a way to approximate a > function that has 2 input variables and one output. > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Approximation-of-a-function-from-R-2-to-R-tp4701805.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Approximation of a function from R^2 to R
why not just use the tools in npudens? they can predict on a new set. You can also you tools like fitdistr to fit a parametric multivariate density, or you can use loess or lm with poly or splines to estimate the surface (but this will not guarantee a volume of 1). On Thu, Jan 15, 2015 at 2:19 AM, rala wrote: > Thanks for the reply. I have datapoints. > What I actually want to do is to estimate a joint density function. > I used npudens() to estimate the kernel density of two vectors and got the > densities at the evaluation points. Now I want an approximation for this so > I can have an estimate for different points. > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Approximation-of-a-function-from-R-2-to-R-tp4701805p4701828.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Need help with BIG Data
There is a section in the High-Performance Computing (HPC) CRAN Task View on "Large memory and out-of-memory data" ( http://cran.r-project.org/web/views/HighPerformanceComputing.html) that should probably be the first place to start. On Wed, Jan 21, 2015 at 8:18 AM, Paromita Guha wrote: > Hi all, > > I have a dataset with more than 16800 rows and 2000 columns. I have been > trying to run some econometric estimation and regressions as well as some > statistical procedures on the dataset and R keeps giving me errors. > > I tried attaching the data and I was unable to do so. > > > Could anyone please help me by pointing out some useful websites or > resources that deals with BIG data on R and econometrics procedures. I > googled and could not find anything much helpful. > > Thanks for your help. > > Paromita > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] the less-than-minus gotcha
Steve (and any others still paying attention to this thread), Larry Wall (author of Perl) said something along the lines of: things that are similar should look similar, things that are different should look different. Ironically one of the first places I saw that quote was in a Perl vs. Python language war and the same quote was being used by both sides. This made me think that you can learn a lot about how programmers think by what they make look similar and what they make look different (and therefore what they think are similar and different). In R, I see the assignments: foo( x <- something ) as assign to the variable x in the current (or calling) environment and foo( x = something ) as assign to the variable x in the environment created by the function call. With this distinction only "<-" makes any sense at the top level, but then I see assigning to the 2 different environments as 2 different things that should look different. Using "=" for assignment makes sense if (and only if) you consider assigning into different environments to be the same (or at least very similar) thing. Also you mentioned that foo( x <- something ) should always be written as: x <- something foo(x) and for many cases I agree, but consider the counter example of: system.time( out <- longRunningSimulationFunction(n=1e6) ) compared to: out = longRunningSimulationFunction(n=1e6) system.time(out) I would argue that the 1st version is much more useful than the 2nd. On Mon, Feb 2, 2015 at 6:57 PM, Steve Taylor wrote: > Responding to several messages in this thread... > > > > All the more reason to use = instead of <- > > Definitely not! > > Martin and Rolf are right, it's not a reason for that; I wrote that > quickly without thinking it through. An "=" user might be more likely to > fall for the gotcha, if not spacing their code nicely. So the lesson > learned from the gotcha is that it's good to space your code nicely, as > others have siad, not which assignment symbol to use. > > However, I continue to use "=" for assignment on a daily basis without any > problems, as I have done for many years. I remain unconvinced by any and > all of these arguments against it in favour of "<-". People telling me > that I "should" use the arrow need better agruments than what I've seen so > far. > > I find "<-" ugly and "->" useless/pointless, whereas "=" is simpler and > also nicely familiar from my experience in other languages. It doesn't > matter to me that "=" is not commutative because I don't need it to be. > > > Further it can be nicely marked up by a real "left arrow" > > by e.g. the listings LaTeX 'listings' package... > > Now that's just silly, turning R code into graphical characters that are > not part of the R language. > > > foo(x = y) and foo(x <- y) > > I'm well aware of this distinction and it never causes me any problems. > The latter is an example of bad (obfuscated) coding, IMHO; it should be > done in two lines for clarity as follows: > > x = y > foo(x) > > > Using = has it's problems too. > Same goes for apostrophes. > > Shall we discuss putting "else" at the start of line next? > > cheers, > Steve > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to subset data, by sorting names alphabetically.
The split function does essentially this, but puts the results into a list rather than using the dangerous and messy assign function. The overall syntax is simpler as well. On Thu, Feb 12, 2015 at 3:14 AM, Jim Lemon wrote: > Hi Samarvir, > Assuming that you want to generate a separate data frame for each > value of "Name", > > # name of initial data frame is ssdf > for(nameval in unique(ssdf$Name)) assign(nameval,ssdf[ssdf$Name==nameval,]) > > This will produce as many data frames as there are unique values of > ssdf$Name, each named by the values it contains. > > Jim > > > On Thu, Feb 12, 2015 at 3:57 PM, samarvir singh > wrote: > > hello, > > > > I am cleaning some large data with 4 million observation and 7 variable. > > Of the 7 variables , 1 is name/string > > > > I want to subset data, which have same name > > > > Example- > > > > Name var1 var2 var3 var4 var5 var6 > > aa- - - - -- > > ab > > bd > > ac > > ad > > af > > ba > > bd > > aa > > av > > > > i want to sort the data something like this > > > > aa > > aa > > all aa in a same subset > > > > and all ab in same subset > > > > every column with same name in a subset > > > > > > > > thanks in advance. > > I am new to R community. > > appreciate your help > > - Samarvir > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] bigglm connected to a database
It may be simpler to specify the order in the contrasts rather than trying to order the data. See the C function (notice capitol C). I have never tried this with the bigglm function, so I don't know if it will work the same way or not. But if it works, then that may be a simpler approach. On Tue, Mar 3, 2015 at 1:02 PM, Glenn Schultz wrote: > I can get bigglm working with the following code. > > ModelFit <- bigglm(SMM ~ > I(1-.88 * exp(-.192 * LoanAge))+ > ns(Incentive, df = 5)+ > Purpose + > Occupancy + > TPO + > Servicer, > data = sqlQuery(Train.Data, ModelData), > family = binomial(link = "logit"), > chuncksize = 1, > maxit = 100) > > However, I would like to order the factors so I wrote the following code > to make data. However, it is not working. I have read through the manual > as well as some examples provided and I am not having much success with the > revised code below. I think I need to make data and provide ordering of > the factors in the make data but so far this scheme has not worked. I > think I am missing somethin any insights are appreciated. > > Best Regards, > Glenn > > make.data <- function(connection, query, chunksize,...){ > > function(reset = FALSE) { > if (reset) { > if (got > 0) { > dbClearResult(result) > result <<- dbSendQuery(Train.Data, ModelData) > got <<- 0 > } > return(TRUE) > } > rval <- fetch(result, n = chunksize) > got <<- got + nrow(rval) > if (nrow(rval) == 0) > return(NULL) > return(rval) > } > } > > data <- make.data(connection = Train.Data, query = ModelData, chunksize = > 1) > > ModelFit <- bigglm(SMM ~ > I(1-.88 * exp(-.192 * LoanAge))+ > ns(Incentive, df = 5)+ > Purpose + > Occupancy + > TPO + > Servicer, > data = data, > family = binomial(link = "logit"), > maxit = 100) > > > > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Kruskal-Wallace power calculations.
t;> >we >>> >cannot rely on ANOVA or a similar parametric test. What I would like >>> >to >>> >find is a mechanism for making power calculations for the KW test given >>> >the >>> >nonparametric assumptions. My perusal of the literature has suggested >>> >that >>> >a simulation would be the best method. >>> > >>> >Can anyone point me to good examples of such simulations for KW in R? >>> >And >>> >does anyone have a favourite package for generating simulated data or >>> >conducting such tests? >>> > >>> >Thank you, >>> >Collin. >>> > >>> > [[alternative HTML version deleted]] >>> > >>> >__ >>> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> >https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 values
Thanks for your final paragraph, we sometimes see people who want us to do their homework for them and that does not go over well, but I think you situation is one where many would be happy to help. So here are some hints to help: The rnorm command expects the standard deviation, not the variance, so to generate normals with variance equal to 25 you need to specify the square root (5) as the 3rd argument. The rep command will just repeat the 40 random number 500 times, not generate new ones, so you will have the exact same sample (and all in one long vector). There are a few different ways to do this, but for easiest understanding I would suggest using the replicate function, this function will run a set of code the requested number of times, so think about how you would generate your data and compute the test statistic from the generated data, then pass that code to the replicate function (if it is more than 1 line then use curly brackets ({}) to group the lines of code) to generate your 500 test statistics. On Mon, Apr 6, 2015 at 4:52 PM, Osiris10101 wrote: > Hello, > > I'm facing the following task: > Simulate 500 values of the statistic (n-1)s^2/sigma^2 based on taking 500 > samples of size n=40 > from the N(mu=10; sigma^2 = 25) distribution. > > I think with the following command: > rep(rnorm(40,10,25),times=500) > I was able to simulate the samples but how I now can simulate the values of > the chi-square-distribution is a mystery to me... > > I hope anyone can help me, shouldn't be a big problem... > > Thanks in advance! > > Reason for posting: > I started a course at the University of Manchester and had to catch up with > R, which I never used back in Switzerland. Now I'm solving some exercises to > get more practice and this is one of them. > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Simulate-values-tp4705574.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Spline function
The uniroot function can be used to find a value in a specified interval, if it exists. On Tue, Aug 14, 2018 at 3:30 PM Tania Morgado Garcia wrote: > > Hello everyone. I'm new to R and I'm using spline functions. With the > command splinefun (x, y) I get the function of interpolating the values x > and y. Later, I can evaluate that function for values of x by obtaining the > respective values of y. The point is that I need the inverse operation, > with the function, for a value of Y I need to know the value of x. Could > you please help me? > A cordial greeting > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] test of independence
The basic test of independence for a table based on the Chi-squared distribution can be done using the `chisq.test` function. This is in the stats package which is installed and loaded by default, so you don't need to do anything additional. There is also the `fisher.test` function for Fisher's exact test (similar hypotheses, different methodology and assumptions, may be really slow on your table). If you need more than the basics provided in those functions, then a search of CRAN may be helpful, or give us more detail to be able to help. On Thu, Dec 20, 2018 at 12:08 AM km wrote: > > Dear All, > > How do I do a test of independence with 16x16 table of counts. > Please suggest. > > Regards, > KM > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Accessing Data Frame
Here is another approach that uses only the default packages: > onecar <- mtcars[10,] > w <- which(duplicated(rbind(mtcars,onecar), fromLast = TRUE)) > w [1] 10 > mtcars.subset <- mtcars[-w,] > > > threecars <- mtcars[c(1,10,15),] > w <- which(duplicated(rbind(mtcars,threecars), fromLast=TRUE)) > w [1] 1 10 15 > mtcars.subset <- mtcars[-w, ] This works with a subset of 1, or more than 1, but could cause problems if you have duplicate rows in your original data frame. If you are willing to use a non-default package then there are many possibilities. The anti_join function from the dplyr package has already been mentioned, but the setdiff function from dplyr would also work here and would be a little simpler for your example: > library(dplyr) > mtcars.subset2 <- setdiff(mtcars,threecars) > identical(as.list(mtcars.subset), as.list(mtcars.subset2)) [1] TRUE The as.list function above was to remove some attributes that were different between the outputs. On Thu, Jan 3, 2019 at 10:59 AM Benoit Galarneau wrote: > > Thanks for the feedback. > Point taken about the data.table package, I will take a look for sure. > As I am new to the R programming, I'm exploring with the default > libraries as a start. > > I have various options that works like this one: > > topCard <- deck[1,] > #Remove card from deck using row name > deck <- deck[!rownames(deck) %in% row.names(topCard),] > > Is it recommended/safe/good practice to work on items using the item names? > > Benoit > > Jeff Newmiller a écrit : > > >> In my programmer's head, something similar to this should "work": ... > >> deck[aCard] > > > > There are some people who agree with you... see the data.table > > package, which can be made to behave like this. > > > > Keep in mind that the aCard data frame in general may have a > > different set of column names or more than one row. (I would be > > concerned that the logic of your application was inefficiently > > designed if `deck` actually has the same columns as `aCard` as in > > your example.) Others have pointed out that data frames are > > typically combined using the merge function, which allows matching > > columns to be specified very flexibly. > > > > > > On January 3, 2019 6:50:22 AM PST, Benoit Galarneau > > wrote: > >> Hi everyone, > >> I'm new to the R world. > >> Probably a newbie question but I am stuck with some concept with data > >> frame. > >> I am following some examples in the "Hands-On Programming with R". > >> > >> In short, how can I access/filter items in a data frame using a > >> variable. > >> > >> One example consists of manipulating elements from a deck of card: > >> > >>> deck > >> face suit value > >> 1 king spades13 > >> 2 queen spades12 > >> 3 jack spades11 > >> 4ten spades10 > >> etc. > >> > >> Let's say I want to remove or filter out the first card. I know I > >> could do deck[-1]. > >> > >> But let's say I have: topCard <- deck[1,] > >> > >> topCard is then a list of 3 elements > >>> topCard > >> face suit value > >> 1 king spades13 > >> > >> My question is the following, how can I remove or filter out the deck > >> using the topCard variable. > >> > >> In my programmer's head, something similar to this should "work": > >>> deck[10,] > >>face suit value > >> 10 four spades 4 > >>> aCard <- deck[10,] > >>> aCard > >>face suit value > >> 10 four spades 4 > >>> deck[aCard] > >> Error in `[.default`(deck, aCard) : invalid subscript type 'list' > >> > >> Wihout having to specify all elements in the logical tests. > >> > >> deck[deck$face == aCard$face & deck$suit == aCard$suit & deck$value == > >> > >> aCard$value,] > >>face suit value > >> 10 four spades 4 > >> > >> __ > >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> https://stat.ethz.ch/mailman/listinfo/r-help > >> PLEASE do read the posting guide > >> http://www.R-project.org/posting-guide.html > >> and provide commented, minimal, self-contained, reproducible code. > > > > -- > > Sent from my phone. Please excuse my brevity. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Issue with t.test
Can you show us an example with the data that you are using and the output from t.test. A t-value of 1.96 is not an automatic rejection. It depends on alpha and the degrees of freedom. Even if we set alpha at 0.05, 1.96 should not give a p-value less than 0.05 with finite degrees of freedom. This also depends on the arguments to t.test. If the alternative is set to "Less" then a t value of 1.96 would give a p-value close to 0.975 for high degrees of freedom. The only time I have seen t.test give a p-value of 1 is when the data mean exactly equals the null hypothesis mean and the alternative is the default of two.sided. For us to diagnose what is going on we need to see your command (how you are calling t.test) and what data you are using. On Tue, Mar 12, 2019 at 1:49 PM SMRUTI BULSARI wrote: > > I am writing this e-mail as I have come across one issue while performing > t-test using R. If the function t.test(…) is used, a p-value of 1 is obtained > for a calculated t-value greater than 1.96. If the t-value is greater than > 1.96, the null hypothesis is rejected. However, if the p-value is greater > than 0.05, one may say that there is not enough evidence to reject the null > hypothesis. Thus, a t-value of greater than 1.96 and a p-value of 1 leaves > the user of R software confused on whether to reject or not to reject the > null. Moreover, how can p-value of stochastic process be exactly equal to 1? > Can you please guide me on whom should I report this issue to? Or can you > please forward this issue to the appropriate person / team? > > Thanking you, > > Sincerely, > > Smruti Bulsari > > Assistant Professor > Department of Human Resource Development > Veer Narmad South Gujarat University > Surat - 395 007 > (Gujarat) INDIA > > Ph:+91-261-2256071 (Ext. 204) > > Alternate E-mail: sbbuls...@vnsgu.ac.in > > LinkedIn Profile: https://www.linkedin.com/in/smruti-bulsari-0a30b312/ > > Blog Posts: https://wordpress.com/posts/smrutibulsari.wordpress.com > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Application design.
Here are 2 possibilities to consider. The shiny package allows a web browser interface to R. It can run from a server, but can also run just on a single computer. You could set this up like you suggest, where the user would double click on an icon on the desktop which would then run R, load the package and open the browser. The user can then make some selections in the browser (subset the data, choose cutoffs, etc.) and the resulting graphs and summaries will show up in the browser window. I don't know how hard it is to copy and paste from the browser to power point, but viewing will be nicely automatic (and possibly just printing or saving the resulting web page may be enough to pass up the line). The knitr package along with the pandoc program provides a system for creating a template file that can then be processed to create a final result. Again you could set up an icon on the desktop to run R and process the template file. The template file would have the code for querying the data and producing the graphs and summaries and also how to display them. I don't think that knitr/pandoc currently has a way to directly create power point slides, but it does have tools for creating pdf or html based slides (I do the pdf ones quite often, yes on windows) or you can produce a word document as the output that can then easily be copied/pasted to power point (I do this as well when clients want to do the copy/paste rather than having me create a single pdf report). Also, if you have not already, read the help page ?Startup, this gives details on what R does as it starts and gives options for automatically running code when R starts. On Mon, Jul 21, 2014 at 8:24 PM, John McKown wrote: > I'm designing an R based application for my boss. It's not much, but > it might save him some time. What it will be doing is reading data > from an MS-SQL database and creating a number of graphs. At present, > he must log into one server to run a vendor application to display the > data in a grid. He then cuts this data and pastes it into an Excel > spreadsheet. He then generates some graphs in Excel. Which he then > cuts and pastes into a Power Point presentation. Which is the end > result for distribution to others up the food chain. > > What I would like to do is read the MS-SQL data base using RODBC and > create the graphs using ggplot2 instead of using Excel. I may end up > being told to create an Excel file as well. > > My real question is organizing the R programs to do this. Basically > what I was thinking of was a "master" program. It does the ODBC work > and fetches the data into one, or more, data.frames. I was then > thinking that it would be better to have separate source files for > each graph produced. I would use the source() function in the "master" > R program to load & execute each one in order. Is this a decent > origination? Or would it be better for each "create a graph" R file to > really just define a unique function which the "master" program would > then invoke? I guess this latter would be a good way to keep the > workspace "clean" since all the variables in the functinon would "go > away" when the function ended. > > I guess what I'm asking is how others organize the R applications. Oh, > I plan for this to be run by my boss by double clicking on the > "master" R source file, which I will associate with the Rscript > program in Windows. Yes, this is Windows based . > > Appreciate your thoughts. Especially if I'm really off track. > > -- > There is nothing more pleasant than traveling and meeting new people! > Genghis Khan > > Maranatha! <>< > John McKown > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] Importing random subsets of a data file
For speed your best choice is probably to load your data into a database, then pull your samples from the database. A simple database is SQLite and there are R packages that work directly with that database. Can the later samples contain some of the same rows as previous samples? Or once a row is used in a sample, it can never be used again in a later sample? If the former you could use R to choose a sample of "row numbers" then ask the database for those rows (some databases have the concept of rows built in, others would need a sequential column of "row numbers" added), then repeat for each sample. If the later then you could add a column to the database based on randomly generated numbers and create an index (sort) by that column, then select the 1st n observations as the 1st sample, the next n observations as the 2nd sample, etc. On Wed, Jul 23, 2014 at 9:33 AM, Khurram Nadeem wrote: > Hi R folks, > > Here is my problem. > > *1.* I have a large data file (say, in .csv or .txt format) containing 1 > million rows and 500 variables (columns). > > *2.* My statistical algorithm does not require the entire dataset but just > a small random sample from the original 1 million rows. > > *3. *This algorithm needs to be applied 1 times, each time generating a > different random sample from the 'big' file as described in (2) above. > > Is there a way to 'import' only a (random) subset of rows from the .csv > file without importing the entire dataset? A quick search on various R > forums suggest that read.table() does not have this functionality. > Obviously, I want to avoid importing the whole file because of memory > issues. Looking forward to your help. > > Thanks, > Khurram > > Khurram Nadeem > Postdoctoral Research Fellow > Department of Mathematics & Statistics > Acadia University, NS, Canada. > > [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] interactive labeling/highlighting on multiple xy scatter plots
There is the TkBrush function in the TeachingDemos package that gives brushing in a scatterplot matrix using a Tk interface rather than ggobi. There is also the iplots package which allows you to create multiple scatterplots, histograms, boxplots, barcharts, etc. and points selected in any one of the plots will then be highlighted in all the others. Both of those solutions require R to be installed. I don't know of any way to get what you want without installing at least one of ggobi or R (or some other program of similar complexity to install). On Mon, Jul 28, 2014 at 6:48 PM, Shi, Tao wrote: > hi list, > > I'm comparing the changes of ~100 analytes in multiple treatment conditions. > I plotted them in several different xy scattter plots. It would be nice if I > mouse over one point on one scatter plot, the label of the analyte on that > scatter plot AS WELL AS on all other scatter plots will be automatically > shown. I know brushing in rggobi does this, but its interface is not good > and it needs R or ggobi to run (I want send the results to the collaborators > and let them to play with it without the need of installing R or ggobi on > their machine). rCharts is nice but so far it can only create one scatter > plot at a time. > > Any good suggestions? > > Many thanks! > > Tao > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] interactive labeling/highlighting on multiple xy scatter plots
Another option that is in developement, but may do what you want is ggvis (http://ggvis.rstudio.com/). I have seen an example of brushing created with ggvis that can then be embedded in a web page. I am not sure if you can send the html and support files directly to someone without R (probably Rstudio) or if you need to upload it to a server for others to see, but the later is still an option for collaborators who do not have R installed. On Tue, Jul 29, 2014 at 2:13 PM, Shi, Tao wrote: > Thank you very much, Greg and Ramnath, for the pointers! I'll explore more. > > > > > On Tuesday, July 29, 2014 8:10 AM, Ramnath Vaidyanathan > wrote: > > > > There are plugins for rCharts that help you create custom charts. > > Here is a scatterplot matrix example > > http://mostlyconjecture.com/2014/02/09/scatterplot-matrix-with-rcharts/ > > > It doesn't support brushing, but I think it won't be hard adding that > behavior if you contact its author. > > Hope this helps. > > Best, > Ramnath > > > > __ > Ramnath Vaidyanathan > Assistant Professor of Operations Management > Desautels Faculty of Management > 1001 Sherbrooke Street West > Montreal, QC H3A 1G5 > Ph: +1 (514) 398-1457 > __ > > > On Tue, Jul 29, 2014 at 11:01 AM, Greg Snow <538...@gmail.com> wrote: > > There is the TkBrush function in the TeachingDemos package that gives >>brushing in a scatterplot matrix using a Tk interface rather than >>ggobi. There is also the iplots package which allows you to create >>multiple scatterplots, histograms, boxplots, barcharts, etc. and >>points selected in any one of the plots will then be highlighted in >>all the others. Both of those solutions require R to be installed. >> >>I don't know of any way to get what you want without installing at >>least one of ggobi or R (or some other program of similar complexity >>to install). >> >>On Mon, Jul 28, 2014 at 6:48 PM, Shi, Tao wrote: >>> hi list, >>> >>> I'm comparing the changes of ~100 analytes in multiple treatment >>> conditions. I plotted them in several different xy scattter plots. It >>> would be nice if I mouse over one point on one scatter plot, the label of >>> the analyte on that scatter plot AS WELL AS on all other scatter plots will >>> be automatically shown. I know brushing in rggobi does this, but its >>> interface is not good and it needs R or ggobi to run (I want send the >>> results to the collaborators and let them to play with it without the need >>> of installing R or ggobi on their machine). rCharts is nice but so far it >>> can only create one scatter plot at a time. >>> >>> Any good suggestions? >>> >>> Many thanks! >>> >>> Tao >>> >>> __ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> >> >>-- >>Gregory (Greg) L. Snow Ph.D. >>538...@gmail.com >> -- Gregory (Greg) L. Snow Ph.D. 538...@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] a knitr question
My preference when teaching is to have the code and results look the same as it appears in the R console window, so with the prompts and without the output commented. But then I also `purl` my knitr file to create a script file to give to the students that they can copy and paste from easily. On Wed, Jul 30, 2014 at 8:45 AM, Ista Zahn wrote: > On Tue, Jul 29, 2014 at 10:17 PM, Erin Hodgess > wrote: >> I was thinking that for teaching, it may be helpful for them to see the >> whole thing. > > Hopefully you're teaching them to write their code in a script, in > which case the prompt will not be helpful. > > Best, > Ista >> >> >> On Tue, Jul 29, 2014 at 6:56 PM, Yihui Xie wrote: >> >>> Yeah, it is just my personal opinion. Some users like it, and some do not. >>> >>> Regards, >>> Yihui >>> -- >>> Yihui Xie >>> Web: http://yihui.name >>> >>> >>> On Tue, Jul 29, 2014 at 5:36 PM, Peter Alspach >>> wrote: >>> > Kia ora Erin >>> > >>> > But beware - to quote from Yihui 2013 introduction to knitr >>> > >>> > "It is easy to revert to the output with prompts (set option >>> prompt=TRUE), and you will quickly realize the inconvenience to the readers >>> if they want to copy and run the code ..." >>> > >>> > Peter Alspach >>> > >>> > -Original Message- >>> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] >>> On Behalf Of Erin Hodgess >>> > Sent: Wednesday, 30 July 2014 10:28 a.m. >>> > To: r-help@r-project.org >>> > Subject: Re: [R] a knitr question >>> > >>> > Sorry: just solved it. >>> > >>> > You simply include "prompt=TRUE" in the <<>> section >>> > >>> > Thanks, >>> > Erin >>> > >>> > >>> > >>> > On Tue, Jul 29, 2014 at 6:22 PM, Erin Hodgess >>> > wrote: >>> > >>> >> Hello! >>> >> >>> >> When constructing code using knitr, is there a way to get the ">" >>> >> prompt to appear, please? >>> >> >>> >> Everything else works great!! >>> >> >>> >> Thank you! >>> >> >>> >> Sincerely, >>> >> Erin >>> >> >>> >> >>> >> >>> >> -- >>> >> Erin Hodgess >>> >> Associate Professor >>> >> Department of Mathematical and Statistics University of Houston - >>> >> Downtown >>> >> mailto: erinm.hodg...@gmail.com >>> >> >>> > >>> > >>> > >>> > -- >>> > Erin Hodgess >>> > Associate Professor >>> > Department of Mathematical and Statistics University of Houston - >>> Downtown >>> > mailto: erinm.hodg...@gmail.com >>> >> >> >> >> -- >> Erin Hodgess >> Associate Professor >> Department of Mathematical and Statistics >> University of Houston - Downtown >> mailto: erinm.hodg...@gmail.com >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] interactive labeling/highlighting on multiple xy scatter plots
The brushing may only be available in the development version of ggvis. See here for the example: https://github.com/rstudio/webinars/tree/master/2014-01 On Thu, Jul 31, 2014 at 10:17 AM, Shi, Tao wrote: > I looked at ggvis briefly before, but didn't notice its brushing capability. > Now you explained. > > Thanks, both! > > Tao > > > > > On Wednesday, July 30, 2014 9:50 AM, Ramnath Vaidyanathan > wrote: > > > > ggvis is an excellent option to do this kind of stuff. > > The only limitation currently is that all sorts of interactivity (tooltips, > brushing etc.) are done on the server side using Shiny. So you have to upload > your HTML to a shiny server for the interactivity to work. > > Best, > Ramnath > > > > __ > Ramnath Vaidyanathan > Assistant Professor of Operations Management > Desautels Faculty of Management > 1001 Sherbrooke Street West > Montreal, QC H3A 1G5 > Ph: +1 (514) 398-1457 > __ > > > On Wed, Jul 30, 2014 at 12:45 PM, Greg Snow <538...@gmail.com> wrote: > > Another option that is in developement, but may do what you want is >>ggvis (http://ggvis.rstudio.com/). I have seen an example of brushing >>created with ggvis that can then be embedded in a web page. I am not >>sure if you can send the html and support files directly to someone >>without R (probably Rstudio) or if you need to upload it to a server >>for others to see, but the later is still an option for collaborators >>who do not have R installed. >> >> >>On Tue, Jul 29, 2014 at 2:13 PM, Shi, Tao wrote: >>> Thank you very much, Greg and Ramnath, for the pointers! I'll explore more. >>> >>> >>> >>> >>> On Tuesday, July 29, 2014 8:10 AM, Ramnath Vaidyanathan >>> wrote: >>> >>> >>> >>> There are plugins for rCharts that help you create custom charts. >>> >>> Here is a scatterplot matrix example >>> >>> http://mostlyconjecture.com/2014/02/09/scatterplot-matrix-with-rcharts/ >>> >>> >>> It doesn't support brushing, but I think it won't be hard adding that >>> behavior if you contact its author. >>> >>> Hope this helps. >>> >>> Best, >>> Ramnath >>> >>> >>> >>> __ >>> Ramnath Vaidyanathan >>> Assistant Professor of Operations Management >>> Desautels Faculty of Management >>> 1001 Sherbrooke Street West >>> Montreal, QC H3A 1G5 >>> Ph: +1 (514) 398-1457 >>> __ >>> >>> >>> On Tue, Jul 29, 2014 at 11:01 AM, Greg Snow <538...@gmail.com> wrote: >>> >>> There is the TkBrush function in the TeachingDemos package that gives >>>>brushing in a scatterplot matrix using a Tk interface rather than >>>>ggobi. There is also the iplots package which allows you to create >>>>multiple scatterplots, histograms, boxplots, barcharts, etc. and >>>>points selected in any one of the plots will then be highlighted in >>>>all the others. Both of those solutions require R to be installed. >>>> >>>>I don't know of any way to get what you want without installing at >>>>least one of ggobi or R (or some other program of similar complexity >>>>to install). >>>> >>>>On Mon, Jul 28, 2014 at 6:48 PM, Shi, Tao wrote: >>>>> hi list, >>>>> >>>>> I'm comparing the changes of ~100 analytes in multiple treatment >>>>> conditions. I plotted them in several different xy scattter plots. It >>>>> would be nice if I mouse over one point on one scatter plot, the label of >>>>> the analyte on that scatter plot AS WELL AS on all other scatter plots >>>>> will be automatically shown. I know brushing in rggobi does this, but >>>>> its interface is not good and it needs R or ggobi to run (I want send the >>>>> results to the collaborators and let them to play with it without the >>>>> need of installing R or ggobi on their machine). rCharts is nice but so >>>>> far it can only create one scatter plot at a time. >>>>> >>>>> Any good suggestions? >>>>> >>>>> Many thanks! >>>>> >>>>> Tao >>>>> >>>>> __ >>>>> R-help@r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>> PLEASE do read the posting guide >>>>> http://www.R-project.org/posting-guide.html >>>>> and provide commented, minimal, self-contained, reproducible code. >>>> >>>> >>>> >>>>-- >>>>Gregory (Greg) L. Snow Ph.D. >>>>538...@gmail.com >>>> >> >> >> >>-- >>Gregory (Greg) L. Snow Ph.D. >>538...@gmail.com >> -- Gregory (Greg) L. Snow Ph.D. 538...@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] Need(?) way to create a "picture" (or "plot") of a data.frame
I think it may be time for you to rethink your process. Yes there are ways to do what you are asking, but when you start wanting to combine graphs, tables, r output and descriptions and annotations then it is time to look into tools like knitr. With knitr you can create a template file with R code to create the graphs of interest as well as tables and output and include any descriptions/annotations that you want. Then you process the template into a report with the code being run for you and the results inserted into the final report. With knitr, and the pandoc program, you can generate the final report as a pdf file, html file, MS Word document, and others. I don't think that you can generate Power Point directly yet, but you can generate pdf or html slides (better than Power point anyways) or put everything of interest into a Word document that can then be easily cut and paste to Power Point. This will require some investment up front and a shift in the way you are doing things, but in the long run it can be a real time and effort saver. On Thu, Jul 31, 2014 at 5:49 AM, John McKown wrote: > OK, I'm probably using the wrong tool for this, but I'm doing > everything else in this project in R, so I'm looking at how to do this > too. I create a number of graphs using ggplot2. I use the png() > function before the print(..graph.variable..) in order to create a PNG > file which can be embedded in a MS PowerPoint display. This is working > fairly well. > > But what I need now is a way to create a png file which is basically a > "picture" of what you might see when you simply display a data.frame > using Rstudio or even from the command prompt. I considered just using > sink() and print(), but I have two problems. First, it doesn't create > a PNG output. Second, I need to put in text annotations, title, etc. > So what I need might be what a "geom_data.table" would produce, if > such a thing existed in ggplot2. > > Is there another "plotting" package which will do such a weird thing? > > -- > There is nothing more pleasant than traveling and meeting new people! > Genghis Khan > > Maranatha! <>< > John McKown > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] qqnorm with histogram?
Not a single function, but the subplot function in the TeachingDemos package can be used to add the histogram and/or density plot in the empty part of a qqplot. On Sun, Aug 3, 2014 at 1:38 PM, Spencer Graves wrote: > Does a function exist that combines a normal probability plot with a > histogram and maybe a density estimate on the same plot? > > > I'm revising the Wikipedia article on "Normal probability plot", and I > think it would be good to provide examples of this. > > > Thanks, > Spencer > > > p.s. Please reply also with suggestions for how to improve that Wikipedia > article if you feel so inclined. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] break loop with keypress
You could create a tcltk window that looks for a button click and/or key press and when that happens change the value of a variable. Then in your loop you just look at the value of the same variable and break when the value changes. On Tue, Aug 5, 2014 at 6:13 AM, William Simpson wrote: > This works, but it is not quite what I need: > > par(mar=rep(0,4)) > > while(1) > { > img1<-matrix(runif(2500),50,50) > dev.hold(); image(img1,useRaster=TRUE); dev.flush() > img2<-matrix(runif(2500),50,50) > dev.hold(); image(img2,useRaster=TRUE); dev.flush() > } > > I would like to do this: > while(!kbhit()) > { > ... > > where kbhit() polls the keyboard, returning a non-zero integer if the > keyboard buffer has something in it. The animation loop continues > until a key is pressed. > > All the ways of getting user input I have seen (e.g. getGraphicsEvent) > are not suitable because they would wait on each pass through the loop > until the key is pressed and therefore no animation would be > presented. > > Any ideas on how to present a continuous animation loop which is > broken upon user input (keypress or mouse button press)? I am using > Windows 7. Thanks very much for any help. > > Bill > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] how to process multiple data files using R loop
In addition to the solution and comments that you have already received, here are a couple of additional comments: This is a variant on FAQ 7.21, if you had found that FAQ then it would have told you about the get function. The most important part of the answer in FAQ 7.21 is the last part where it says that it is better to use a list. If all the objects of interest are related and you want to do the same or similar things to each one, then having them all stored in a single list can simplify things for the future. You can collect all the objects into a single list using the mget command, e.g.: P_objects <- mget( ls(pattern='P_')) Now that they are in a list you can do the equivalent of your loop, but simpler with the lapply function, e.g.: lapply( P_objects, head, 2 ) And if you want to do other things with all these objects, such as save them, plot them, do a regression analysis on them, delete them, etc. then you can do that using lapply/sapply as well in a simpler way than looping. On Fri, Aug 8, 2014 at 12:25 PM, Fix Ace wrote: > I have 16 files and would like to check the information of their first two > lines, what I did: > > >> ls(pattern="P_") > [1] "P_3_utr_source_data" "P_5_utr_source_data" > [3] "P_exon_per_gene_cds_source_data" "P_exon_per_gene_source_data" > [5] "P_exon_source_data""P_first_exon_oncds_source_data" > [7] "P_first_intron_oncds_source_data" "P_first_intron_ongene_source_data" > [9] "P_firt_exon_ongene_source_data""P_gene_cds_source_data" > [11] "P_gene_source_data""P_intron_source_data" > [13] "P_last_exon_oncds_source_data" "P_last_exon_ongene_source_data" > [15] "P_last_intron_oncds_source_data" "P_last_intron_ongene_source_data" > > > >>for(i in ls(pattern="P_")){head(i, 2)} > > It obviously does not work since nothing came out > > What I would like to see for the output is : > >> head(P_3_utr_source_data,2) > V1 > 1 1 > 2 1 >> head(P_5_utr_source_data,2) > V1 > 1 1 > 2 1 >> > . > > . > . > > > > Could anybody help me with this? > > Thank you very much for your time:) > [[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. > -- Gregory (Greg) L. Snow Ph.D. 538...@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] save results in a loop
Generally if you want to save the results of a loop then it is time to learn to use the lapply and sapply functions instead. Try something like: Tukey <- lapply( 6:n, function(i) Tukey1 = HSD.test(lm(sdata_mg[,i] ~ sdata_mg$Medium+sdata_mg$color+sdata_mg$type+sdata_mg$Micro), 'sdata_mg$Micro') ) though that is still ugly with all those subscripting `$`s. A little nicer might be: tmpfun <- function(vname) { tmp.f <- as.formula( paste( vname, '~ Medium + color + type + Micro') ) HSD.test( lm(tmp.f, data=sdata_mg), 'Micro' ) } Tukey <- lapply( names(sdata_mg)[6:n], tmpfun ) or tmpfun <- function(vname) { vname <- as.name(vname) HSD.test( eval(substitute( lm(vname ~ Medium + color + type + Micro, data=sdata_mg) )), 'Micro') } Tukey <- lapply(names(sdata_mg)[6:n], tmpfun) On Wed, Aug 13, 2014 at 1:43 PM, Wenlan Tian wrote: > Hi, i'm new to R. I have a question about how to save results in a loop to > a file. Here is an example: > > for (i in 6:n){ > Tukey1 = HSD.test(lm(sdata_mg[,n] ~ > sdata_mg$Medium+sdata_mg$color+sdata_mg$type+sdata_mg$Micro), > 'sdata_mg$Micro') > } > > > I don't know how to do it with the loop for all data, so i just tried one > of them, > Tukey1 = HSD.test(lm(sdata_mg[,1] ~ > sdata_mg$Medium+sdata_mg$color+sdata_mg$type+sdata_mg$Micro), > 'sdata_mg$Micro') > Tukey1 > > The results look like this: > > $statistics > Mean CV MSerror HSD r.harmonic > 11.87421 3.102479 0.1357148 0.5288771 7.384615 > > $parameters > Df ntr StudentizedRange > 24 4 3.901262 > > $means >sdata_mg[, 6] std r Min Max > 111d 11.86369 0.5317421 6 11.08623 12.45651 > 125d 11.74433 0.1663130 6 11.53504 12.02412 > 14d 11.54073 0.3877921 8 10.80300 11.96797 > Ground12.16673 0.3391952 12 11.56278 12.86199 > > $comparison > NULL > > $groups > trtmeans M > 1 Ground 12.16673 a > 2 111d 11.86369 ab > 3 125d 11.74433 ab > 4 14d11.54073 b > > > How could i get all the results in the loop? > > [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] Generating a polygon around points
On Fri, Aug 15, 2014 at 4:06 PM, Rolf Turner wrote: > OTOH R is still lacking a mind_read() function so it probably > would NOT give you *exactly* what you want. We can try the (very pre-alpha) esp package: > source('g:/R/esp/esp.R') > esp() [1] "piccalilli crawlspace mole swarthy thunderhead forever" Somehow I doubt that that is *exactly* what the original poster wants. I guess it still needs work. -- Gregory (Greg) L. Snow Ph.D. 538...@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] R packages for power analysis
While there are tools that claim to compute power for tests beyond what you find in the pwr package, I don't like to use them because either I don't agree with the assumptions that they make, or I don't know what assumptions are being made (and therefore I don't know whether I agree with them or not). Once you are beyond the basics there are a lot more assumptions/conditions to think about. A tool that you can just plug a few values into will need to make some assumptions for you. To do a proper power analysis without having the assumptions made for us you need a tool that is more a programming language than a plug-and-chug toy. Luckily R is such a programming language. You can compute power using simulation with just the main R packages. Here is some sample code for a simulation to compute power for the Mann-Whitney (also called the Wilcoxon) test: simfun <- function(n1=25, n2=n1, mu1=5, mu2=mu1) { x1 <- rexp(n1, 1/mu1) x2 <- rexp(n2, 1/mu2) wilcox.test(x1,x2)$p.value } out <- replicate(1, simfun(mu1=5,mu2=8)) hist(out) abline(v=0.05,col='red') mean(out <= 0.05) Change the means/sample sizes/etc. and rerun for additional information. On Thu, Aug 28, 2014 at 1:29 PM, varin sacha wrote: > Dear all, > > I do know very well the pwr packages from Stéphane Champely. > I would have known if somebody knows others packages for power analysis ? > I think here more about the calculation of the power analysis of the > nonparametric tests like the mann whitney or the kruskall wallis. > > Best Regards, > > Sacha > [[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. > -- Gregory (Greg) L. Snow Ph.D. 538...@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] Overwriting a procedure
A perhaps better approach would be to have the functions that currently call fixx accept an argument of a function to use. It could default to fixx, but if the caller passed in a new function it would use that function instead. If you really want to overwrite a function inside of a package namespace then look at the assignInNamespace function in the utils package (but note the warning in the description on the help page). On Tue, Sep 2, 2014 at 12:45 PM, Steven Yen wrote: > Is there a way to over-write a procedure (subroutine)? > > I include a default procedure fixx in a list of procedures which are > compiled into a package. By default, the procedure deliver the data matrix > x. > > fixx <- function(x){ > result <- list(x=x) > return(result) > } > > In some applications, I have transformations (such as squared terms) in some > column(s) in x. So I include the following procedure in the mail (calling) > program, hoping to over-write the default procedure under the same name in > the package (which is the way other languages works, e.g., Gauss): > > fixx <- function(x){ > x[,6]<-x[,5]^2/10 > result <- list(x=x) > return(result) > } > > This does not seem to work. The procedure in the main (calling) program > seems to get ignored. Any idea? 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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] Covariance between two dichotomous variables
If you have 2 dichotomous variables coded 0/1 (and stored as numerics) then the var and cov functions can be used to compute the covariance as if they were continuous variables. Some algebra shows that the continous covariance and the binomial covariance only differ by the denominator (n for binomial, n-1 for continuous), for large sample sizes the difference is trivial, for small sample sizes (or even large if you want) you can just multiply by (n-1)/n to correct. On Tue, Sep 2, 2014 at 10:29 PM, Heather Kettrey wrote: > Hi, > > I am trying to test a mediation hypothesis using coefficients from logistic > regression analyses (x, m, and y are all dichotomous). I am running a test > of significance using MacKinnon and Dwyer's adaptation of Sobel's test > (i.e., correcting for different scales of coefficients in cases of a > dichotomous outcome). > > In order to make this correction I need to compute the covariance between x > and m. I have searched various R packages and the R-help page archive and > cannot find a way to do this in R. > > Does anyone know how to compute the covariance between two dichotomous > variables in R? It seems like there should be a very simple answer to this > question, but I cannot find it. > > Thanks in advance! > > Heather > > > -- > Heather Hensman Kettrey > PhD Candidate > Department of Sociology > Vanderbilt University > > [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] Operator proposal: %between%
The TeachingDemos package has %<% and %<=% operators for a between style comparison. So for your example you could write: 1 %<% 5 %<% 10 or 1 %<=% 5 %<=% 10 And these operators already work with vectors: lb %<=% x %<% ub and can even be further chained: 0 %<% x %<% y %<% z %<% 1 # only points where x < y and y < z and all between 0 and 1. It is a little bit different syntax from yours, but would that do what you want? If not, we could add a %between% function (expand it a bit following Duncan's suggestion) to the TeachingDemos package if you don't want to create your own package. On Thu, Sep 4, 2014 at 8:41 AM, Torbjørn Lindahl wrote: > Not sure if this is the proper list to propose changes like this, if it > passes constructive criticism, it would like to have a %between% operator > in the R language. > > I currently have this in my local R startup script: > > `%between%` <- function(x,...) { > y <- range( unlist(c(...)) ) > return( x >= y[1] & x =< y[2] ) > } > > It allows me to do things like: 5 %between c(1,10) > > and also as act as an "in_range" operator: > foo %between% a.long.list.with.many.values > > This may seem unnecessary, since 5 >= foo[1] && foo<= foo[2] is also quite > short to type, but there is a mental cost to this, eg if you are deeply > focused on a complicated program flow, the %between% construct is a lot > easier to type out, and relate to, than the logically more complex > construct with && and <=/>=, at least in my experience. > > -- > mvh > Torbjørn Lindahl > > [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] Testing general hypotheses on regression coefficients
Others have discussed some of the theoretical approaches (delta method), but as has also been pointed out, this is a mailing list about R, not theory, so here are some approaches to your question from the approach of those of us who like programming R more than remembering theory. I assume that one reason you may be interested in B2/B1 is that you want the confidence interval on the quantity, not just the test of whether it is 0 (that test being equivalent to B2=0 unless B1 is exactly equal to 0). So I will focus more on confidence intervals (which you can use as tests by seeing if the null value is in the interval/region or not). Approach 1, simulation: If all the assumptions hold for the linear regression, then the parameter estimates are considered to by multivariate normal. You can get the covariance matrix for this normal using the vcov function on the summary of your fitted object. Now you can use the mvrnorm function with the estimated means and covariance to generate a bunch of observations from this multivariate normal and compute B2/B1 or some combination of B2/B1 and B4/B3 for each observation. These values represent the distribution of interest and you can calculate a confidence interval by finding the quantiles of the values (0.025 and 0.975 for 95%) or finding the HPD interval (minimum width interval), the emp.hpd function in the TeachingDemos package is one way to do this. For your second hypothesis you could look at B2/B1 - B4/B3 = 0 or (B2/B1) / (B4/B3) = 1, or create a joint confidence region on the 2 ratios and see if the x=y line intersects that region. Approach 2, bootstrap: Bootstrap the whole process, fit the regression model then find the ratio of the estimates. Find the bootstrap confidence interval of the ratio(s), follow above advice. Approach 3, Bayes: Fit a Bayesian regression model and look at the posterior distribution of the ratio(s) of interest, calculate the credible interval/region (the steps will be similar to the previous approaches). Approach 4, simulate from the null: Fit your regression model under then null hypothesis of interest being true (for a more complicated null, your second, you may need to use optimization or quadratic programming to allow some values to vary, but have others dependent on those, then find the least squares solution). Now simulate data based on that model, fit the full regression to the simulated data sets and compare the parameter estimates (or ratios thereof) to the parameter estimates from the original data. You could try any of these approaches for hypotheses where traditional linear hypotheses work and compare the results from the traditional approach to the above approaches to see how they compare (and how many iterations/samples you will need). On Fri, Sep 5, 2014 at 8:17 PM, Chris wrote: > Hi. > > Say I have a model like > > y = a + B1*x1 + B2*x2 + B3*x3 + B4*x4 + e > > and I want to test > > H0: B2/B1 = 0 > > or > > H0: B2/B1=B4/B3 > > (whatever H1). How can I proceed? > > I now about car::linearHypothesis, but I can't figure out a way to do the > tests above. > > Any hint? > > Thanks. > > C > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] read.table() 1Gb text dataframe
When working with datasets too large to fit in memory it is usually best to use an actual database, read the data into the database, then pull the records that you want into R. There are several packages for working with databases, but 2 of the simplest are the RSQLite and sqldf packages (installing them will install the database backend for you). The read.csv.sql function in the sqldf package will read in a csv file by first reading it into the database, then pulling the desired subset (you need to know some basic sql) into R, all the database stuff is handled in the background for you. On Thu, Sep 18, 2014 at 5:48 PM, Stephen HK Wong wrote: > Dear All, > > I have a table of 4 columns and many millions rows separated by > tab-delimited. I don't have enough memory to read.table in that 1 Gb file. > And actually I have 12 text files like that. Is there a way that I can just > randomly read.table() in 10% of rows ? I was able to do that using colbycol > package, but it is not not available. Many thanks!! > > > > Stephen HK Wong > Stanford, California 94305-5324 > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] a REALLY dumb question
Instead of making a local copy and editing, you may consider using the trace function with edit=TRUE, this allows you to insert things like print statements, but takes care of the environment and other linkages for you (and is easy to untrace when finished). On Fri, Oct 3, 2014 at 11:12 AM, Erin Hodgess wrote: > thank you!! > > > On Fri, Oct 3, 2014 at 12:18 PM, Duncan Murdoch > wrote: > >> On 03/10/2014 12:09 PM, Erin Hodgess wrote: >> >>> So please be prepared... >>> >>> Ok. I made a copy of the arima.r function called earima.r to put in some >>> print statements. Fair enough. >>> >>> Now when I run earima, the .Call statements call find the C subroutines. >>> >>> I know that this should be a really simple fix, but I don't know how. I >>> do >>> know that the original arima function is in stats. >>> >>> Sorry for the trouble. >>> >>> >>> >>> If you run >> >> environment(arima) <- environment(stats::arima) >> >> it should work (assuming your function is still called arima). The >> problem is that statements like >> >> .Call(C_ARIMA_Like, y, mod, 0L, TRUE) >> >> refer to variables like C_ARIMA_Like, which are local to the package >> environment of stats. They aren't exported, so your function (which >> presumably has a different environment) can't see them. >> >> Duncan Murdoch >> > > > > -- > Erin Hodgess > Associate Professor > Department of Mathematical and Statistics > University of Houston - Downtown > mailto: erinm.hodg...@gmail.com > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] Hadley's book: paper/PDF/etc. versus github
Hadley, have you tried producing the book in other electronic formats (other than pdf)? such as epub? I tried and ended up with a file that worked, but all the example code was missing (which defeats the convenience of having it on an ebook reader), I did not check if everything else was there or not. thanks, On Fri, Oct 3, 2014 at 6:37 AM, Hadley Wickham wrote: >> Hi, folks. I've got a sort of coupon that would allow me to get a >> copy of "Advanced R" by Hadley Wickham at no cost. OTOH, I've already >> cloned the github repository, and having the "live" Rmd files (or in >> this case, rmd files) is enormously more useful to me than having any >> form of electronic or paper format. > > I presume you mean https://github.com/hadley/adv-r (no need to be > secretive about it ;) > >> The only reason I can think of for getting, say, a PDF version of the >> book is that corrected versions of such books are sometimes (always?) >> made available for free if you've already got the PDF version of the >> book. (I know O'Reilly does this.) > > The pdf version of the book is made from the files in that repo, so I > don't see any advantage there. (You can build the pdf yourself if you > spend a few minutes looking for the right file ;) > >> But if the github version is going to continue to exist, be updated, >> and be generally available, that's even better. IS it going to exist, >> be updated, and be generally available? Any thoughts? > > The github version _is_ the authoritative version of the book (and in > some sense it's already slightly better than the book, since a number > of minor typos have been fixed since the book was published). C&H is > mostly print on demand, so later printings of the book are likely to > pick up the improvements, although there is still some additional > human checking in the process, so it'll only get updated every 6 > months or so. > > The repo and http://adv-r.had.co.nz will continue to exist for the > foreseeable future. > > 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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] par("plt") behaving inconsistely? bug?
I believe that what is happening is that the clipping region is being reset when you call box, but not when you call rect. If you insert the command "par(xpd=NA)" (or TRUE instead of NA) after the plot.new and use the rect commands then you can see both rectangles (because this turns the clipping off). Working with the clipping region (indirectly in your case) is complex since some functions properly reset the region and others do not (and making the others automatically reset it may cause other problems when they reset a clipping region that should not be reset). So the options are: 1 dive into the source code enough to figure out if fixing rect to work with the clipping region is simple or not and submitting a patch 2 wait for Prof Brian Ripley to notice this fact and do the above (he has fixed a couple of other functions when made aware) 3 use par(xpd=TRUE) (or NA) to not clip to the plotting region (this is simple, but will allow things to be drawn outside of the plotting region, on simple example is using abline) 4 use a function that properly sets the clipping region (such as box) before plotting anything else 5 call clip(0,1,0,1) (or with the actual user coordinates) to manually set the clipping region 6 other? On Mon, Oct 6, 2014 at 12:00 PM, Murat Tasan wrote: > Hi all -- I just encountered a behavior that I believe has changed > from previous versions, though I haven't chased back the last version > that behaves as my existing code expects quite yet. > Perhaps this is a bug, though perhaps I'm missing a subtle detail > somewhere in the documentation... > > Here's some code that works as expected (in R 3.1.1): > > > pdf() > plot.new() > > original_plt <- par("plt") > > plt_1 <- c(original_plt[1], >original_plt[1] + (original_plt[2] - original_plt[1]) / 2, >original_plt[3], >original_plt[3] + (original_plt[4] - original_plt[3]) / 2) > par("plt" = plt_1) > plot.window(xlim = c(0, 1), ylim = c(0, 1)) > box() > plt_2 <- c(plt_1[2], >original_plt[2], >plt_1[4], >original_plt[4]) > par("plt" = plt_2) > plot.window(xlim = c(0, 1), ylim = c(0, 1)) > box() > par("plt" = original_plt) > box(lty = 2) > dev.off() > > > This will draw 3 boxes... one in the lower left corner (specified by > plt_1), one in the top right corner (specified by plt_2), and one > dotted box around the full plot box (original_plt). > > Now, if you replace the first two box() calls by: rect(0, 0, 1, 1), > only the lower-left rectangle is drawn. > If you _add_ rect(0, 0, 1, 1) after each box() call, all boxes and > rectangles are correctly drawn. > > It seems that after setting plt once, subsequent plt alterations put > the device into a state that will permits drawing of _some_ things > (e.g. box()), but not other things (e.g. rect, lines, points). > > A kludge to fix this is to call box(col = "white")... but that's quite > the kludge, indeed! > Axis() works just like box(), too... but I haven't exhausted which > drawing functions work and which don't. > > I'd classify this is a bug, but I thought I'd check here first. > I've also only checked this so far with the pdf() device, so I don't > know if it is somehow device-specific. > > I detected this because some existing code (that worked on some > earlier version of R, sorry that I don't know which one yet...) has > suddenly stopped working! > > Cheers! > > -murat > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] HELP
I think we have a fortune candidate. On Thu, Oct 16, 2014 at 12:35 AM, PIKAL Petr wrote: > Hi > > It will be even worse with age, try to contact optician :-) > > If you want to get better answer you need to provide more info about your > file, what you did and how it failed. > > Cheers > Petr > > >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- >> project.org] On Behalf Of JAVAD LESSAN >> Sent: Wednesday, October 15, 2014 2:53 PM >> To: r-help@r-project.org >> Subject: [R] HELP >> >> Hello There! >> >> I have an issue reading a large text file and parsing it. I would be >> grateful if you let me you can help me about? Thanks. >> >> Javad >> >> [[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. > > > Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou > určeny pouze jeho adresátům. > Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně > jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze > svého systému. > Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email > jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat. > Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či > zpožděním přenosu e-mailu. > > V případě, že je tento e-mail součástí obchodního jednání: > - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, > a to z jakéhokoliv důvodu i bez uvedení důvodu. > - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; > Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany > příjemce s dodatkem či odchylkou. > - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným > dosažením shody na všech jejích náležitostech. > - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost > žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně > pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu > případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je > adresátovi či osobě jím zastoupené známá. > > This e-mail and any documents attached to it may be confidential and are > intended only for its intended recipients. > If you received this e-mail by mistake, please immediately inform its sender. > Delete the contents of this e-mail with all attachments and its copies from > your system. > If you are not the intended recipient of this e-mail, you are not authorized > to use, disseminate, copy or disclose this e-mail in any manner. > The sender of this e-mail shall not be liable for any possible damage caused > by modifications of the e-mail or by delay with transfer of the email. > > In case that this e-mail forms part of business dealings: > - the sender reserves the right to end negotiations about entering into a > contract in any time, for any reason, and without stating any reasoning. > - if the e-mail contains an offer, the recipient is entitled to immediately > accept such offer; The sender of this e-mail (offer) excludes any acceptance > of the offer on the part of the recipient containing any amendment or > variation. > - the sender insists on that the respective contract is concluded only upon > an express mutual agreement on all its aspects. > - the sender of this e-mail informs that he/she is not authorized to enter > into any contracts on behalf of the company except for cases in which he/she > is expressly authorized to do so in writing, and such authorization or power > of attorney is submitted to the recipient or the person represented by the > recipient, or the existence of such authorization is known to the recipient > of the person represented by the recipient. > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] how to overwrite a Unary operator ?
You may be interested in looking at Reference Classes/objects (see ?setRefClass). This is a form of OO programming that is more similar to C++ and Java. You could create a counter object that you could then increment with syntax like: x$inc() x$inc(5) The first would increment by the default (1), the second would then increment by 5. On Fri, Oct 17, 2014 at 2:06 AM, PO SU wrote: > > Tks for your alternative way's details. but like you mentioned in graphics > package, i still wonder how to overload an operator which can pass one param > like +2 . > There seems exists some examples for my needing. But i try to find them but > without any results. > can you show me some examples from it? > > > > > > > -- > > PO SU > mail: desolato...@163.com > Majored in Statistics from SJTU > > > > At 2014-10-17 15:16:47, "David Winsemius" wrote: >> >>On Oct 16, 2014, at 10:36 PM, PO SU wrote: >> >>> >>> Tks for your advice, let the ++ problem alone, how to write an >>> Unary operator ? Is it permitted in R? >>> suchasa<-2 , a%+2% will let a be 4 . >> >>OK, that's just wrong. Oh, OK, just for fun, as it were: >> >>inc <- function(x) >>{ >> eval.parent(substitute(x <- x + 1)) >>} >> >> >> > inc(10) >>Error in 10 <- 10 + 1 : invalid (do_set) left-hand side to assignment >> > y=10 >> > inc(y) >> > y >>[1] 11 >> >> >>> I just want to know it , i won't pollute r with it , because i know >>> what is r . : ) >>> >>It's certainly permitted. Just look at all the overloadings of the "+" >>operator in graphics packages. Look up the documentation on methods in >>R. >> >>Why not just use a well-behaved function, though? >> >>.inc <- function(x) x+1 >> > .inc(10) >>[1] 11 >> >>Then you won't be tempted to try 10 <- .inc(10) because it just >>wouldn't make sense. >> >>-- >>David. >> >>> -- >>> >>> PO SU >>> mail: desolato...@163.com >>> Majored in Statistics from SJTU >>> >>> >>> >>> >>> At 2014-10-17 13:09:47, "Rolf Turner" wrote: >>>> On 17/10/14 17:29, PO SU wrote: >>>>> >>>>> Dear expeRts, >>>>> Now i want to know how to implement an Unary operator like i++ >>>>> in cpp's synax form. >>>>> e.g. 2++ will let 2 be 3 , a<-2 ,a++ ,will let a be 3 >>>>> I tried this : >>>>> '%++%'<-function(x){ >>>>>x<<-x+1 >>>>> } >>>>> but it have problem, the biggest one is it seems the function need >>>>> twoparams like a%++%b , how to write a function needing just one >>>>> param? >>>>> >>>>> TKS ! >>>> >>>> Just ***DON'T***. The "++" operator is useful only for those wish to >>>> write code which is obscure to the point of incomprehensibility. It >>>> makes C and its offspring "write only" languages. >>>> >>>> If you are going to use R, use R and don't pollute it with such >>>> abominations. >>>> >>>> cheers, >>>> >>>> Rolf Turner >>>> >>>> >>>> -- >>>> Rolf Turner >>>> Technical Editor ANZJS >>> __ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >>David Winsemius, MD >>Alameda, CA, USA >> > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@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] how to overwrite a Unary operator ?
There is currently no way to write your own unary operator in R. The only current unary operators are prefix (-, +, !). It would take some major changes to the parser to recognize the syntax that you want (which could also break other things that already work well), and with the oo and other methods it is not really needed. You can technically pass and empty expression to a binary operator: > `%++%` <- function(a,b) a + 1 > x <- 5 > x %++% {} [1] 6 but that does not change the value of the variable (and using `assign` just creates its own problems). And syntax like above is more appropriate for a obfuscated R contest than for anything that you want to be understood. There are assignment functions and you could create an object type and an assignment for such that you might be able to have syntax like: a <- {} to increment a, but you would need to declare a class for a before using it and it would probably be even more complicated than needed. If you really want C like syntax then you could always make an active binding: > f <- local({ + e <- environment() + x <- 1 + list(inc = function(v) { + if(missing(v)) { + e$x <- e$x + 1 + } else { + stop('unary inc cannot be assigned to') + } + x + }, + dec = function(v) { + e$x <- e$x - 1 + x + } ) } ) > > makeActiveBinding("x++", f$inc, .GlobalEnv) > makeActiveBinding("x--", f$dec, .GlobalEnv) > > `x++` [1] 2 > `x++` [1] 3 > `x++` [1] 4 > `x--` [1] 3 > `x--` [1] 2 > `x++` [1] 3 > But it seems simpler to just go with the reference class system at this point. On Sun, Oct 19, 2014 at 11:17 AM, PO SU wrote: > > It's a good way to use RF OOS, but it's not my needing, actually, i want is > there exists a way to write a %++% form function that can pass one param to > it? > So i can use 1%++% to get 2 ,a<-2 , a%++% to get a<-3 . > It seems that the operator overwrite system in R, must pass two params. Is it > true? > > > > > -- > > PO SU > mail: desolato...@163.com > Majored in Statistics from SJTU > > > > At 2014-10-18 00:54:40, "Greg Snow" <538...@gmail.com> wrote: >>You may be interested in looking at Reference Classes/objects (see >>?setRefClass). This is a form of OO programming that is more similar >>to C++ and Java. You could create a counter object that you could >>then increment with syntax like: >> >>x$inc() >>x$inc(5) >> >>The first would increment by the default (1), the second would then >>increment by 5. >> >> >> >>On Fri, Oct 17, 2014 at 2:06 AM, PO SU wrote: >>> >>> Tks for your alternative way's details. but like you mentioned in graphics >>> package, i still wonder how to overload an operator which can pass one >>> param like +2 . >>> There seems exists some examples for my needing. But i try to find them but >>> without any results. >>> can you show me some examples from it? >>> >>> >>> >>> >>> >>> >>> -- >>> >>> PO SU >>> mail: desolato...@163.com >>> Majored in Statistics from SJTU >>> >>> >>> >>> At 2014-10-17 15:16:47, "David Winsemius" wrote: >>>> >>>>On Oct 16, 2014, at 10:36 PM, PO SU wrote: >>>> >>>>> >>>>> Tks for your advice, let the ++ problem alone, how to write an >>>>> Unary operator ? Is it permitted in R? >>>>> suchasa<-2 , a%+2% will let a be 4 . >>>> >>>>OK, that's just wrong. Oh, OK, just for fun, as it were: >>>> >>>>inc <- function(x) >>>>{ >>>> eval.parent(substitute(x <- x + 1)) >>>>} >>>> >>>> >>>> > inc(10) >>>>Error in 10 <- 10 + 1 : invalid (do_set) left-hand side to assignment >>>> > y=10 >>>> > inc(y) >>>> > y >>>>[1] 11 >>>> >>>> >>>>> I just want to know it , i won't pollute r with it , because i know >>>>> what is r . : ) >>>>> >>>>It's certainly permitted. Just look at all the overloadings of the "+" >>>>operator in graphics packages. Look up the documentation on methods in >>>>R. >>>> >>>>Why not just use a well-behaved function, though? >>>> >>>>.inc <- function(x) x+1 >>>> > .inc(10) >>>>[1] 11 >>>> >>>>Then you won't be tempted to try 10 <- .inc
Re: [R] plot hclust object
I don't know of any tools that automate this process. For small sample sizes it may be easiest to just do this by hand, for large sample sizes that plot will probably be to complicated to make sense of. There may be a range of moderate sample sizes for which automation (or partial automation) would be helpful. The hclust object has a component of "height" which is an indicator of the distance between 2 components being combined into a cluster, you could convert this into a distance matrix (or extract the distance matrix used to do the clustering if it is available) and then use multidimensional scaling (cmdscale function is one option) to produce a 2 dimensional set of points. Drawing the circles/ellipses/ovals will be more difficult, possibly generate a cloud of normal points, or a small circle, around each point with the variability/radius low enough that the clouds are unlikely to overlap, then find the convex hull (chull function) for the points within a cluster and draw that (it will be a polygon rather than a smooth curve). The gBuffer command in the rgeos package may be another way to create polygons around the points in a group. On Mon, Oct 27, 2014 at 5:42 AM, David Feitosa wrote: > Hello! > > I have a code that creates an hclust object. > After the object creation I plot the object as a dendrogram, > similar to the left image of this link: > > http://www.cs.jhu.edu/~razvanm/fs-expedition/hclust-example.png > > I would like to create another image, but similar to the right, > as a set of nested dots and elipses/circles. > > Anybody knows how to do this? > > Thanks in advance. > > David Feitosa > > (\_(\ > (=°;°) > (("")("") > > [[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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] plot hclust object
Thanks Martin, It is always great to learn that I don't need to reinvent the wheel (especially when I learn that before reinventing). Do you know if there are any help pages that point to cophenetic (see also or other sections). Maybe it is just the way that my brain is wired (along with being a dabbler, but not expert at cluster analysis), but for some reason the word cophenetic never occurred to me as a search term while thinking about how to create the requested plot. On Tue, Oct 28, 2014 at 9:31 AM, Martin Maechler wrote: >>>>>> Greg Snow <538...@gmail.com> >>>>>> on Mon, 27 Oct 2014 12:33:18 -0600 writes: > > > I don't know of any tools that automate this process. For small > > sample sizes it may be easiest to just do this by hand, for large > > sample sizes that plot will probably be to complicated to make sense > > of. There may be a range of moderate sample sizes for which > > automation (or partial automation) would be helpful. The hclust > > object has a component of "height" which is an indicator of the > > distance between 2 components being combined into a cluster, you could > > convert this into a distance matrix > > it has been known for many years how to do this; still, I have > only learned about it from Robert Gentleman (yes, one of the two > fathers of R), when we added the function > > cophenetic() > to R > which does exactly do this: > Provide the distance matrix which is implicitly defined by a > hierarchical clustering. > > Martin Maechler, ETH Zurich > > > (or extract the distance matrix used to do the clustering > > if it is available) and then use multidimensional scaling > > (cmdscale function is one option) to produce a 2 > > dimensional set of points. Drawing the > > circles/ellipses/ovals will be more difficult, possibly > > generate a cloud of normal points, or a small circle, > > around each point with the variability/radius low enough > > that the clouds are unlikely to overlap, then find the > > convex hull (chull function) for the points within a > > cluster and draw that (it will be a polygon rather than a > > smooth curve). The gBuffer command in the rgeos package > > may be another way to create polygons around the points in > > a group. > > > On Mon, Oct 27, 2014 at 5:42 AM, David Feitosa > wrote: > >> Hello! > >> > >> I have a code that creates an hclust object. > >> After the object creation I plot the object as a dendrogram, > >> similar to the left image of this link: > >> > >> http://www.cs.jhu.edu/~razvanm/fs-expedition/hclust-example.png > >> > >> I would like to create another image, but similar to the right, > >> as a set of nested dots and elipses/circles. > >> > >> Anybody knows how to do this? > >> > >> Thanks in advance. > >> > >> David Feitosa > >> > >> (\_(\ > >> (=°;°) > >> (("")("") > >> > >> [[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. > > > > > -- > > Gregory (Greg) L. Snow Ph.D. > > 538...@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. -- Gregory (Greg) L. Snow Ph.D. 538...@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] plot hclust object
I would suggest links to cophenetic on the help pages for dendrogram and possibly plot.hclust and related functions. I was not complaining. I always enjoy learning new things, it is a testament to the breadth and depth of R that even after more than 25 years using S and R, that I can still be pleasantly surprised with functions that I did not know about. The word cophenetic just has a nice ring to it, has a similar rhythm and rhymes with copacetic (I think I will challenge my writer co-worker to come up with a poem including both words). I can see some of the origin of the word in genetics, but dropped in casual conversation it could be interpreted to mean any number of things. I may ask my wife when I get home if she is feeling cophenetic and want to cluster after the kids are in bed (though I should be careful not to agnes, daisy, pam, etc. or she may choose snuggling with the cats instead of me as her clustering). On Tue, Oct 28, 2014 at 12:26 PM, Martin Maechler wrote: >>>>>> Greg Snow <538...@gmail.com> >>>>>> on Tue, 28 Oct 2014 10:31:27 -0600 writes: > > > Thanks Martin, It is always great to learn that I don't need to > > reinvent the wheel (especially when I learn that before reinventing). > > > Do you know if there are any help pages that point to cophenetic (see > > also or other sections). Maybe it is just the way that my brain is > > wired (along with being a dabbler, but not expert at cluster > > analysis), but for some reason the word cophenetic never occurred to > > me as a search term while thinking about how to create the requested > plot. > > I understand. Indeed, the world is never going to be perfect, nor is R. > > Currently the only link to 'cophenetic' is in ?reorder.dendrogram > and it's easy possible you'd neither have seen that page. > > I strongly agree that more \link's would be useful in general > and in particular for cophenetic. I'm happy to take suggestions, > notably if they already use Rd syntax ... ;-) > > Martin > > > On Tue, Oct 28, 2014 at 9:31 AM, Martin Maechler > > wrote: > >>>>>>> Greg Snow <538...@gmail.com> > >>>>>>> on Mon, 27 Oct 2014 12:33:18 -0600 writes: > >> > >> > I don't know of any tools that automate this process. For small > >> > sample sizes it may be easiest to just do this by hand, for large > >> > sample sizes that plot will probably be to complicated to make sense > >> > of. There may be a range of moderate sample sizes for which > >> > automation (or partial automation) would be helpful. The hclust > >> > object has a component of "height" which is an indicator of the > >> > distance between 2 components being combined into a cluster, you > could > >> > convert this into a distance matrix > >> > >> it has been known for many years how to do this; still, I have > >> only learned about it from Robert Gentleman (yes, one of the two > >> fathers of R), when we added the function > >> > >> cophenetic() > >> to R > >> which does exactly do this: > >> Provide the distance matrix which is implicitly defined by a > >> hierarchical clustering. > >> > >> Martin Maechler, ETH Zurich > >> > >> > (or extract the distance matrix used to do the clustering > >> > if it is available) and then use multidimensional scaling > >> > (cmdscale function is one option) to produce a 2 > >> > dimensional set of points. Drawing the > >> > circles/ellipses/ovals will be more difficult, possibly > >> > generate a cloud of normal points, or a small circle, > >> > around each point with the variability/radius low enough > >> > that the clouds are unlikely to overlap, then find the > >> > convex hull (chull function) for the points within a > >> > cluster and draw that (it will be a polygon rather than a > >> > smooth curve). The gBuffer command in the rgeos package > >> > may be another way to create polygons around the points in > >> > a group. > >> > >> > On Mon, Oct 27, 2014 at 5:42 AM, David Feitosa > wrote: > >> >> Hello! > >> >> > >> >> I have a code that creates an hclust object. > >> >> After the object creation I plot the object as a dend
Re: [R] Packages for Handling Large Data Set
Look at the task view for High Performance Computing ( http://cran.r-project.org/web/views/HighPerformanceComputing.html) there is a section on packages for large memory and out-of-memory analyses. There are also sections on parallel computing which is one way to deal with large data if you have access to the right type of cluster (part of the dataset lives on each machine so can fit in the local memory). On Tue, Nov 25, 2014 at 6:06 AM, jeeth ghambole wrote: > Hello All, > > I am working on BackTesting Strategies on stocks using daily prices. > > Initially the size of data was very limited and can be easily handled using > R and SQL, but now my analysis has been extending on large set of data. Can > anyone suggest me the best packages available for handling large datasets. > > Thank you. > > With Regards, > Jeeth G. > > [[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. > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] function to avoid <<-
By "At the top level" Hadley meant to put that code outside of the function definition. In you source file that line should be very near the top, before any function definitions. Then "myenv" will not be temporary (well it will go away when you end the R session). Further, when this code is compiled into a package then "myenv" becomes package local, meaning that functions within the package can access it and the objects inside of it, but it will not interfere with any other packages or the global environment. On Tue, Dec 2, 2014 at 9:32 AM, Karim Mezhoud wrote: > Thanks Dr Hadley, > > but when I use a function the myenv remains temporary and I am to face the > same problem. > > > fun <- function(){ > > myenv <- new.env(parent = emptyenv()) > > fun1 <- function(){ > myenv$X <- 5 > } > > } > > ls(myEnv) > #character(0) > > Ô__ > c/ /'_;kmezhoud > (*) \(*) ⴽⴰⵔⵉⵎ ⵎⴻⵣⵀⵓⴷ > http://bioinformatics.tn/ > > > > On Tue, Dec 2, 2014 at 4:17 PM, Hadley Wickham > wrote: > > > At the top level do: > > > > myenv <- new.env(parent = emptyenv()) > > > > Then in your functions do > > > > myenv$x <- 50 > > myenv$x > > > > etc > > > > You also should not be using data() in that way. Perhaps you want > > R/sysdata.rda. See http://r-pkgs.had.co.nz/data.html for more details. > > > > Hadley > > > > On Tue, Dec 2, 2014 at 2:28 AM, Karim Mezhoud > wrote: > > > Dear All, > > > > > > I am writing a GUIpackage that needs global variables. > > > I had many warning message when I checked the code as for example: > > > geteSet: no visible binding for global variable ‘curselectCases’ > > > I would like to write a function that creates a global place for > Objects > > to > > > be loaded as: > > > > > > > > > Fun <- function(){ > > > > > > Object <- 5 > > > > > > Var2Global <- function(Object){ > > > .myDataEnv <- new.env(parent=emptyenv()) # not exported > > > isLoaded <- function(Object) { > > > exists(Object, .myDataEnv) > > > } > > > getData <- function(Object) { > > > if (!isLoaded(Object)) data(Object, envir=.myDataEnv) > > > .myDataEnv[[Object]] > > > } > > > } > > > > > > } > > > > > > To avoid the use of: Object <<- 5 > > > > > > but it seems not working yet. Object == 5 is not a global variable > after > > > running Fun(). > > > > > > Any Idea? > > > Thanks > > > Ô__ > > > c/ /'_;kmezhoud > > > (*) \(*) ⴽⴰⵔⵉⵎ ⵎⴻⵣⵀⵓⴷ > > > http://bioinformatics.tn/ > > > > > > [[alternative HTML version deleted]] > > > > > > __ > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > https://stat.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > -- > > http://had.co.nz/ > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Output In R
I would suggest that instead of trying to view all the results in the console that you save the result into a object then use the View (note the capitol V) function to be able to scroll through the results. The head and tail functions have already been mentioned and I second their use for a quick view. Since you are already using dplyr you should look at the slice (and possibly filter) function for another way to display pieces of the resulting object. On Tue, Aug 18, 2015 at 6:41 AM, Shivi82 wrote: > Hello All, > > As i am a newbie in R so most of you would have seen this question zillion > times. I searched for the answer on this forum as well on other various > forums however could not find the answer i am looking for. > > I am dplyr package and used a very basic code: > select(june,city,state,mod) > > The data sheet i am using has more than 3 million observations but the > console does not print all of them and show only few options and give a > message: > [ reached getOption("max.print") -- omitted 376341 rows ] > > > What is the option that i need to add to see all values in the output. > Similarly once i scroll down and then if i scroll up i am not able to see > the values starting from row #1. Please suggest > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Output-In-R-tp4711227.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot z=f(x,y) analytically
R has several options for projecting a 3 dimensional plot onto a 2 dimensional plane and plotting the result. Which is best depends on what you want. You mention a function "plot3d" but not which package it comes from. You are more likely to receive prompt and useful help when you do your part of the homework and tell us which package it is from (it is not in the default packages). In fact, with a name like that, there could easily be more than one package with a function of that name and if we tell you how to use the function from a different package than you are using then the "help" will probably be more confusing than helpful. In base R you can use functions like persp, image, and contour (after using a function like outer), the help pages have examples. If you load the lattice package then you can use wireframe, levelplot, or contourplot, again the help pages have examples. The TeachingDemos package has functions rotate.persp and rotate.wireframe that create an interactive interface to the corresponding plots. The help page for the plot3d function in the RGL package (one likely candidate for the function you mentioned) points to the plot3d.function function in the "See Also" section which has examples that you could plug your function into. On Wed, Aug 19, 2015 at 5:47 AM, chappo007 wrote: > Hi, > > I've been led to believe that in R it is possible to produce a 3d > analytical plot of a function. I've been pointed in the direction of > plot3d(), so the command is something like > plot3d(x^2+y^2,(x,-3,3),(y,-3,3)). And a smart person out there is going to > tell me where this syntax comes from (or belongs to), there is also a R > package called MapleSoft ( I believe) which is commercial, and there is > always Mathematica. So is there a R function to plot z=f(x,y) without > obtain or generating data. > > Cheers, > Mike > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Plot-z-f-x-y-analytically-tp4711272.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting over a raster image with control over location and orientation
For base plotting functions (not grid) then you may be interested in the updateusr function in the TeachingDemos package. If you can find the current coordinates of 2 points on the 1st plot (the background image) that are not in the same horizontal or vertical line (use the locator function if nothing else) and you know what you would like the coordinates of the 2 points to be, then you just call updateusr with the current coordinates and the desired coordinates and it resets them for you so that you can add to the current plot with lines or other low level functions. On Fri, Aug 21, 2015 at 8:30 AM, ravi wrote: > Hi,I would like to get some help in plotting over an image. I have a png > image over which I would like to have a plot. I would like to be able to > control the location, area and orientation of the plot on the image. > I have taken help from the following references > :http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Murrell.pdfhttp://stackoverflow.com/questions/12918367/in-r-how-to-plot-with-a-png-as-background > In order to give a reproducible example, I set up my image with the help of > some code from the the first reference above. > > #Setting up the initial example raster image > x <- y <- seq(-4*pi, 4*pi, len=27) > r <- sqrt(outer(x^2, y^2, "+")) > z <- cos(r^2)*exp(-r/6) > image <- (z - min(z))/diff(range(z)) > step <- diff(x)[1] > xrange <- range(x) + c(-step/2, step/2) > yrange <- range(y) + c(-step/2, step/2) > plot(x, y, ann=FALSE,xlim=xrange, ylim=yrange,xaxs="i", yaxs="i") > rasterImage(image,xrange[1], yrange[1],xrange[2], yrange[2],interpolate=FALSE) > > # the explanation of my problem starts here > # First, I want to mark out a particular line > lines(c(10,10.5),c(-10.5,10),col="red",lwd=2) > #In my problem, I have to locate these points graphically from the image > calpoints <- locator(n=2,type='p',pch=4,col='blue',lwd=2) > # this gives the line corresponding to the x-axis for my overlay plot > # I don't want the red line on my plot > #the red line plotted earlier is just to show the example location > newOrigin<-calpoints[1] > xLimit<-calpoints[2]#xlimit marks the limit of the x-axis on the image# on > this new line as the x-axis, I want to make a new plot# the y-axis should be > perpendicular to the x-axis. I would like to be able to specify the width of > coverage over the image#example > xx<-1:10 > yy<-xx^2 > plot(xx,yy,xlim=range(xx),ylim=range(yy),col="blue",type="b",xlab="x",ylab="square > of x") > # I would prefer to have the image more transparent just under the x and y > labels and axis labelsThanks, Ravi > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Calculate the area under a curve
An alternative to your approach is to pass your data to the approxfun or splinefun functions and then use the integrate function on the result. On Mon, Aug 24, 2015 at 3:10 AM, CarstenH wrote: > Hi all > > I need to calculate the area under a curve (integral) for the following data > pairs: > > Depth SOC > 22.50.143 > 28.50.165 > 34.50.131 > 37.50.134 > 40.50.138 > 43.50.107 > 46.50.132 > 49.50.175 > 52.50.087 > 55.50.117 > 58.50.126 > 61.50.13 > 64.50.122 > 67.50.161 > 71.50.144 > 76.50.146 > 82.50.156 > 94.50.132 > > (Table name is P) > > After reading the data set I assiged the collumns by: > > /x <- (P$Depth) > y <- (P$SOC) > / > > and decided to make a ploynominal function (3rd order): > > /fitP <- lm( y~poly(x,3,raw=TRUE) )/ > > At the next step I failed. I can plot point and function but am not able to > integrate the curve between e.g. depths 20 and 80. > > If I try: > / > integrand <-function(fitP1) > predict(y) > integrate(integrand, lower = 25, upper = 80)/ > > the "Conosle" opend with the message: "Source unavailable or out of sync" > and > / > function(fitP1) > predict(y) > / > ) > > > Would be great if somebody could help! > > Thanks > > Carsten > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Calculate-the-area-under-a-curve-tp4711418.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating "Envelope" around a plot
Look at the polylineoffset function in the polyclip package. It looks like it does what you are asking for. On Mon, Nov 2, 2015 at 5:33 AM, WRAY NICHOLAS wrote: > Hi I am plotting various strands of information, and I want to create an > "envelope" around each line, so that the locus of the envelope is the boundary > points no more than a fixed maximum distance from the plotted line, a bit like > drawing a larger rectangle with paralle sides and curved compass corners > around > a smaller rectangle. Obviously I can work out how to do this in code > (eventually) but I suspect it would take me a while and i was wondering > whether > there was some R function which I don't know about which creates sets of of > points at a given maximal distance > > the lines are simple vectors, ie like this noddy example > > veca<-c(4,3,6,5,7,3,2,3,3,6,8,7) > plot(veca,type="l",lwd=2) > > then I want to plot the locus of the boundary of all points no more than > (say) 1 > unit from the line I imagine that one would have to provide a larger set of > interpolated points between the actual points of veca, but I can do that no > problem > > I'd be grateful if anyone out there in the R-ethervoid has any ideas > > Thanks, Nick Wray > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot with pauses?
Here is one option if you don't want to write the explicit for loop (there is still a loop): library(TeachingDemos) v<-0:60 z<-3/5+4i/5 t<-z^(v/9) tmpfun <- function(npoints) { plot( Re(t)[seq_len(npoints)], Im(t)[seq_len(npoints)], xlab="Real", ylab="Imaginary", xlim=c(-1,1), ylim=c(-1,1), asp=1) } tkexamp( tmpfun, list(npoints=list('animate',from=0,to=length(t), resolution=1, delay=500)) ) On Wed, Nov 11, 2015 at 10:30 PM, Judson wrote: > I'm trying to create a > series of demos for students. > > It would be helpful > if plotted data points > could appear one by one > with, say, half-second delays > between points. > > For instance, > code like this > > v<-0:60 > z<-3/5+4i/5 > t<-z^(v/9) > plot(Re(t),Im(t)) > > would be better if I > could invoke some > pausing between points > so the student could see > the progression of > the process. Many > mathematical progressions > might be more understandable > if the viewer could see > this happen over intervals > of time. > > Naturally I'd like to > avoid for loops if that's > possible. > > I really don't know > where to start my > search. Any suggestions? > > . judson blake > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] SWEAVE - a gentle introduction
John, One additional point that I have not seen brought up yet. If your main goal is to have all the output from an existing R script put into a single output file then you should look at the `stitch` function in the knitr package. This will take an existing R script and convert it to one of the formats that knitr can process, then processes it for you without you needing to modify the script or learn any of the markdown (LaTeX or HTML or other). You do not have a lot of control over how the output looks, but it is quick and easy. For the long run I would suggest learning to use the full power of knitr, but stitch (and the related spin function which gives a few more options) is a quick way to process an existing script. On Tue, Nov 17, 2015 at 8:21 AM, John Sorkin wrote: > I am looking for a gentle introduction to SWEAVE, and would appreciate > recommendations. > I have an R program that I want to run and have the output and plots in one > document. I believe this can be accomplished with SWEAVE. Unfortunately I > don't know HTML, but am willing to learn. . . as I said I need a gentle > introduction to SWEAVE. > Thank you, > John > > > > John David Sorkin M.D., Ph.D. > Professor of Medicine > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology and > Geriatric Medicine > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > John David Sorkin M.D., Ph.D. > Professor of Medicine > Chief, Biostatistics and Informatics > University of Maryland School of Medicine Division of Gerontology and > Geriatric Medicine > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > (Phone) 410-605-7119 > (Fax) 410-605-7913 (Please call phone number above prior to faxing) > > Confidentiality Statement: > This email message, including any attachments, is for ...{{dropped:18}} __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] is.na behavior
Richard, I think the reason that this gives the warning is for the rest of us who don't think about asking about missing values in non-data objects. I could imagine someone choosing a poor name for a variable and doing something like: mean <- mean(x) is.na(mean) which would then tell them whether the mean of x was missing (due to missing in x). Later in a new session they may try something similar but use a different variable name in the 1st line (e.g. Mean) but accidentally still ask for is.na(mean). So, is.na would find the mean function and report that it is not missing, but the warning would let the user know that what was checked for missingness was not what they had intended. I could also imagine meaning to write something like: is.na(mean(x)) but accidentially writing is.na(mean) instead and I would appreciate the warning that would send me back to review my code and find the mistake. On Wed, Nov 18, 2015 at 8:03 PM, Richard M. Heiberger wrote: > David, > > Your answer begs the question. > What is the problem with non-(list or vector) of type language. > To my eye both expression(abcd) and call("mean") look like they have > non-missing values, hence I anticipated that they are not NA, and therefore > that is.na() would return FALSE without a warning. > > On the html email, I turned that off years ago. It looks like gmail > (who handles > my university's email accounts) turned it back on. I just turned it off > again. > I too find it very annoying to have to revisit setting changes that I > didn't make. > Thank you for letting me know. > > Rich > > > On Wed, Nov 18, 2015 at 9:36 PM, David Winsemius > wrote: >> >>> On Nov 18, 2015, at 5:54 PM, Richard M. Heiberger wrote: >>> >>> What is the rationale for the following warning in R-3.2.2? >>> >>>> is.na(expression(abcd)) >>> [1] FALSE >>> Warning message: >>> In is.na(expression(abcd)) : >>> is.na() applied to non-(list or vector) of type ‘expression’ >> >> Well, the R interpreter does think that this is not a list: >> >>> is.list(expression(abcd)) >> [1] FALSE >> >> >>> methods(is.na) >> [1] is.na,abIndex-method is.na,denseMatrix-method >> [3] is.na,indMatrix-method is.na,nsparseMatrix-method >> [5] is.na,nsparseVector-method is.na,sparseMatrix-method >> [7] is.na,sparseVector-method is.na.coxph.penalty* >> [9] is.na.data.frame is.na.numeric_version >> [11] is.na.POSIXlt is.na.raster* >> [13] is.na.ratetable* is.na.Surv >> >> >> So the rationale is probably the same as the rationale for this warning: >> >>> is.na(call("mean", 1:4)) >> [1] FALSE FALSE >> Warning message: >> In is.na(call("mean", 1:4)) : >> is.na() applied to non-(list or vector) of type ‘language' >> >>> [[alternative HTML version deleted]] >> >> >> I’m somewhat puzzled at your use of HTML for an Rhelp posting. I thought you >> were a longtime R user? >> >> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >> David Winsemius >> Alameda, CA, USA >> > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] fill the area outside a polygon
Adrian, Draw the polygon once without the border and the whole in it, then go back and draw the border around the outer polygon without any fill. On Wed, Dec 2, 2015 at 9:31 AM, Adrian Dușa wrote: > On Wed, Dec 2, 2015 at 5:19 PM, David L Carlson wrote: >> >> Using only base graphics, one solution would be to embed the inner > polygon in the outer one and turn off the border: >> >> par(mai=c(0, 0, 0, 0)) >> plot(1:100, type="n") >> polygon(c(0, 100, 100, 0, 0, 20, 80, 80, 20, 20, 0), >> c(0, 0, 100, 100, 0, 20, 20, 80, 80, 20, 0), col="lightblue", > border=NA) > > > I see what you did, interesting. > I do need the border though, although if this is the only solution, perhaps > I could live without it. > > It's working on a Windows machine (which I presume you are using), but > under MacOS I only get the entire big polygon filled, including the hole > in the middle. > > Thanks, > Adrian > > -- > Adrian Dusa > University of Bucharest > Romanian Social Data Archive > Soseaua Panduri nr.90 > 050663 Bucharest sector 5 > Romania > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Bezier to line segments
You may also be interested in the xspline function (graphics package, so you don't need to install or load anything extra) since you mention general splines. These splines can be made similar to Bezier curves (but not exactly the same). The function returns a set of coordinates (when draw=FALSE) that represent line segments for drawing the approximate curve. On Wed, Jan 6, 2016 at 6:43 AM, Adrian Dușa wrote: > I just found the package "bezier". > Trying to find the needle, I missed the haystack... > > On Wed, Jan 6, 2016 at 9:56 AM, Adrian Dușa wrote: > >> Dear All, >> >> I am interested into transforming Bezier curves (or general splines) to a >> series of line segments. >> For simplicity, the Bezier curves are either cubic (arches, no inflection >> points) or they have at most one inflection point. >> >> The entry parameters are exactly four points (with x and y coordinates): >> - start point >> - end point >> - and two control points to define the curve. >> >> I read a lot about parabolic approximation, and there is also a famous >> deCasteljau algorithm. >> >> Before attempting to create my own function, I wonder if something like >> this already exists in R (or can easily be adapted to R). >> >> Thanks in advance for any hint, >> Adrian >> >> -- >> Adrian Dusa >> University of Bucharest >> Romanian Social Data Archive >> Soseaua Panduri nr.90 >> 050663 Bucharest sector 5 >> Romania >> > > > > -- > Adrian Dusa > University of Bucharest > Romanian Social Data Archive > Soseaua Panduri nr.90 > 050663 Bucharest sector 5 > Romania > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 output as html or pdf without rstudio
Yes, you can use the knitr package directly (that is what Rstudio uses, but it is its own package). On Fri, Jan 8, 2016 at 1:16 PM, Ragia . wrote: > dear group, > is there a way to write my outputs to any kind of files ( the output contains > text and graph) using R only without installing rstudio and using rmd files. > thanks in advance > Ragia > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Logistic Regression
Do you have the sample sizes that the sample proportions were computed from (e.g. 0.5 could be 1 out of 2 or 100 out of 200)? If you do then you can specify the model with the proportions as the y variable and the corresponding sample sizes as the weights argument to glm. If you only have proportions without an integer sample size then you may want to switch to using beta regression instead of logistic regression. On Sat, Jan 23, 2016 at 1:41 PM, pari hesabi wrote: > Hello everybody, > > I am trying to fit a logistic regression model by using glm() function in R. > My response variable is a sample proportion NOT binary numbers(0,1). > > Regarding glm() function, I receive this error: non integer # successes in a > binomial glm! > > I would appreciate if anybody conducts me. > > > Regards, > > Pari > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Accessing specific data.frame columns within function
You are trying to use shortcuts where shortcuts are not appropriate and having to go a lot longer around than if you did not use the shortcut, see fortune(312). You should really reread the help page: help("[[") and section 6.1 of An Introduction to R. Basically you should be able to do something like: f <- function(data, oldnames) { data <- data[ data[[oldnames[2] ]] == 4, ] data[['d']] <- data[[ oldnames[1] ]]^2 + data[[ oldnames[2] ]] data } Or maybe a little more readable (but not as good a golf score): f <- function(data, oldnames) { aa <- oldnames[1] cc <- oldnames[2] data <- data[ data[[ cc ]] == 4, ] data[['d']] <- data[[ aa ]]^2 + data[[ cc ]] data } I could have used a and c instead of aa and cc, but the doubled letters mean less confusion with the `c` function in R. Also you should read (and heed) the Warning section on the help page for subset (?subset). On Thu, Feb 4, 2016 at 9:13 PM, Clark Kogan wrote: > Hello, > > I am trying to write a function that adds a few columns to a data.frame. The > function uses the columns in a specific way. For instance, it might take a^2 > + c to produce a column d. Or it might do more complex manipulations that I > don't think I need to discuss here. I want to keep x as a data.frame when I > pass it into the function, as I want to use some data.frame functionality on > x. > > Furthermore, I don't want the names in x to have to be specific. I want to > be able to specify which columns the function should treat as "a" and "c". > > The way I am currently doing it, is that I pass the names of the columns > that I want to treat as a and c. > > f <- function(data,oldnames) { > newnames <- c("a","c") > ix <- match(oldnames,names(y)) > names(y)[ix] <- newnames > y <- subset(y,c==4) > y$d <- y$a^2 + y$c > ix <- match(newnames,names(y)) > names(y)[ix] <- oldnames > y > } > > y <- data.frame(k=c(1,1,1),l=c(2,2,5),m=c(4,2,4)) > f(y,c("k","m")) > > The way that I am doing it does not seem all that elegent or standard > practice. My question is: are there potential problems programming with > data.frames in this way, and are their standard practice methods of > referencing data.frame names that deal with these problems? > > Thanks! > > Clark > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Separating point symbols and line types in a legend.
One option is to call `legend` twice and do some manual positioning. This worked for me: plot(1:10) legend('topleft', lty=1:3, bty="n", legend=c('','','') ) legend('topleft', pch=c(20,8,1), bty="n", legend=c('clyde','irving','melvin'), inset=c(0.1,0)) You may need to fiddle with the amount of inset for your particular plot and device combination. On Thu, Feb 11, 2016 at 9:52 PM, Rolf Turner wrote: > > I would like to have a legend given in the manner > > legend("topleft",pch=c(20,8,1),lty=1:3,bty="n", >legend=c("clyde","irving","melvin")) > > but with the point symbol *NOT* being superimposed on the line segments that > are plotted. > > I saw that I can specify "merge=FALSE" in the call to legend() but this > gives results like unto > >* irving > > with the plot symbol being immediately juxtaposed to the plotted line > segment. I would like a space between them, like so: > > * irving > > (See the difference?) > > I can see no arguments to legend that allow me to effect this. I can adjust > positioning of the legend text, but not of the plotted point character or > line segment. Is there any way to effect the desired result? Or is there a > "simple" adjustment that one could make to the code for legend() that would > allow me to accomplish what I want? > > Ta. > > cheers, > > Rolf Turner > > -- > Technical Editor ANZJS > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to create an executable file from R GUI?
To give a full answer we need some more detail from you. For example what operating system are you on? what do you mean by "users click on it"? and at what point do you want them to click (after running R, when looking at the desktop, etc.) But to help get you started you may want to look at the help page `?Startup` which tells you all the things that R does as it starts up and how to have it run commands automatically as it is starting up. I have created some GUI examples in the past that clients then wanted to have on their own computer to play with and demonstrate to others. I usually would install R on their machine for them and create a shortcut on the desktop (these were all MS Windows computers) that pointed to the standard R executable, but started in a specific directory/folder. Then in that folder I created a ".Rprofile" file with the commands to load in the appropriate data and packages and run the gui demonstration. The user could then double click on the shortcut on the desktop and 2 windows would pop up (the regular R interface and my gui demo), I instructed the client to just minimize and ignore the regular R window and they were then able to use my demo and then close everything when they were finished. You could do something similar (but exactly how will differ between Windows, Mac, and Linux computers). On Thu, Feb 18, 2016 at 9:27 AM, simon0098--- via R-help wrote: > Hi, > I've created a GUI using RGtk2 package. How can I make an executable file > from my R script so that users click on it and the GUI appears for them? > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to avoid endless loop in shiny
You need to use `isolate` on one of the assignments so that it does not register as an update. Here are a few lines of code from the server.R file for an example that I use that has a slider for r (correlation) and another slider for r^2 and whenever one is changed, I want the other to update: observe({ updateSliderInput(session, 'r', value=isolate(ifelse(input$r<0,-1,1))*sqrt(input$r2)) }) observe({ updateSliderInput(session, 'r2', value=input$r^2) }) I did end up in a loop once when I happened to choose just the wrong value and the rounding caused a jumping back and forth, but all the other times this has worked perfectly without the endless loop. On Tue, Mar 8, 2016 at 12:35 PM, Michael Peng wrote: > Hi, > > I added two sliderInput into the app with package "shiny": sliderA and > sliderB. The values in the two sliders are correlated. If I change sliderA, > I used updateSliderInput to update the value in sliderB. And also If I > change sliderB, I used updateSliderInput to update the value in slideA. > > The problem is it is an endless loop. How can I use updateSliderInput > without sending message to update the other slider. > > Thank. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] summation involving multiple summations
You can create a list of functions then use subscripting. E.g.: funvec <- c(sin, cos, tan) for(i in 1:3) { print(funvec[[i]](pi/6)) } Just create the list with the different functions that you want to call, then subscript that list with your n_r variable. You can also look at ?switch, but I think the list of functions may work better for you. On Sat, Mar 19, 2016 at 7:17 AM, Mahmoud via R-help wrote: > Dear R Experts > > I've a function which involves multiple summations, and the number of > summations depends on a > random variable named (n-r), where n is known but r is random and r > So, if , for example , n-r=3, the function is: > >>n_r=3 >>fx=function(x)sum(sapply(1:n_r, function(j1) {sum(sapply(1:(j1), >>function(j2){sum(sapply(1:(j2), >>function(j3){(j1>j2)*(j2>j3)/(x+exp(tc[j1]+tc[j2]+tc[j3])^4}))}))}))} > > The value of r will be generated from a simulation process, so in one > iteration r may be equal to 0, and in another iteration it might be equal to > 2 and so on, and accordingly (n-r) is either 1, 2, or 3. And this makes the > body of the summation different every time. > > > Here's my trail code in the simple case when n=3: > > library(nleqslv) > N=100;n=3 > a=matrix(0,nrow=N,ncol=1) > for(i in 1:N){ > tc=matrix(0, nrow=n, ncol=1) > t=matrix(0, nrow=n, ncol=1) > c=matrix(0,nrow=n,ncol=1) > for(j in 1: n){ > t[j]=rexp(1,rate=3) > > c[j]=rexp(1, rate =2) > if (t[j]>=c[j]) {tc[j]=t[j]} > } > n_r=nrow(tc) > if(n_r==1){fx=function(x)sum(sapply(1:n-3, function(j1){1/(x+exp(tc[j1]))^4})) > a[i]=nleqslv(0.5, fx)$x > } > if(n_r==2){fx=function(x)sum(sapply(1:n-2, > function(j1){sum(sapply(1:(j1),function(j2){(j1>j2)/(x+exp(tc[j1]+tc[j2]))^4}))})) > a[i]=nleqslv(0.5, fx)$x > } > if(n_r==3){fx=function(x)sum(sapply(1:n, function(j1) {sum(sapply(1:(j1), > function(j2){sum(sapply(1:(j2), > function(j3){(j1>j2)*(j2>j3)/(x+exp(tc[j1]+tc[j2]+tc[j3]))^4}))}))})) > a[i]=nleqslv(0.5, fx)$x > } > } > > Is there any other way to write a loop that could be executed for any value > of r instead of putting the if () statement for each single value of r , as > n may take large values reaching 30, for instance. > > Any help or recommendation for a reference that can help me would be > appreciated . > Thank you > Mahmoud Farid > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Persistent state in a function?
Boris, You may want to look into the R6 package. This package has tools that help create objects (environments) with methods that can use and change the object. You can have your persistent table stored as part of your object and then create methods that will use and modify the table within the object. On Sat, Mar 19, 2016 at 10:45 AM, Boris Steipe wrote: > Dear all - > > I need to have a function maintain a persistent lookup table of results for > an expensive calculation, a named vector or hash. I know that I can just keep > the table in the global environment. One problem with this approach is that > the function should be able to delete/recalculate the table and I don't like > side-effects in the global environment. This table really should be private. > What I don't know is: > -A- how can I keep the table in an environment that is private to the > function but persistent for the session? > -B- how can I store and reload such table? > -C- most importantly: is that the right strategy to initialize and maintain > state in a function in the first place? > > > For illustration ... > > --- > > myDist <- function(a, b) { > # retrieve or calculate distances > if (!exists("Vals")) { > Vals <<- numeric() # the lookup table for distance values ># here, created in the global env. > } > key <- sprintf("X%d.%d", a, b) > thisDist <- Vals[key] > if (is.na(thisDist)) { # Hasn't been calculated yet ... > cat("Calculating ... ") > thisDist <- sqrt(a^2 + b^2) # calculate with some expensive function > ... > Vals[key] <<- thisDist # store in global table > } > return(thisDist) > } > > > # run this > set.seed(112358) > > for (i in 1:10) { > x <- sample(1:3, 2) > print(sprintf("d(%d, %d) = %f", x[1], x[2], myDist(x[1], x[2]))) > } > > > Thanks! > Boris > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Persistent state in a function?
> > > > > On Mar 23, 2016, at 5:58 PM, Martin Morgan > wrote: > >> Use a local environment to as a place to store state. Update with <<- and >> resolve symbol references through lexical scope E.g., >> >>persist <- local({ >>last <- NULL# initialize >>function(value) { >>if (!missing(value)) >>last <<- value # update with <<- >>last# use >>} >>}) >> >> and in action >> >> > persist("foo") >> [1] "foo" >> > persist() >> [1] "foo" >> > persist("bar") >> [1] "bar" >> > persist() >> [1] "bar" >> >> A variant is to use a 'factory' function >> >>factory <- function(init) { >>stopifnot(!missing(init)) >>last <- init >>function(value) { >>if (!missing(value)) >>last <<- value >>last >>} >>} >> >> and >> >> > p1 = factory("foo") >> > p2 = factory("bar") >> > c(p1(), p2()) >> [1] "foo" "bar" >> > c(p1(), p2("foo")) >> [1] "foo" "foo" >> > c(p1(), p2()) >> [1] "foo" "foo" >> >> The 'bank account' exercise in section 10.7 of RShowDoc("R-intro") >> illustrates this. >> >> Martin >> >> On 03/19/2016 12:45 PM, Boris Steipe wrote: >>> Dear all - >>> >>> I need to have a function maintain a persistent lookup table of results for >>> an expensive calculation, a named vector or hash. I know that I can just >>> keep the table in the global environment. One problem with this approach is >>> that the function should be able to delete/recalculate the table and I >>> don't like side-effects in the global environment. This table really should >>> be private. What I don't know is: >>> -A- how can I keep the table in an environment that is private to the >>> function but persistent for the session? >>> -B- how can I store and reload such table? >>> -C- most importantly: is that the right strategy to initialize and >>> maintain state in a function in the first place? >>> >>> >>> For illustration ... >>> >>> --- >>> >>> myDist <- function(a, b) { >>> # retrieve or calculate distances >>> if (!exists("Vals")) { >>> Vals <<- numeric() # the lookup table for distance values >>># here, created in the global env. >>> } >>> key <- sprintf("X%d.%d", a, b) >>> thisDist <- Vals[key] >>> if (is.na(thisDist)) { # Hasn't been calculated yet ... >>> cat("Calculating ... ") >>> thisDist <- sqrt(a^2 + b^2) # calculate with some expensive >>> function ... >>> Vals[key] <<- thisDist # store in global table >>> } >>> return(thisDist) >>> } >>> >>> >>> # run this >>> set.seed(112358) >>> >>> for (i in 1:10) { >>> x <- sample(1:3, 2) >>> print(sprintf("d(%d, %d) = %f", x[1], x[2], myDist(x[1], x[2]))) >>> } >>> >>> >>> Thanks! >>> Boris >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> >> This email message may contain legally privileged and/or confidential >> information. If you are not the intended recipient(s), or the employee or >> agent responsible for the delivery of this message to the intended >> recipient(s), you are hereby notified that any disclosure, copying, >> distribution, or use of this email message is prohibited. If you have >> received this message in error, please notify the sender immediately by >> e-mail and delete this email message from your computer. Thank you. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] polygon angle option perpendicular to axis
Filling polygons with lines is a throwback to the time when the height of quality graphics was the mechanical pen plotter (a device that used a pen in a mechanical arm to draw the plot on a piece of paper). Computing and printing technology has advanced quite a bit from that day, so you may want to reconsider why you want polygons filled with lines instead of just a solid color (and I consider white, grey, and black as colors for this purpose). On Wed, Apr 27, 2016 at 2:17 PM, Simon, Heather wrote: > I am trying to use the angle option in polygon to create polygons filled with > horizontal and vertical lines. The polygons I am crating are irregular and > it the angle function appears to set the angle of the shading perpendicular > to the polygon sides rather than perpendicular to the axes. Is there any way > to set the angle relative to the axes rather than relative to the polygon > sides? > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] row names, coulmn names
There are some packages that add labels or other attributes (units) to columns of data frames and have methods to display the labels, units, etc. One of these packages is Hmisc, see the label and unit functions. I believe that there are other packages as well. This may provide what the original poster desires. On Sun, May 1, 2016 at 1:55 PM, David Winsemius wrote: > >> On May 1, 2016, at 11:09 AM, Jan Kacaba wrote: >> >> Hello dear R helpers, >> >> Is it possible to have more than 1 row for column names in data.frame, >> array, tbl_df? I would like to have column numbers in the first row, string >> names in the second row, physical unit in third row. > > It's possible to embed "\n" in names but whether that will deliver desired > results with plotting and printing functions may be another matter. You would > always need to quote names, even when using "$". > > >> How would I do it? >> >> Derek >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > David Winsemius > Alameda, CA, USA > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.