Re: [R] Using table to get frequencies of several factors at once
Yes thank you, that worked. -Original Message- From: John Kane [mailto:jrkrid...@inbox.com] Sent: Friday, January 11, 2013 4:23 PM To: Pancho Mulongeni; R help Subject: RE: [R] Using table to get frequencies of several factors at once Does something like this do what you want? It returns a list of tables md - data.frame((matrix(sample(1:5, 100, replace = TRUE),nrow= 10))) str(md) apply(md, 2, table) John Kane Kingston ON Canada -Original Message- From: p.mulong...@namibia.pharmaccess.org Sent: Fri, 11 Jan 2013 11:17:42 + To: r-help@r-project.org Subject: [R] Using table to get frequencies of several factors at once Hi, I have a dataframe with n columns, but I am only looking at five of them. And lots of rows, over 700. So I would like to find frequencies for each of the numeric columns (variables) using the table function. However, is there a fast way to produce a frequency table where the 5 rows represent the 5 numeric variables and the columns refer to the values (levels) of the respective numeric variables, which in this case are 0 and 1. The only way I have figured it out is via a for loop: m-seq(218,222,1) #these are columns of the variables in the larger dataframe tm-m[1:5] #I need this for the for loop l.tm-length(tm) B-matrix(nrow=l.tm,ncol=2) #the matrix to hold the freqs for (p in 1:l.tm) { var.num-m[p] B[p,]-table(DATA[,var.num]) } B [,1] [,2] [1,] 6979 [2,] 512 194 [3,] 604 102 [4,] 7006 [5,] 706 706 So the rows represent my five variables (columns) that occupy columns 218 through 222 in the DATA dataframe. So the second column represents my frequencies of the value 1, which is what I am interested in. The last row has a double entry, because there was only one value, 0, with a freq of 706 and so R duplicated in the two columns, but that's ok, I can just ignore it. So is there are better way to do this? Is there a way to use the so called tapply function? I struggle to understand the help doc for this.function. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks orcas on your desktop! Check it out at http://www.inbox.com/marineaquarium __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] hwo to subtract a child array from the big array?
Actually, I find a method. The function reshape OR array data_5m-array(data,c(5,length(data)/5)) and data_5m[1,] is what I wanted ,but I donot think it is a good method. 2013/1/14 Jeff Newmiller jdnew...@dcn.davis.ca.us ab - AA[(1:10)*10] -- TANG Jie Email: totang...@gmail.com Tel: 0086-2154896104 Shanghai Typhoon Institute,China [[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] Fwd: Help with nonlinear regression
-- Forwarded message -- From: r-help-ow...@r-project.org Date: Mon, Jan 14, 2013 at 12:31 AM Subject: Help with nonlinear regression To: ahmedati...@gmail.com The message's content type was not explicitly allowed -- Forwarded message -- From: Ahmed Attia ahmedati...@gmail.com To: r-help@r-project.org Cc: Date: Mon, 14 Jan 2013 00:31:41 -0800 Subject: Help with nonlinear regression Hi- I have a question about nonlinear regression. *Asymptotic Regression Model** * * below is the equation of the model (Reference the R book page 662)* y = a - b e^-cx when I compensate x with 50 for instance, I get a very high value does not match the graph produced by the same model (Asymptotic regression model). below is the output analysis from R; Formula: GN1 ~ SSasymp(nrate, a, b, c) Parameters: Estimate Std. Error t value Pr(|t|) a 12.8190 0.4407 29.09 8.92e-05 *** b 5.7249 0.2803 20.42 0.000257 *** c -4.6697 0.1703 -27.41 0.000107 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 0.2874 on 3 degrees of freedom Number of iterations to convergence: 0 Achieved convergence tolerance: 7.184e-06 based on these coefficients should y= 12.81 5.72 e4.66x ? the predicted lines indicate that the model works fine, but I do not know how to compensate x in the equation to get y AA -- Ahmed M. Attia Research Assistant Dept. Of SoilCrop Sciences Texas AM University ahmed ahmeda...@zu.edu.eg.at...@ag.tamu.edu Cell phone: 001-979-248-5215 [[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] One sided confidence limits for the regression line
On 01/14/2013 05:19 PM, li li wrote: Hi all, I am trying to plot the one-sided confidence limits for the regression line. It seems it is ok to use predict function to compute the two sided confidence limits. Does any one know a easy way to compute the one sided confidence limits? Essentially just multiply the lack of confidence by 2. E.g. for 95% one-sided confidence use 90% two-sided confidence limits (and choose the limit that you're interested in). E.g.: set.seed(42) x- seq(0,10,length=101) y- 1.5 + 2.5*x + rnorm(101,0,5) fit - lm(y ~ x) pfit - predict(fit,interval=confidence,level=0.90) plot(x,y) lines(x,pfit[,fit]) lines(x,pfit[,upr],col=red) You are then, for any given x value, 95% confident that the true mean of Y lies *below* the corresponding y-value on red curve that was plotted. cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Grabbing Specific Words from Content (basic text mining)
Hi all, Suppose I have a data frame with mixed content (name age and address). a-Name: John Smith Age: 35 Address: 32, street, sub, something b-data.frame(a) 1. The question is I want to extract the name age and address separately from this data frame (containing potentially more people). 2. Also just incase I have to deal with it how would the syntax change if I had Name as opposed to Name: (without the colon). Any thoughts are much appreciated. Thanks, Sachin [[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] The three-dot question
Dear all, Why does not the three-dot accept arguments from the parent environment? I am just confused with this error, can someone give me a hint? rm(list=ls()) testFun - function(a, ...) + { + if(a){ + print(a) + }else + { + print(b) + } + } myTask - function(a) + { + b - 3 + testFun(a, b = b) + } myTask(FALSE) Error in print(b) : object 'b' not found Thanks in advance! Feng -- Feng Li Department of Statistics Stockholm University SE-106 91 Stockholm, Sweden http://feng.li/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Grabbing Specific Words from Content (basic text mining)
Total newb here, but you might want to check out ?grep and ?regmatches as a start. (ways to match and then extract substrings respectively) On Mon, Jan 14, 2013 at 9:30 AM, Sachinthaka Abeywardana sachin.abeyward...@gmail.com wrote: Hi all, Suppose I have a data frame with mixed content (name age and address). a-Name: John Smith Age: 35 Address: 32, street, sub, something b-data.frame(a) 1. The question is I want to extract the name age and address separately from this data frame (containing potentially more people). 2. Also just incase I have to deal with it how would the syntax change if I had Name as opposed to Name: (without the colon). Any thoughts are much appreciated. Thanks, Sachin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] random effects model
Sorry I have corrected the mistakes: BP.stack3 - reshape(Copy.of.BP_2,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long) BP.stack3 head(BP.stack3) tail(BP.stack3) names(BP.stack3)[c(2,3,4,5,6,7)] - c(Sex,MaternalAge,Education,Birthplace,AggScore,IntScore) names(BP.stack3)[1:7] BP.stack3 - transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c(Male,Female)),MaternalAge=factor(MaternalAge,labels=c(39years or less,40-49 years,50 years or older)),Education=factor(Education,labels=c(Primary/special,Started secondary,Completed grade10, Completed grade12, College,University)),Birthplace=factor(Birthplace,labels=c(Australia,Other English-speaking,Other))) str(BP.stack3) table(BP.stack3$Sex) BP.stack3$Sex - factor(BP.stack3$Sex,levels=levels(BP.stack3$Sex)[c(2,1)]) levels(BP.stack3$Sex) BPsub6 - subset(BP.stack3,subset=!(is.na(Sex)| is.na(Education)|is.na (Birthplace)|is.na(Education)|is.na(hibp14)| is.na(hibp21))) summary(BPsub6) BPsub6$Categ[BPsub6$Overweight==1BPsub6$time==1BPsub6$Obese==0] - Overweight14 BPsub6$Categ[BPsub6$Overweight==1BPsub6$time==2BPsub6$Obese==0] - Overweight21 BPsub6$Categ[BPsub6$Obese==1BPsub6$time==1BPsub6$Overweight==0|BPsub6$Obese==1BPsub6$time==1BPsub6$Overweight==1 ] - Obese14 BPsub6$Categ[BPsub6$Obese==0BPsub6$time==1BPsub6$Overweight==0] - Normal14 BPsub6$Categ[BPsub6$Obese==0BPsub6$time==2BPsub6$Overweight==0] - Normal21 BPsub6$Categ[BPsub6$Obese==1BPsub6$time==2BPsub6$Overweight==0|BPsub6$Obese==1BPsub6$time==2BPsub6$Overweight==1] - Obese21 BPsub6$Categ - factor(BPsub6$Categ) BPsub6$time - factor(BPsub6$time) summary(BPsub6$Categ) BPsub7 - subset(BPsub6,subset=!(is.na(Categ))) BPsub7 - BPsub7[order(BPsub7$CODEA),] BPsub7$hibp14 - factor(BPsub7$hibp14) levels(BPsub7$hibp14) levels(BPsub7$Categ) names(BPsub7) head(BPsub7) tail(BPsub7) str(BPsub7) library(gee) BP.gee8 - gee(hibp14~ time*Categ, data=BPsub7,id=CODEA,family=binomial, corstr=exchangeable,na.action=na.omit) summary(BP.gee8) ## Can you try this out please? I am not clear where the defect is with model? One other previous model had no correlation between obese 14 and time. With this one, i cannot find anything wrong as such, but still wont work. Thanks On Mon, Jan 14, 2013 at 10:30 AM, arun kirshna [via R] ml-node+s789695n4655440...@n4.nabble.com wrote: HI, I think I mentioned to you before that when you reshape the columns excluding the response variable, response variable gets repeated (in this case hibp14 or hibp21) and creates the error I run your code, there are obvious problems in the code so I didn't reach up to BP.gee BP_2b-read.csv(BP_2b.csv,sep=\t) BP.stack3 - reshape(BP_2b,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long) BP.stack3 - transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c(Male,Female)),MaternalAge=factor(MaternalAge,labels=c(39years or less,40-49 years,50 years or older)),Education=factor(Education,labels=c(Primary/special,Started secondary,Completed grade10, Completed grade12, College,University)),Birthplace=factor(Birthplace,labels=c(Australia,Other English-speaking,Other))) BP.stack3$Sex - factor(BP.stack3$Sex,levels=levels(BP.stack3$Sex)[c(2,1)]) BP.sub3a - subset(BP.stack3,subset=!(is.na(Sex)| is.na(Education)|is.na (Birthplace)|is.na(Education)|is.na(hibp14)| is.na(hibp21))) nrow(BP.sub3a) #[1] 3364 BP.sub5a - BP.sub3a[order(BP.sub3a$CODEA),] # your code was BP.sub5a - BP.sub3a[order(BP.sub5a$CODEA),] ^ was not defined before #Next line BPsub3$Categ[BPsub6$Overweight==1BPsub3$time==1BPsub3$Obese==0]- Overweight14 #It should be BP.sub3 and what is BPsub6, it was not defined previously. #Error in BPsub3$Categ[BPsub6$Overweight == 1 BPsub3$time == 1 BPsub3$Obese == : #object 'BPsub3' not found A.K. From: Usha Gurunathan [hidden email]http://user/SendEmail.jtp?type=nodenode=4655440i=0 To: arun [hidden email]http://user/SendEmail.jtp?type=nodenode=4655440i=1 Sent: Sunday, January 13, 2013 1:51 AM Subject: Re: [R] random effects model HI AK Thanks a lot for explaining that. 1. With the chi sq. ( in order to find out if the diffce is significant between groups) do I have create a separate excel file and make a dataframe.How do I go about it? I have resent a mail to Jun Yan at a difft email ad( first add.didn't work, mail not delivered). 2. With my previous query ( reg. Obese/Overweight/ Normal at age 14 Vs change of blood pressure status at 21), even though I had compromised without the age-specific regression, but I am still keen to explore why the age-specific regression didn't work despite it looking okay. I have given below the syntax. If you get time, could you kindly look at it and see if it could work by any
Re: [R] The three-dot question
Hi Feng, I'm afraid I don't entirely understansd your question -- the `...` construct only allows you to pass variable numbers of arguments, not to have arbitrary access to the parent frames. You need to manually extract b from the dots inside of testFun. Also, it's quite frowned upon to put ##rm(list = ls())## in your examples: it's the mailing list equivalent of asking a buddy to come over to help you move and then punching him in the face when he tries to lift your sofa. Cheers, Michael On Mon, Jan 14, 2013 at 10:21 AM, Feng Li m...@feng.li wrote: Dear all, Why does not the three-dot accept arguments from the parent environment? I am just confused with this error, can someone give me a hint? rm(list=ls()) testFun - function(a, ...) + { + if(a){ + print(a) + }else + { + print(b) + } + } myTask - function(a) + { + b - 3 + testFun(a, b = b) + } myTask(FALSE) Error in print(b) : object 'b' not found Thanks in advance! Feng -- Feng Li Department of Statistics Stockholm University SE-106 91 Stockholm, Sweden http://feng.li/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] GLM Modelling help needed
So, with R you use object[int,int] to select the rows and columns you want to highlight. ([rows,columns]); what you've done here is asked it to apply to rows 1 to 2 (1:2), across all columns. You'll want [,3:4] to specify two particular columns. I'm not familiar enough with glm itself to provide any further guidance (I'll leave that to other readers) but when it comes to automation, you might want to look at the mapply function (type ?mapply) or the plyr package, particularly ddply (?ddply). With ddply you can (for example) split by year and week, execute a function within ddply on specified variables, and then recombine into one dataset consisting of Year, Week and Relationship. Assuming it works - like I said, not particularly familiar with glm :) On Mon, Jan 14, 2013 at 12:08 AM, bhatmb mansi.bhatna...@alumni.utoronto.ca wrote: Hi Everyone, I am new to R and am figuring my way around it. I am trying to determine the relationship between A B, for each week of the year. My dataset looks like: YearWeekA B 19821 11.3 198.53 19822 14.4309.00 19823 23.2325.49 When i tried to run glm on just the first entry using [1,] i got the error: Error in nmod2$R4.2w[1, ] : incorrect number of dimensions My edited code for glm is: abundmod1-glm(R4.2w~N_4,data=nmod1[1:2,]) Does this code still just use the information from the first week? Also since I have to run it for more than 10 years worth of data for 15 weeks, is there a faster way? Thank you so much in advance! Mansi -- View this message in context: http://r.789695.n4.nabble.com/GLM-Modelling-help-needed-tp4655438.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Grabbing Specific Words from Content (basic text mining)
On Mon, Jan 14, 2013 at 4:30 AM, Sachinthaka Abeywardana sachin.abeyward...@gmail.com wrote: Hi all, Suppose I have a data frame with mixed content (name age and address). a-Name: John Smith Age: 35 Address: 32, street, sub, something b-data.frame(a) 1. The question is I want to extract the name age and address separately from this data frame (containing potentially more people). 2. Also just incase I have to deal with it how would the syntax change if I had Name as opposed to Name: (without the colon). Try this: library(gsubfn) a - Name: John Smith Age: 35 Address: 32, street, sub, something b - data.frame(a) strapplyc(as.character(b$a), Name: (.*) Age: (.*) Address: (.*)) [[1]] [1] John Smith 35 [3] 32, street, sub, something a. - Name John Smith Age 35 Address 32, street, sub, something b. - data.frame(a.) strapplyc(as.character(b.$a.), Name (.*) Age (.*) Address (.*)) [[1]] [1] John Smith 35 [3] 32, street, sub, something -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] random effects model
Hi AK I have been trying to create some plots. All being categorical variables, I am not getting any luck with plots. The few ones that have worked are below: barchart(~table(HiBP)|Obese,data=BP.sub3) ## BP.sub3 is the stacked data without missing values barchart(~table(HiBP)|Overweight,data=BP.sub3) plot(jitter(hibp14,factor=2)~jitter(Obese14,factor=2),col=gray,cex=0.7, data=Copy.of.BP_2) ## Copy.of.BP_2 is the original wide format ## not producing any good plots with mixed models as well. summary(lme.3 - lme(HiBP~time, data=BP.sub3,random=~1|CODEA, na.action=na.omit)) anova(lme.3) head(ranef(lme.3)) print(plot(ranef(lme.3))) ## Thanks for any help. On Mon, Jan 14, 2013 at 4:33 AM, arun smartpink...@yahoo.com wrote: HI, I think I mentioned to you before that when you reshape the columns excluding the response variable, response variable gets repeated (in this case hibp14 or hibp21) and creates the error I run your code, there are obvious problems in the code so I didn't reach up to BP.gee BP_2b-read.csv(BP_2b.csv,sep=\t) BP.stack3 - reshape(BP_2b,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long) BP.stack3 - transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c(Male,Female)),MaternalAge=factor(MaternalAge,labels=c(39years or less,40-49 years,50 years or older)),Education=factor(Education,labels=c(Primary/special,Started secondary,Completed grade10, Completed grade12, College,University)),Birthplace=factor(Birthplace,labels=c(Australia,Other English-speaking,Other))) BP.stack3$Sex - factor(BP.stack3$Sex,levels=levels(BP.stack3$Sex)[c(2,1)]) BP.sub3a - subset(BP.stack3,subset=!(is.na(Sex)| is.na(Education)|is.na (Birthplace)|is.na(Education)|is.na(hibp14)| is.na(hibp21))) nrow(BP.sub3a) #[1] 3364 BP.sub5a - BP.sub3a[order(BP.sub3a$CODEA),] # your code was BP.sub5a - BP.sub3a[order(BP.sub5a$CODEA),] ^ was not defined before #Next line BPsub3$Categ[BPsub6$Overweight==1BPsub3$time==1BPsub3$Obese==0]- Overweight14 #It should be BP.sub3 and what is BPsub6, it was not defined previously. #Error in BPsub3$Categ[BPsub6$Overweight == 1 BPsub3$time == 1 BPsub3$Obese == : #object 'BPsub3' not found A.K. From: Usha Gurunathan usha.nat...@gmail.com To: arun smartpink...@yahoo.com Sent: Sunday, January 13, 2013 1:51 AM Subject: Re: [R] random effects model HI AK Thanks a lot for explaining that. 1. With the chi sq. ( in order to find out if the diffce is significant between groups) do I have create a separate excel file and make a dataframe.How do I go about it? I have resent a mail to Jun Yan at a difft email ad( first add.didn't work, mail not delivered). 2. With my previous query ( reg. Obese/Overweight/ Normal at age 14 Vs change of blood pressure status at 21), even though I had compromised without the age-specific regression, but I am still keen to explore why the age-specific regression didn't work despite it looking okay. I have given below the syntax. If you get time, could you kindly look at it and see if it could work by any chance? Apologies for persisting with this query. BP.stack3 - reshape(Copy.of.BP_2,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long BP.stack3 head(BP.stack3) tail(BP.stack3) names(BP.stack3)[c(2,3,4,5,6,7)] - c(Sex,MaternalAge,Education,Birthplace,AggScore,IntScore) BP.stack3 - transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c(Male,Female)),MaternalAge=factor(MaternalAge,labels=c(39years or less,40-49 years,50 years or older)),Education=factor(Education,labels=c(Primary/special,Started secondary,Completed grade10, Completed grade12, College,University)),Birthplace=factor(Birthplace,labels=c(Australia,Other English-speaking,Other))) table(BP.stack3$Sex) BP.stack3$Sex - factor(BP.stack3$Sex,levels=levels(BP.stack3$Sex)[c(2,1)]) levels(BP.stack3$Sex) BP.sub3a - subset(BP.stack3,subset=!(is.na(Sex)| is.na(Education)|is.na (Birthplace)|is.na(Education)|is.na(hibp14)| is.na(hibp21))) summary(BP.sub3a) BP.sub5a - BP.sub3a[order(BP.sub5a$CODEA),] BPsub3$Categ[BPsub6$Overweight==1BPsub3$time==1BPsub3$Obese==0] - Overweight14 BPsub3$Categ[BPsub6$Overweight==1BPsub3$time==2BPsub3$Obese==0] - Overweight21 BPsub3$Categ[BPsub3$Obese==1BPsub3$time==1BPsub3$Overweight==0|BPsub3$Obese==1BPsub3$time==1BPsub3$Overweight==1 ] - Obese14 BPsub3$Categ[BPsub3$Obese==0BPsub3$time==1BPsub3 BPsub3$Categ[BPsub6$Overweight==1BPsub3$time==1BPsub3$Obese==0] - Overweight14$Overweight==0] - Normal14 BPsub3$Categ[BPsub3$Obese==0BPsub3$time==2BPsub3$Overweight==0] - Normal21 BPsub3$Categ[BPsub3$Obese==1BPsub3$time==2BPsub3$Overweight==0|BPsub3$Obese==1BPsub3$time==2BPsub3$Overweight==1] - Obese21
Re: [R] The three-dot question
Hi Michael, Thanks for the reply. On Mon, 2013-01-14 at 10:33 +, R. Michael Weylandt wrote: Hi Feng, I'm afraid I don't entirely understansd your question -- the `...` construct only allows you to pass variable numbers of arguments, not to have arbitrary access to the parent frames. You need to manually extract b from the dots inside of testFun. Also, it's quite frowned upon to put ##rm(list = ls())## in your examples: it's the mailing list equivalent of asking a buddy to come over to help you move and then punching him in the face when he tries to lift your sofa. The rm line just wants to declare there is no b in the global environment. I did not mean people ought to try it. Also notice that there is in front of the rm. You won't get hurt if you just copy and paste it. If it bites you, the mouse and keyboard did it:) Cheers, Feng Cheers, Michael On Mon, Jan 14, 2013 at 10:21 AM, Feng Li m...@feng.li wrote: Dear all, Why does not the three-dot accept arguments from the parent environment? I am just confused with this error, can someone give me a hint? rm(list=ls()) testFun - function(a, ...) + { + if(a){ + print(a) + }else + { + print(b) + } + } myTask - function(a) + { + b - 3 + testFun(a, b = b) + } myTask(FALSE) Error in print(b) : object 'b' not found Thanks in advance! Feng -- Feng Li Department of Statistics Stockholm University SE-106 91 Stockholm, Sweden http://feng.li/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Feng Li Department of Statistics Stockholm University SE-106 91 Stockholm, Sweden http://feng.li/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to fit a linear model to data by minimizing the mean absolute percent error?
Hi All, I wonder if you can help me with an aparently simple task. I have been searching examples for this without any luck: #Assume x-1:10 #x ranges from 1 to 10. y-x*runif(10)+ 1.5*x #y is a linear function of x with some error. Add uniform error that is scaled to be larger as x values also become larger #error is proportional to x size, this should cause heterocedasticity. #I know there are many methods to deal with heterocedasticity, but in my specific case, I want to use percent regression to minimize the mean absolute #percentual error as opposed to regular regression that deals with the square of the errors. #Question, how to fit a linear model to minimize this error on the data y ~ x above? #Please do not use model-lm(y ~ x) as this will minimize the square of the errors, not the mean absolute percent error Best regards, André Cesta [[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] Does psm::Surv handle interval2 data?
Does Surv in psm handle interval2 data? The argument list seems to indicate it does but I get an error. Thanks, Chris # code library('survival') left - c(1, 3, 5, NA) right -c(2, 3, NA, 4) Surv(left, right, type='interval2') survreg(Surv(left, right, type='interval2') ~ 1) library('rms') Surv(left, right, type='interval2') # error args(Surv) psm(Surv(left, right, type='interval2') ~ 1) # same error (of course) psm(survival::Surv(left, right, type='interval2') ~ 1) # runs # output R version 2.15.2 (2012-10-26) -- Trick or Treat Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-w64-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. library('survival') Loading required package: splines left - c(1, 3, 5, NA) right -c(2, 3, NA, 4) Surv(left, right, type='interval2') [1] [1, 2] 3 5+ 4- survreg(Surv(left, right, type='interval2') ~ 1) Call: survreg(formula = Surv(left, right, type = interval2) ~ 1) Coefficients: (Intercept) 1.317943 Scale= 0.6098782 Loglik(model)= -5.3 Loglik(intercept only)= -5.3 n= 4 library('rms') Loading required package: Hmisc Hmisc library by Frank E Harrell Jr Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview') to see overall documentation. NOTE:Hmisc no longer redefines [.factor to drop unused levels when subsetting. To get the old behavior of Hmisc type dropUnusedLevels(). Attaching package: 'Hmisc' The following object(s) are masked from 'package:survival': untangle.specials The following object(s) are masked from 'package:base': format.pval, round.POSIXt, trunc.POSIXt, units Attaching package: 'rms' The following object(s) are masked from 'package:survival': Surv Surv(left, right, type='interval2') # error Error in Surv(left, right, type = interval2) : argument event is missing, with no default args(Surv) function (time, time2, event, type = c(right, left, interval, counting, interval2), origin = 0) NULL psm(Surv(left, right, type='interval2') ~ 1) # same error (of course) Error in Surv(left, right, type = interval2) : argument event is missing, with no default psm(survival::Surv(left, right, type='interval2') ~ 1) # runs Parametric Survival Model: Weibull Distribution psm(formula = survival::Surv(left, right, type = interval2) ~ 1) Model LikelihoodDiscrimination Ratio Test Indexes Obs4LR chi2 0.00R2 0.000 Events 6d.f. 0g0.000 sigma 0.6099gr 1.000 CoefS.E. Wald Z Pr(|Z|) (Intercept) 1.3179 0.3598 3.66 0.0002 Log(scale) -0.4945 0.5977 -0.83 0.4081 ** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues [[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] Does psm::Surv handle interval2 data?
Chris, Thanks for sending the specifics. It appears that I've let Surv in rms fall behind recent versions of Surv in survival. It will take me a few days to get this fixed. I'll send a follow-up note then. Frank Andrews, Chris wrote Does Surv in psm handle interval2 data? The argument list seems to indicate it does but I get an error. Thanks, Chris # code library('survival') left - c(1, 3, 5, NA) right -c(2, 3, NA, 4) Surv(left, right, type='interval2') survreg(Surv(left, right, type='interval2') ~ 1) library('rms') Surv(left, right, type='interval2') # error args(Surv) psm(Surv(left, right, type='interval2') ~ 1) # same error (of course) psm(survival::Surv(left, right, type='interval2') ~ 1) # runs # output R version 2.15.2 (2012-10-26) -- Trick or Treat Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-w64-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. library('survival') Loading required package: splines left - c(1, 3, 5, NA) right -c(2, 3, NA, 4) Surv(left, right, type='interval2') [1] [1, 2] 3 5+ 4- survreg(Surv(left, right, type='interval2') ~ 1) Call: survreg(formula = Surv(left, right, type = interval2) ~ 1) Coefficients: (Intercept) 1.317943 Scale= 0.6098782 Loglik(model)= -5.3 Loglik(intercept only)= -5.3 n= 4 library('rms') Loading required package: Hmisc Hmisc library by Frank E Harrell Jr Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview') to see overall documentation. NOTE:Hmisc no longer redefines [.factor to drop unused levels when subsetting. To get the old behavior of Hmisc type dropUnusedLevels(). Attaching package: 'Hmisc' The following object(s) are masked from 'package:survival': untangle.specials The following object(s) are masked from 'package:base': format.pval, round.POSIXt, trunc.POSIXt, units Attaching package: 'rms' The following object(s) are masked from 'package:survival': Surv Surv(left, right, type='interval2') # error Error in Surv(left, right, type = interval2) : argument event is missing, with no default args(Surv) function (time, time2, event, type = c(right, left, interval, counting, interval2), origin = 0) NULL psm(Surv(left, right, type='interval2') ~ 1) # same error (of course) Error in Surv(left, right, type = interval2) : argument event is missing, with no default psm(survival::Surv(left, right, type='interval2') ~ 1) # runs Parametric Survival Model: Weibull Distribution psm(formula = survival::Surv(left, right, type = interval2) ~ 1) Model LikelihoodDiscrimination Ratio Test Indexes Obs4LR chi2 0.00R2 0.000 Events 6d.f. 0g0.000 sigma 0.6099gr 1.000 CoefS.E. Wald Z Pr(|Z|) (Intercept) 1.3179 0.3598 3.66 0.0002 Log(scale) -0.4945 0.5977 -0.83 0.4081 ** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues [[alternative HTML version deleted]] __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Does-psm-Surv-handle-interval2-data-tp4655472p4655475.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to fit a linear model to data by minimizing the mean absolute percent error?
Hi All, I wonder if you can help me with an aparently simple task. I have been searching examples for this without any luck: #Assume x-1:10 #x ranges from 1 to 10. y-x*runif(10)+ 1.5*x #y is a linear function of x with some error. Add uniform error that is scaled to be larger as x values also become larger #error is proportional to x size, this should cause heterocedasticity. #I know there are many methods to deal with heterocedasticity, but in my specific case, I want to use percent regression to minimize the mean absolute #percentual error as opposed to regular regression that deals with the square of the errors. #Question, how to fit a linear model to minimize this error on the data y ~ x above? #Please do not use model-lm(y ~ x) as this will minimize the square of the errors, not the mean absolute percent error Best regards, André Cesta __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 three-dot question
Hi: If you want testFun to know about b, then you would have to do b-list(...)$b inside TestFun itself. But the dot dot dot argument is not really for that purpose. The use of dotdotdot is for the case where a function INSIDE testFun has a formal argument named say b. Then you can pass the ... at the top level and the function inside will receive the ... but automatically slurp the b out of the dot dot dot and know about it. Below is an example of the use I'm talking about. It was created by a mentoR when I was trying to understand the dotdotdot concept. hope it helps you. #== Note that f does not directly know about x and g does. That is g knows about x even though f does not know and g got it from f. g - function(x, ...) { cat(g: exists('x') = , exists(x), \n); list(...) } f - function(...) { cat(f: exists('x') = , exists(x), \n); g(...) } f(x = 3, y = 4) f: exists('x') = FALSE g: exists('x') = TRUE $y On Mon, Jan 14, 2013 at 5:21 AM, Feng Li m...@feng.li wrote: Dear all, Why does not the three-dot accept arguments from the parent environment? I am just confused with this error, can someone give me a hint? rm(list=ls()) testFun - function(a, ...) + { + if(a){ + print(a) + }else + { + print(b) + } + } myTask - function(a) + { + b - 3 + testFun(a, b = b) + } myTask(FALSE) Error in print(b) : object 'b' not found Thanks in advance! Feng -- Feng Li Department of Statistics Stockholm University SE-106 91 Stockholm, Sweden http://feng.li/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fwd: Help with nonlinear regression
-- Forwarded message -- From: Ahmed Attia ahmedati...@gmail.com Date: Mon, Jan 14, 2013 at 2:31 AM Subject: Help with nonlinear regression To: r-help@r-project.org Dears- I have a question about nonlinear regression. Asymptotic Regression Model below is the equation of the model (Reference the R book page 662) y = a - b e^-cx when I compensate x with 50 for instance, I get a very high value does not match the graph produced by the same model (Asymptotic regression model). below is the output analysis from R; Formula: GN1 ~ SSasymp(nrate, a, b, c) Parameters: Estimate Std. Error t value Pr(|t|) a 12.8190 0.4407 29.09 8.92e-05 *** b 5.7249 0.2803 20.42 0.000257 *** c -4.6697 0.1703 -27.41 0.000107 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.2874 on 3 degrees of freedom Number of iterations to convergence: 0 Achieved convergence tolerance: 7.184e-06 based on these coefficients should y= 12.81 – 5.72 e4.66x ? the predicted lines indicate that the model works fine, but I do not know how to compensate x in the equation to get y AA -- Ahmed M. Attia Research Assistant Dept. Of SoilCrop Sciences Texas AM University ahmed.at...@ag.tamu.edu Cell phone: 001-979-248-5215 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 three-dot question
On 13-01-14 6:34 AM, Feng Li wrote: Hi Michael, Thanks for the reply. On Mon, 2013-01-14 at 10:33 +, R. Michael Weylandt wrote: Hi Feng, I'm afraid I don't entirely understansd your question -- the `...` construct only allows you to pass variable numbers of arguments, not to have arbitrary access to the parent frames. You need to manually extract b from the dots inside of testFun. Also, it's quite frowned upon to put ##rm(list = ls())## in your examples: it's the mailing list equivalent of asking a buddy to come over to help you move and then punching him in the face when he tries to lift your sofa. The rm line just wants to declare there is no b in the global environment. I did not mean people ought to try it. Also notice that there is in front of the rm. You won't get hurt if you just copy and paste it. If it bites you, the mouse and keyboard did it:) If you are using a smart GUI, it will give you the option of pasting just the commands, so there's a reasonable risk of executing the rm(). On the other hand, users should always start with an empty workspace, so it's not so much a punch in the face as a minor annoyance. Duncan Murdoch Cheers, Feng Cheers, Michael On Mon, Jan 14, 2013 at 10:21 AM, Feng Li m...@feng.li wrote: Dear all, Why does not the three-dot accept arguments from the parent environment? I am just confused with this error, can someone give me a hint? rm(list=ls()) testFun - function(a, ...) + { + if(a){ + print(a) + }else + { + print(b) + } + } myTask - function(a) + { + b - 3 + testFun(a, b = b) + } myTask(FALSE) Error in print(b) : object 'b' not found Thanks in advance! Feng -- Feng Li Department of Statistics Stockholm University SE-106 91 Stockholm, Sweden http://feng.li/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ginv / LAPACK-SVD causes R to segfault on a large matrix.
Dear R-help list members, I am hoping to get you help in reproducing a problem I am having That is only reproducible on a large-memory machine. Whenever I run the following lines, get a segfault listed below: *** caught segfault *** address 0x7f092cc46e40, cause 'invalid permissions' Traceback: 1: La.svd(x, nu, nv) 2: svd(X) 3: ginv(bigmatrix) Here is the code that I run: require(MASS) l=3 w=3 x=rpois(l*w,0.00126) bigmatrix=matrix(x,nrow=l,ncol=w) inverted=ginv(bigmatrix) I have tried this both with OMP_NUM_THREADS=1 and greater than 1, and the resulting is always a segfault. The max memory used in around 40G. I am running this on a machine with 128Gb of RAM. I have also done tests with 15,000x15,000 matrices, and they do not cause any segfaults, so I think the problem is related to the size of the input to the La.svd function. I have also tried this with a less sparse matrix, but again, no change in the outcome. I have submitted the bug report to the R bugzilla site ( https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15163), but I wanted to see if anyone on the r-help list has hit this problem before, or can reproduce it, and if there is a solution out there. My web searches have turned up nothing. It appears that R uses a modified version of LAPACK 3.1, and the latest version of LAPACK is 3.4.2. Is that important? Thanks so much for your help, Cyrus PS: Here is my SessionInfo: (I am using ubuntu). R version 2.15.2 (2012-10-26) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] MASS_7.3-22 Matrix_1.0-10 lattice_0.20-10 Rcpp_0.10.2 [5] devtools_0.8 loaded via a namespace (and not attached): [1] compiler_2.15.2 digest_0.6.0evaluate_0.4.3 grid_2.15.2 [5] httr_0.2memoise_0.1 parallel_2.15.2 RCurl_1.95-3 [9] stringr_0.6.2 tools_2.15.2whisker_0.1 [[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] Grabbing Specific Words from Content (basic text mining)
Hello, Suppose I have a data frame with mixed content (name age and address). a-Name: John Smith Age: 35 Address: 32, street, sub, something b-data.frame(a) Since it is dataframe, assumption is you stored data in the columns as Name, Age, Address, sub etc. 1. The question is I want to extract the name age and address separately from this data frame (containing potentially more people). a$Name will extract all data in the column Name similarly for other information. Which you can assign to other variable. 2. Also just incase I have to deal with it how would the syntax change if I had Name as opposed to Name: (without the colon). One can handle slightly different words with agrep command. How ever, your situation can be different. May be this is what you can use to proceed further. You can use agrep command with option max.distance to extract or handle agrep(name,f,max.distance=0.1) or Name|Name: may work in your situation. -- Manjusha S. Joshi blog:http://manjushajoshi.wordpress.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] sqldf package: using variables in where condition
Sent from my iPhone On Jan 13, 2013, at 9:47 PM, ravsre ravishre...@hotmail.com wrote: I am trying to use the sqldf package to create independent data frames from a master dataframe. I want to use sqldf package and perform a simple select statement. However, what I want to do is to create a loop and repeatedly send a variable to the where clause condition such as a: select * from mydfrm where Symbol = list[i] The 'list' is another data frame with a single column with 15 values. All I what to do is to create loop for i in 1:15 and pass on into the select statement as list[1], list[2 }..tile list[15] Can someone help since, I am unable to reference the element location as variable in the sqldf function? also, is there a better way? would appreciate your help Rgds, Ravi -- View this message in context: http://r.789695.n4.nabble.com/sqldf-package-using-variables-in-where-condition-tp4655445.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] putting data.frame values in new dataframes
I have a very dataset which I want to put in new dataframes according to date. Example: Suppose I have number day month hours 1 1 1410 2 2 2 141012 3 3 141018 4 4 1510 3 5 5 151014 6 6 161018 7 7 161020 8 8 161023 9 9 2010 1 10 10 211014 11 11 211015 Now I want to get 5 new data frames, with first one number day month hours 1 1 1410 2 2 2 141012 3 3 141018 etc. Is there an efficient way to do this? Thanks for the help -- View this message in context: http://r.789695.n4.nabble.com/putting-data-frame-values-in-new-dataframes-tp4655474.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ginv / LAPACK-SVD causes R to segfault on a large matrix.
On 14 January 2013 15:08, Cyrus Shaoul cyrus.sha...@uni-tuebingen.de wrote: La.svd Dear Cyrus, Have you tried running La.svd ; LAPACK only version (without R) via C/C++ or Fortran code? After all it can be a LAPACK issue and R-team has no control on that. Best, -m __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] readJPEG function cannot open jpeg files
I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[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] Grabbing Specific Words from Content (basic text mining)
HI, YOu could do either: Lines-readLines(textConnection(Name: John Smith Age: 35 Address: 32, street, sub, something Name Adam Grey Age: 25 Address: 26, street, sub, something)) Lines[-grep(Name\\:,Lines)]-gsub(Name,Name:,Lines[-grep(Name\\:,Lines)]) Name-gsub(Name\\: (.*) Age\\: (.*) Address\\: (.*),\\1,Lines) age-gsub(Name\\: (.*) Age\\: (.*) Address\\: (.*),\\2,Lines) Address-gsub(Name\\: (.*) Age\\: (.*) Address\\: (.*),\\3,Lines) dat1-data.frame(Name,age,Address,stringsAsFactors=FALSE) dat1 dat1 # Name age Address #1 John Smith 35 32, street, sub, something #2 Adam Grey 25 26, street, sub, something #or Lines[-grep(Name\\:,Lines)]-gsub(Name,Name:,Lines[-grep(Name\\:,Lines)]) res-read.table(text=gsub(Name|Age|Address,,Lines),sep=:,stringsAsFactors=F)[-1] res[sapply(res,is.character)]-do.call(cbind,lapply(res[sapply(res,is.character)],function(x) sub(^[[:space:]]*(.*?)[[:space:]]*$,\\1,x))) str(res) #'data.frame': 2 obs. of 3 variables: # $ V2: chr John Smith Adam Grey # $ V3: num 35 25 # $ V4: chr 32, street, sub, something 26, street, sub, something A.K. - Original Message - From: Sachinthaka Abeywardana sachin.abeyward...@gmail.com To: r-help@r-project.org r-help@r-project.org Cc: Sent: Monday, January 14, 2013 4:30 AM Subject: [R] Grabbing Specific Words from Content (basic text mining) Hi all, Suppose I have a data frame with mixed content (name age and address). a-Name: John Smith Age: 35 Address: 32, street, sub, something b-data.frame(a) 1. The question is I want to extract the name age and address separately from this data frame (containing potentially more people). 2. Also just incase I have to deal with it how would the syntax change if I had Name as opposed to Name: (without the colon). Any thoughts are much appreciated. Thanks, Sachin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] putting data.frame values in new dataframes
thank you very much, I have a smaller question: If I give the first dataframe a name, say data1. How can I read it without pasting the dataframe -- View this message in context: http://r.789695.n4.nabble.com/putting-data-frame-values-in-new-dataframes-tp4655474p4655482.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] The three-dot question
That makes sense. Thanks! Feng On Mon, 2013-01-14 at 09:09 -0500, Mark Leeds wrote: Hi: If you want testFun to know about b, then you would have to do b-list(...)$b inside TestFun itself. But the dot dot dot argument is not really for that purpose. The use of dotdotdot is for the case where a function INSIDE testFun has a formal argument named say b. Then you can pass the ... at the top level and the function inside will receive the ... but automatically slurp the b out of the dot dot dot and know about it. Below is an example of the use I'm talking about. It was created by a mentoR when I was trying to understand the dotdotdot concept. hope it helps you. #== Note that f does not directly know about x and g does. That is g knows about x even though f does not know and g got it from f. g - function(x, ...) { cat(g: exists('x') = , exists(x), \n); list(...) } f - function(...) { cat(f: exists('x') = , exists(x), \n); g(...) } f(x = 3, y = 4) f: exists('x') = FALSE g: exists('x') = TRUE $y On Mon, Jan 14, 2013 at 5:21 AM, Feng Li m...@feng.li wrote: Dear all, Why does not the three-dot accept arguments from the parent environment? I am just confused with this error, can someone give me a hint? rm(list=ls()) testFun - function(a, ...) + { + if(a){ + print(a) + }else + { + print(b) + } + } myTask - function(a) + { + b - 3 + testFun(a, b = b) + } myTask(FALSE) Error in print(b) : object 'b' not found Thanks in advance! Feng -- Feng Li Department of Statistics Stockholm University SE-106 91 Stockholm, Sweden http://feng.li/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Feng Li Department of Statistics Stockholm University SE-106 91 Stockholm, Sweden http://feng.li/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] sqldf package: using variables in where condition
On Mon, Jan 14, 2013 at 8:36 AM, Ravi Sreedhar ravishre...@hotmail.com wrote: Sent from my iPhone On Jan 13, 2013, at 9:47 PM, ravsre ravishre...@hotmail.com wrote: I am trying to use the sqldf package to create independent data frames from a master dataframe. I want to use sqldf package and perform a simple select statement. However, what I want to do is to create a loop and repeatedly send a variable to the where clause condition such as a: select * from mydfrm where Symbol = list[i] The 'list' is another data frame with a single column with 15 values. All I what to do is to create loop for i in 1:15 and pass on into the select statement as list[1], list[2 }..tile list[15] Can someone help since, I am unable to reference the element location as variable in the sqldf function? See Example 5 on the sqldf home page. http://code.google.com/p/sqldf/#Example_5._Insert_Variables -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] putting data.frame values in new dataframes
Perhaps split(mydf, paste(mydf$month,mydf$day)) -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/14/13 5:57 AM, condor radonniko...@hotmail.nl wrote: I have a very dataset which I want to put in new dataframes according to date. Example: Suppose I have number day month hours 1 1 1410 2 2 2 141012 3 3 141018 4 4 1510 3 5 5 151014 6 6 161018 7 7 161020 8 8 161023 9 9 2010 1 10 10 211014 11 11 211015 Now I want to get 5 new data frames, with first one number day month hours 1 1 1410 2 2 2 141012 3 3 141018 etc. Is there an efficient way to do this? Thanks for the help -- View this message in context: http://r.789695.n4.nabble.com/putting-data-frame-values-in-new-dataframes- tp4655474.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to fit a linear model to data by minimizing the mean absolute percent error?
Take the logs of both side and minimize the absolute error on the log scale, then transform your results back. The quantreg package does L1 regression. If you want to know **why**, this works, consult a local statistician or post to a statistical list like stats.stackexchange.com. This is not an R question. --- Bert On Mon, Jan 14, 2013 at 4:22 AM, Andre Cesta aace...@yahoo.com wrote: Hi All, I wonder if you can help me with an aparently simple task. I have been searching examples for this without any luck: #Assume x-1:10 #x ranges from 1 to 10. y-x*runif(10)+ 1.5*x #y is a linear function of x with some error. Add uniform error that is scaled to be larger as x values also become larger #error is proportional to x size, this should cause heterocedasticity. #I know there are many methods to deal with heterocedasticity, but in my specific case, I want to use percent regression to minimize the mean absolute #percentual error as opposed to regular regression that deals with the square of the errors. #Question, how to fit a linear model to minimize this error on the data y ~ x above? #Please do not use model-lm(y ~ x) as this will minimize the square of the errors, not the mean absolute percent error Best regards, André Cesta [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Course: Introduction to zero inflated models and GLMM
We would like to announce the following statistics course: Introduction to zero inflated models and GLMM 13 - 16 May 2013. Elche, Spain. For details, see: http://www.highstat.com/statscourse.htm Course flyer: http://www.highstat.com/Courses/Flyer2013_05Elche_ZIP.pdf Kind regards, Alain Zuur -- Dr. Alain F. Zuur First author of: 1. Analysing Ecological Data (2007). Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p. URL: www.springer.com/0-387-45967-7 2. Mixed effects models and extensions in ecology with R. (2009). Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer. http://www.springer.com/life+sci/ecology/book/978-0-387-87457-9 3. A Beginner's Guide to R (2009). Zuur, AF, Ieno, EN, Meesters, EHWG. Springer http://www.springer.com/statistics/computational/book/978-0-387-93836-3 4. Zero Inflated Models and Generalized Linear Mixed Models with R. (2012) Zuur, Saveliev, Ieno. http://www.highstat.com/book4.htm Other books: http://www.highstat.com/books.htm Statistical consultancy, courses, data analysis and software Highland Statistics Ltd. 6 Laverock road UK - AB41 6FN Newburgh Tel: 0044 1358 788177 Email: highs...@highstat.com URL: www.highstat.com URL: www.brodgar.com -- Dr. Alain F. Zuur First author of: 1. Analysing Ecological Data (2007). Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p. URL: www.springer.com/0-387-45967-7 2. Mixed effects models and extensions in ecology with R. (2009). Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer. http://www.springer.com/life+sci/ecology/book/978-0-387-87457-9 3. A Beginner's Guide to R (2009). Zuur, AF, Ieno, EN, Meesters, EHWG. Springer http://www.springer.com/statistics/computational/book/978-0-387-93836-3 4. Zero Inflated Models and Generalized Linear Mixed Models with R. (2012) Zuur, Saveliev, Ieno. http://www.highstat.com/book4.htm Other books: http://www.highstat.com/books.htm Statistical consultancy, courses, data analysis and software Highland Statistics Ltd. 6 Laverock road UK - AB41 6FN Newburgh Tel: 0044 1358 788177 Email: highs...@highstat.com URL: www.highstat.com URL: www.brodgar.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 fit a linear model to data by minimizing the mean absolute percent error?
It doesn't look like you have read the Posting Guide (see bottom of email). This not a homework help forum. Please use the assistance provided by your educational institution. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Andre Cesta aace...@yahoo.com wrote: Hi All, I wonder if you can help me with an aparently simple task. I have been searching examples for this without any luck: #Assume x-1:10 #x ranges from 1 to 10. y-x*runif(10)+ 1.5*x #y is a linear function of x with some error. Add uniform error that is scaled to be larger as x values also become larger #error is proportional to x size, this should cause heterocedasticity. #I know there are many methods to deal with heterocedasticity, but in my specific case, I want to use percent regression to minimize the mean absolute #percentual error as opposed to regular regression that deals with the square of the errors. #Question, how to fit a linear model to minimize this error on the data y ~ x above? #Please do not use model-lm(y ~ x) as this will minimize the square of the errors, not the mean absolute percent error Best regards, André Cesta __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] readJPEG function cannot open jpeg files
Similar issue with URLs: yesWeCan - http://upload.wikimedia.org/wikipedia/commons/9/9d/Barack_Obama.jpg; url(yesWeCan) description http://upload.wikimedia.org/wikipedia/commons/9/9d/Barack_Obama.jpg; class url mode r text text opened closed can read yes can write no readJPEG(yesWeCan) Error in readJPEG(yesWeCan) : unable to open http://upload.wikimedia.org/wikipedia/commons/9/9d/Barack_Obama.jpg On 14 January 2013 14:57, Yi Yuan lamban...@gmail.com wrote: I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] readJPEG function cannot open jpeg files
Being unable to open a file is a related to your operating system and how R interacts with that OS. If your interactive development environment (IDE, of which RStudio is an example) is trying to make things simpler for you but you don't understand how to use it, then you need to ask help from your RStudio support resources, not here. When posting here, you should mention your results from using base R functions like ?sessionInfo ?getwd ?list.files as indicated in the Posting Guide mentioned at the bottom of every R-help email. Consistent with the fact that this is an interface issue between R and the OS, sometimes you will have to investigate the problem from outside R. For example, you might need to investigate issues with security permissions that are OS specific and completely outside the scope of this forum. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Yi Yuan lamban...@gmail.com wrote: I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to open grib file in R?
I have this https://echange-fichiers.inra.fr/get?k=6TdTdezNeZwAqJtpwVm grib file which is a regular lat-lon 0.25x0.25 degrees and contains 4 fields . I tried to open it using : grib - readGDAL(C:\\Users\\aalyaari\\Desktop\\Vol_025_H14_2010060700.grib) but I got this error: C:\Users\aalyaari\Desktop\Vol_025_H14_2010060700.grib has GDAL driver GRIB and has 721 rows and 1440 columns Error in validityMethod(as(object, superClass)) : Geographical CRS given to non-conformant data: -90.125 90.125 Any idea why I am getting this error? -- View this message in context: http://r.789695.n4.nabble.com/How-to-open-grib-file-in-R-tp4655497.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] readJPEG function cannot open jpeg files
You can use file.info(myFile) to make sure the file exists and has appropriate permissions (mode in file.info's lingo, as in Unix). E.g., file.info(c:/temp/BO.jpeg) # this one does not exist size isdir mode mtime ctime atime exe c:/temp/BO.jpeg NANA NA NA NA NA NA file.info(c:/temp/BO.jpg) # this one exists size isdir mode mtime ctime atime c:/temp/BO.jpg 150536 FALSE 666 2013-01-14 08:35:32 2013-01-14 08:33:09 2013-01-14 08:33:09 exe c:/temp/BO.jpg no I can readJPEG() the file with mode 666, but not all permission information is encoded in the mode. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Monday, January 14, 2013 8:25 AM To: Yi Yuan; r-help@r-project.org Subject: Re: [R] readJPEG function cannot open jpeg files Being unable to open a file is a related to your operating system and how R interacts with that OS. If your interactive development environment (IDE, of which RStudio is an example) is trying to make things simpler for you but you don't understand how to use it, then you need to ask help from your RStudio support resources, not here. When posting here, you should mention your results from using base R functions like ?sessionInfo ?getwd ?list.files as indicated in the Posting Guide mentioned at the bottom of every R-help email. Consistent with the fact that this is an interface issue between R and the OS, sometimes you will have to investigate the problem from outside R. For example, you might need to investigate issues with security permissions that are OS specific and completely outside the scope of this forum. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Yi Yuan lamban...@gmail.com wrote: I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to open grib file in R?
On Mon, Jan 14, 2013 at 4:36 PM, Jonsson amen.alya...@bordeaux.inra.fr wrote: but I got this error: C:\Users\aalyaari\Desktop\Vol_025_H14_2010060700.grib has GDAL driver GRIB and has 721 rows and 1440 columns Error in validityMethod(as(object, superClass)) : Geographical CRS given to non-conformant data: -90.125 90.125 Any idea why I am getting this error? At a guess, and this is just a guess, I'd say the system tried to give a Geographical CRS to non-conformant data... So, what's a Geographical CRS? One with latitude and longitude. What's non-conformant data? Data that can't conform to latitude and longitude. Why is -90.125 not conformable to latitude-longitude? Because it's further south than the south pole. Why have you got data that goes further south than the south pole and further north than the north pole? I don't know. I suspect you have points at the poles and the software thinks these are grid cells that are 0.250 lat-long degrees wide. Ask your source. For what its worth, the raster package will ignore the error, but reveals another: g=raster(Vol_025_H14_2010060700.grib) Warning: Inside GRIB2Inventory, Message # 5 ERROR: Ran out of file reading SECT0 There were 76 trailing bytes in the file. g class : RasterLayer band: 1 dimensions : 721, 1440, 1038240 (nrow, ncol, ncell) resolution : 0.25, 0.25 (x, y) extent : -0.125, 359.875, -90.125, 90.125 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +a=6367470 +b=6367470 +no_defs data source : /nobackup/rowlings/Downloads/Vol_025_H14_2010060700.grib names : Vol_025_H14_2010060700 I suspect there's an off-by-one error in the code that created this. Remember there are only three possible mistakes in computing - off by one errors and divide by zero errors. Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 open grib file in R?
Your question should have been posted to the R-sig-geo mailing list. FWIW I have no direct experience with the files or functions you are using, but I have to say the error message seems pretty clear to me: latitude values are normally limited to [-90,90], but your file appears to have data outside this range. Thus, the file appears to have invalid data. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Jonsson amen.alya...@bordeaux.inra.fr wrote: I have this https://echange-fichiers.inra.fr/get?k=6TdTdezNeZwAqJtpwVm grib file which is a regular lat-lon 0.25x0.25 degrees and contains 4 fields . I tried to open it using : grib - readGDAL(C:\\Users\\aalyaari\\Desktop\\Vol_025_H14_2010060700.grib) but I got this error: C:\Users\aalyaari\Desktop\Vol_025_H14_2010060700.grib has GDAL driver GRIB and has 721 rows and 1440 columns Error in validityMethod(as(object, superClass)) : Geographical CRS given to non-conformant data: -90.125 90.125 Any idea why I am getting this error? -- View this message in context: http://r.789695.n4.nabble.com/How-to-open-grib-file-in-R-tp4655497.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Tukey HSD plot with lines indicating (non-)significance
Dear list members, I'm running some tests looking at differences between means for various levels of a factor, using Tukey's HSD method. I would like to plot the data as boxplots or dotplots, with horizontal significance lines indicating which groups are statistically significantly different, according to Tukey HSD. Here's a nice image showing an example of such a graphical display: http://www.biomedcentral.com/1471-2148/11/99/figure/F2 Is there a R function for this? I have tried searching, and found several nice plotting fuctions for Tukey's HSD, but they all either hide the actual data, or display the results only with letters indicating (non-)signifiance. Examples: # Fit an one-way ANOVA. library(DAAG) l=aov(ShootDryMass ~ trt, data=rice) summary(l) # Calculate the Tukey HSD tests and CIs. # The plot shows all 6*5/2 = 15 confidence intervals, # but not the data or the actual group means. l.hsd=TukeyHSD(l, trt, ordered = TRUE) l.hsd plot(l.hsd) # I rather like this one. It shows the group means in a nice way, # but hides the data. And checking which groups are different # isn't always easy (e.g., for NH4Cl - NH4NO3), as one # has to compare differences to a non-aligned scale (bar). onewayPlot(l) # One function that gives a results closer to what I want, # is the compact letter display (CLD) of the multcomp package. # This shows boxplots (but it is easy to overlay the actual # observations, using the points() function) and uses letters # to indicate non-significance. # # (Note that (if I have understood everything correctly) this # doesn't actually calculcate Tukey HSD values (the Tukey # in the glht() call only selects Tukey *contrasts*), but # the results should be *very* similar.) library(multcomp) l.glht=glht(l, linfct = mcp(trt = Tukey)) summary(l.glht) l.cld=cld(l.glht) old.par - par( mai=c(1,1,2,1)) plot(l.cld) par(old.par) # Basically, I want a similar display as the one above (or # preferably a ggplot2- or lattice-based one), but with lines # instead of letters. Of course, for this, the levels need to be # reordered by group means, and it is only guaranteed to # work for balanced data. Example, with the lines missing: library(ggplot2) d=rice d$trt=reorder(d$trt, -d$ShootDryMass) ggplot(d, aes(x=trt, y=ShootDryMass)) + geom_boxplot(outlier.colour=NA) + geom_jitter(col=red, size=3, position=position_jitter(width=.1)) Is there such a function available in R? -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] readJPEG function cannot open jpeg files
On 14/01/2013 16:26, Suzen, Mehmet wrote: Similar issue with URLs: Not a similar issue at all: a URL is not a file. That most functions in R itself open connections including URLs does not mean that contributed packages do. The package help is quite specific about its requirements. source: Either name of the file to read from or a raw vector representing the JPEG file content. Which suggests to you how you can do this, apart from download.file, of course. Something like readJPEG(readBin(yesWeCan, raw, 1e6)) yesWeCan - http://upload.wikimedia.org/wikipedia/commons/9/9d/Barack_Obama.jpg; url(yesWeCan) description http://upload.wikimedia.org/wikipedia/commons/9/9d/Barack_Obama.jpg; class url mode r text text opened closed can read yes can write no readJPEG(yesWeCan) Error in readJPEG(yesWeCan) : unable to open http://upload.wikimedia.org/wikipedia/commons/9/9d/Barack_Obama.jpg On 14 January 2013 14:57, Yi Yuan lamban...@gmail.com wrote: I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] putting data.frame values in new dataframes
Hi, Do you want to read it from a saved file? res-split(dat1,dat1$day) res[[1]] names(res)-paste(data,1:5,sep=) write.table(res[[1]],file=data1.txt) read.table(data1.txt,sep=,header=TRUE) # number day month hours #1 1 14 10 2 #2 2 14 10 12 #3 3 14 10 18 A.K. - Original Message - From: condor radonniko...@hotmail.nl To: r-help@r-project.org Cc: Sent: Monday, January 14, 2013 9:55 AM Subject: Re: [R] putting data.frame values in new dataframes thank you very much, I have a smaller question: If I give the first dataframe a name, say data1. How can I read it without pasting the dataframe -- View this message in context: http://r.789695.n4.nabble.com/putting-data-frame-values-in-new-dataframes-tp4655474p4655482.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ginv / LAPACK-SVD causes R to segfault on a large matrix.
No, Mehmet, I haven't tried that yet. I was hoping to find out if there was some other option. I have no experience using LAPACK directly. I have looked into RcppEigen and RcppArmadillo, but have not tested them yet. If there are no other options, I guess I will go down that path. Thanks a lot, Cyrus On Mon, Jan 14, 2013 at 4:17 PM, Suzen, Mehmet msu...@gmail.com wrote: On 14 January 2013 15:08, Cyrus Shaoul cyrus.sha...@uni-tuebingen.de wrote: La.svd Dear Cyrus, Have you tried running La.svd ; LAPACK only version (without R) via C/C++ or Fortran code? After all it can be a LAPACK issue and R-team has no control on that. Best, -m -- Cyrus Shaoul, PhD http://www.sfs.uni-tuebingen.de/~cshaoul/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to fit a linear model to data by minimizing the mean absolute percent error?
Hi Bert, Thanks for your reply. Your recommendation seems to minimize the error transformed with log, but not the percent error, that is, the model error divided by the observed value (for each observation). I need to minimize the percent error. With log, there could be a very large observation, with a very large error and even with log it would be larger than other errors and have more influence in the regression. But if I take the percent error to minimize, this observation with large error would not have a larger influence. Best regards, André From: Bert Gunter gunter.ber...@gene.com To: Andre Cesta aace...@yahoo.com Cc: r-help@r-project.org r-help@r-project.org Sent: Monday, 14 January 2013, 13:34 Subject: Re: [R] How to fit a linear model to data by minimizing the mean absolute percent error? Take the logs of both side and minimize the absolute error on the log scale, then transform your results back. The quantreg package does L1 regression. If you want to know **why**, this works, consult a local statistician or post to a statistical list like stats.stackexchange.com. This is not an R question. --- Bert On Mon, Jan 14, 2013 at 4:22 AM, Andre Cesta aace...@yahoo.com wrote: Hi All, I wonder if you can help me with an aparently simple task. I have been searching examples for this without any luck: #Assume x-1:10 #x ranges from 1 to 10. y-x*runif(10)+ 1.5*x #y is a linear function of x with some error. Add uniform error that is scaled to be larger as x values also become larger #error is proportional to x size, this should cause heterocedasticity. #I know there are many methods to deal with heterocedasticity, but in my specific case, I want to use percent regression to minimize the mean absolute #percentual error as opposed to regular regression that deals with the square of the errors. #Question, how to fit a linear model to minimize this error on the data y ~ x above? #Please do not use model-lm(y ~ x) as this will minimize the square of the errors, not the mean absolute percent error Best regards, André Cesta [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] readJPEG function cannot open jpeg files
I have used the biOps package to read pictures and it works fine. For example you can plot a pic just by: library(biOps) x - readJpeg(mypic.jpg) ##mypic should be in you working directory plot(x) Notice that is only one uppercase letter on readJpeg and mypic is jpg not jpeg Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx From: William Dunlap wdun...@tibco.com To: Jeff Newmiller jdnew...@dcn.davis.ca.us; Yi Yuan lamban...@gmail.com; r-help@r-project.org r-help@r-project.org Sent: Monday, January 14, 2013 8:44 AM Subject: Re: [R] readJPEG function cannot open jpeg files You can use file.info(myFile) to make sure the file exists and has appropriate permissions (mode in file.info's lingo, as in Unix). E.g., file.info(c:/temp/BO.jpeg) # this one does not exist size isdir mode mtime ctime atime exe c:/temp/BO.jpeg NA NA NA NA NA NA NA file.info(c:/temp/BO.jpg) # this one exists size isdir mode mtime ctime atime c:/temp/BO.jpg 150536 FALSE 666 2013-01-14 08:35:32 2013-01-14 08:33:09 2013-01-14 08:33:09 exe c:/temp/BO.jpg no I can readJPEG() the file with mode 666, but not all permission information is encoded in the mode. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Monday, January 14, 2013 8:25 AM To: Yi Yuan; r-help@r-project.org Subject: Re: [R] readJPEG function cannot open jpeg files Being unable to open a file is a related to your operating system and how R interacts with that OS. If your interactive development environment (IDE, of which RStudio is an example) is trying to make things simpler for you but you don't understand how to use it, then you need to ask help from your RStudio support resources, not here. When posting here, you should mention your results from using base R functions like ?sessionInfo ?getwd ?list.files as indicated in the Posting Guide mentioned at the bottom of every R-help email. Consistent with the fact that this is an interface issue between R and the OS, sometimes you will have to investigate the problem from outside R. For example, you might need to investigate issues with security permissions that are OS specific and completely outside the scope of this forum. --- Jeff Newmiller The . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Yi Yuan lamban...@gmail.com wrote: I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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,
[R] readJPEG function cannot open jpeg files
Hi, r-help mailing list subscribers, I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. Thanks for your help! [[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] readJPEG function cannot open jpeg files
Thanks William ! file.info(E:/ home work/Rstudio/kim.jpeg) size isdir mode mtime ctime atime exe E:/home work/Rstudio/kim.jpeg NANA NA NA NA NA NA So R thinks this file doesn't exist? But the file is already in E:/ home work/Rstudio folder, I don't understand why file.info( ) returned such message. I have multiple files in this directory E:/home work/Rstudio, but R shows: file.info(E:/home work/Rstudio) size isdir mode mtime ctime atime exe E:/home work/Rstudio0 TRUE 777 2013-01-13 22:12:58 2013-01-13 20:57:36 2013-01-13 22:12:58 no Any help ? On Mon, Jan 14, 2013 at 11:44 AM, William Dunlap wdun...@tibco.com wrote: You can use file.info(myFile) to make sure the file exists and has appropriate permissions (mode in file.info's lingo, as in Unix). E.g., file.info(c:/temp/BO.jpeg) # this one does not exist size isdir mode mtime ctime atime exe c:/temp/BO.jpeg NANA NA NA NA NA NA file.info(c:/temp/BO.jpg) # this one exists size isdir mode mtime ctime atime c:/temp/BO.jpg 150536 FALSE 666 2013-01-14 08:35:32 2013-01-14 08:33:09 2013-01-14 08:33:09 exe c:/temp/BO.jpg no I can readJPEG() the file with mode 666, but not all permission information is encoded in the mode. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Monday, January 14, 2013 8:25 AM To: Yi Yuan; r-help@r-project.org Subject: Re: [R] readJPEG function cannot open jpeg files Being unable to open a file is a related to your operating system and how R interacts with that OS. If your interactive development environment (IDE, of which RStudio is an example) is trying to make things simpler for you but you don't understand how to use it, then you need to ask help from your RStudio support resources, not here. When posting here, you should mention your results from using base R functions like ?sessionInfo ?getwd ?list.files as indicated in the Posting Guide mentioned at the bottom of every R-help email. Consistent with the fact that this is an interface issue between R and the OS, sometimes you will have to investigate the problem from outside R. For example, you might need to investigate issues with security permissions that are OS specific and completely outside the scope of this forum. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Yi Yuan lamban...@gmail.com wrote: I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[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. [[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] readJPEG function cannot open jpeg files
Hi, guys, my problem is solved. I used file.info(list.files(getwd(),full.names=TRUE)) and found out that the said file is listed as kim.jpg instead of kim.jpeg. So kim-readJPEG(kim.jpg) worked. Thanks for your help and sorry for my newbie question. On Mon, Jan 14, 2013 at 11:59 AM, Yi Yuan lamban...@gmail.com wrote: Thanks William ! file.info(E:/ home work/Rstudio/kim.jpeg) size isdir mode mtime ctime atime exe E:/home work/Rstudio/kim.jpeg NANA NA NA NA NA NA So R thinks this file doesn't exist? But the file is already in E:/ home work/Rstudio folder, I don't understand why file.info( ) returned such message. I have multiple files in this directory E:/home work/Rstudio, but R shows: file.info(E:/home work/Rstudio) size isdir mode mtime ctime atime exe E:/home work/Rstudio0 TRUE 777 2013-01-13 22:12:58 2013-01-13 20:57:36 2013-01-13 22:12:58 no Any help ? On Mon, Jan 14, 2013 at 11:44 AM, William Dunlap wdun...@tibco.comwrote: You can use file.info(myFile) to make sure the file exists and has appropriate permissions (mode in file.info's lingo, as in Unix). E.g., file.info(c:/temp/BO.jpeg) # this one does not exist size isdir mode mtime ctime atime exe c:/temp/BO.jpeg NANA NA NA NA NA NA file.info(c:/temp/BO.jpg) # this one exists size isdir mode mtime ctime atime c:/temp/BO.jpg 150536 FALSE 666 2013-01-14 08:35:32 2013-01-14 08:33:09 2013-01-14 08:33:09 exe c:/temp/BO.jpg no I can readJPEG() the file with mode 666, but not all permission information is encoded in the mode. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Monday, January 14, 2013 8:25 AM To: Yi Yuan; r-help@r-project.org Subject: Re: [R] readJPEG function cannot open jpeg files Being unable to open a file is a related to your operating system and how R interacts with that OS. If your interactive development environment (IDE, of which RStudio is an example) is trying to make things simpler for you but you don't understand how to use it, then you need to ask help from your RStudio support resources, not here. When posting here, you should mention your results from using base R functions like ?sessionInfo ?getwd ?list.files as indicated in the Posting Guide mentioned at the bottom of every R-help email. Consistent with the fact that this is an interface issue between R and the OS, sometimes you will have to investigate the problem from outside R. For example, you might need to investigate issues with security permissions that are OS specific and completely outside the scope of this forum. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Yi Yuan lamban...@gmail.com wrote: I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list
Re: [R] readJPEG function cannot open jpeg files
On 13-01-14 11:59 AM, Yi Yuan wrote: Thanks William ! file.info(E:/ home work/Rstudio/kim.jpeg) size isdir mode mtime ctime atime exe E:/home work/Rstudio/kim.jpeg NANA NA NA NA NA NA So R thinks this file doesn't exist? But the file is already in E:/ home work/Rstudio folder, I don't understand why file.info( ) returned such message. I have multiple files in this directory E:/home work/Rstudio, but R shows: file.info(E:/home work/Rstudio) size isdir mode mtime ctime atime exe E:/home work/Rstudio0 TRUE 777 2013-01-13 22:12:58 2013-01-13 20:57:36 2013-01-13 22:12:58 no Any help ? You seem to sometimes have spaces ahead of home and sometimes not. What I recommend most people do on Windows is not to try to type the filename yourself, use file.choose() or choose.files() to get a dialog box and pick it out of there. Duncan Murdoch On Mon, Jan 14, 2013 at 11:44 AM, William Dunlap wdun...@tibco.com wrote: You can use file.info(myFile) to make sure the file exists and has appropriate permissions (mode in file.info's lingo, as in Unix). E.g., file.info(c:/temp/BO.jpeg) # this one does not exist size isdir mode mtime ctime atime exe c:/temp/BO.jpeg NANA NA NA NA NA NA file.info(c:/temp/BO.jpg) # this one exists size isdir mode mtime ctime atime c:/temp/BO.jpg 150536 FALSE 666 2013-01-14 08:35:32 2013-01-14 08:33:09 2013-01-14 08:33:09 exe c:/temp/BO.jpg no I can readJPEG() the file with mode 666, but not all permission information is encoded in the mode. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Monday, January 14, 2013 8:25 AM To: Yi Yuan; r-help@r-project.org Subject: Re: [R] readJPEG function cannot open jpeg files Being unable to open a file is a related to your operating system and how R interacts with that OS. If your interactive development environment (IDE, of which RStudio is an example) is trying to make things simpler for you but you don't understand how to use it, then you need to ask help from your RStudio support resources, not here. When posting here, you should mention your results from using base R functions like ?sessionInfo ?getwd ?list.files as indicated in the Posting Guide mentioned at the bottom of every R-help email. Consistent with the fact that this is an interface issue between R and the OS, sometimes you will have to investigate the problem from outside R. For example, you might need to investigate issues with security permissions that are OS specific and completely outside the scope of this forum. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Yi Yuan lamban...@gmail.com wrote: I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[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. [[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,
Re: [R] How to open grib file in R?
I have just contacted the sources and I am told that he checked min/max lat/lon for the file and it was right. He is using Linux while I am using Windows, would that be problematic? -- View this message in context: http://r.789695.n4.nabble.com/How-to-open-grib-file-in-R-tp4655497p4655517.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Tukey HSD plot with lines indicating (non-)significance
Please look at the MMC (Mean-mean Multiple Comparisons) plot in the HH package. It displays both the means and the differences. install.packages(HH) ## if you don't already have it. library(HH) ?MMC Rich On Mon, Jan 14, 2013 at 12:36 PM, Karl Ove Hufthammer k...@huftis.orgwrote: Dear list members, I'm running some tests looking at differences between means for various levels of a factor, using Tukey's HSD method. I would like to plot the data as boxplots or dotplots, with horizontal significance lines indicating which groups are statistically significantly different, according to Tukey HSD. Here's a nice image showing an example of such a graphical display: http://www.biomedcentral.com/**1471-2148/11/99/figure/F2http://www.biomedcentral.com/1471-2148/11/99/figure/F2 Is there a R function for this? I have tried searching, and found several nice plotting fuctions for Tukey's HSD, but they all either hide the actual data, or display the results only with letters indicating (non-)signifiance. Examples: # Fit an one-way ANOVA. library(DAAG) l=aov(ShootDryMass ~ trt, data=rice) summary(l) # Calculate the Tukey HSD tests and CIs. # The plot shows all 6*5/2 = 15 confidence intervals, # but not the data or the actual group means. l.hsd=TukeyHSD(l, trt, ordered = TRUE) l.hsd plot(l.hsd) # I rather like this one. It shows the group means in a nice way, # but hides the data. And checking which groups are different # isn't always easy (e.g., for NH4Cl - NH4NO3), as one # has to compare differences to a non-aligned scale (bar). onewayPlot(l) # One function that gives a results closer to what I want, # is the compact letter display (CLD) of the multcomp package. # This shows boxplots (but it is easy to overlay the actual # observations, using the points() function) and uses letters # to indicate non-significance. # # (Note that (if I have understood everything correctly) this # doesn't actually calculcate Tukey HSD values (the Tukey # in the glht() call only selects Tukey *contrasts*), but # the results should be *very* similar.) library(multcomp) l.glht=glht(l, linfct = mcp(trt = Tukey)) summary(l.glht) l.cld=cld(l.glht) old.par - par( mai=c(1,1,2,1)) plot(l.cld) par(old.par) # Basically, I want a similar display as the one above (or # preferably a ggplot2- or lattice-based one), but with lines # instead of letters. Of course, for this, the levels need to be # reordered by group means, and it is only guaranteed to # work for balanced data. Example, with the lines missing: library(ggplot2) d=rice d$trt=reorder(d$trt, -d$ShootDryMass) ggplot(d, aes(x=trt, y=ShootDryMass)) + geom_boxplot(outlier.colour=**NA) + geom_jitter(col=red, size=3, position=position_jitter(**width=.1)) Is there such a function available in R? -- Karl Ove Hufthammer __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] readJPEG function cannot open jpeg files
On 13-01-14 12:18 PM, Yi Yuan wrote: Hi, guys, my problem is solved. I used file.info(list.files(getwd(),full.names=TRUE)) and found out that the said file is listed as kim.jpg instead of kim.jpeg. So kim-readJPEG(kim.jpg) worked. Thanks for your help and sorry for my newbie question. Another recommendation I make for all Windows users is to change the Explorer options to display full filenames. That would have prevented this error. (This is an option in Windows, not in R.) I've never understood why Microsoft thinks it is good to display incomplete filenames. This practice causes so many problems. Duncan Murdoch On Mon, Jan 14, 2013 at 11:59 AM, Yi Yuan lamban...@gmail.com wrote: Thanks William ! file.info(E:/ home work/Rstudio/kim.jpeg) size isdir mode mtime ctime atime exe E:/home work/Rstudio/kim.jpeg NANA NA NA NA NA NA So R thinks this file doesn't exist? But the file is already in E:/ home work/Rstudio folder, I don't understand why file.info( ) returned such message. I have multiple files in this directory E:/home work/Rstudio, but R shows: file.info(E:/home work/Rstudio) size isdir mode mtime ctime atime exe E:/home work/Rstudio0 TRUE 777 2013-01-13 22:12:58 2013-01-13 20:57:36 2013-01-13 22:12:58 no Any help ? On Mon, Jan 14, 2013 at 11:44 AM, William Dunlap wdun...@tibco.comwrote: You can use file.info(myFile) to make sure the file exists and has appropriate permissions (mode in file.info's lingo, as in Unix). E.g., file.info(c:/temp/BO.jpeg) # this one does not exist size isdir mode mtime ctime atime exe c:/temp/BO.jpeg NANA NA NA NA NA NA file.info(c:/temp/BO.jpg) # this one exists size isdir mode mtime ctime atime c:/temp/BO.jpg 150536 FALSE 666 2013-01-14 08:35:32 2013-01-14 08:33:09 2013-01-14 08:33:09 exe c:/temp/BO.jpg no I can readJPEG() the file with mode 666, but not all permission information is encoded in the mode. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller Sent: Monday, January 14, 2013 8:25 AM To: Yi Yuan; r-help@r-project.org Subject: Re: [R] readJPEG function cannot open jpeg files Being unable to open a file is a related to your operating system and how R interacts with that OS. If your interactive development environment (IDE, of which RStudio is an example) is trying to make things simpler for you but you don't understand how to use it, then you need to ask help from your RStudio support resources, not here. When posting here, you should mention your results from using base R functions like ?sessionInfo ?getwd ?list.files as indicated in the Posting Guide mentioned at the bottom of every R-help email. Consistent with the fact that this is an interface issue between R and the OS, sometimes you will have to investigate the problem from outside R. For example, you might need to investigate issues with security permissions that are OS specific and completely outside the scope of this forum. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Yi Yuan lamban...@gmail.com wrote: I installed jpeg package and tried to use kim-readJPEG(kim.jpeg) to read in a jpeg file, but R gave me an error: Error in readJPEG(kim.jpeg) : unable to open kim.jpeg I already put kim.jpeg in Rstudio's default working directory: E:\home work\Rstudio. So I don't think it's a problem caused by omitting the file's path. But I tried with the full path version just in case and still got the unable to open error: kim-readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) Error in readJPEG(E:\\ home work\\Rstudio\\kim.jpeg) : unable to open E:\ home work\Rstudio\kim.jpeg So now I really don't know what is wrong. [[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
Re: [R] ginv / LAPACK-SVD causes R to segfault on a large matrix.
On Jan 14, 2013, at 9:07 AM, Cyrus Shaoul wrote: No, Mehmet, I haven't tried that yet. I was hoping to find out if there was some other option. I have no experience using LAPACK directly. I have looked into RcppEigen and RcppArmadillo, but have not tested them yet. If there are no other options, I guess I will go down that path. I tried it on a 64 bit R with 32GB of RAM. It exhausted those resources and started paging out into virtual memory. No error, but I killed the process. -- David. Thanks a lot, Cyrus On Mon, Jan 14, 2013 at 4:17 PM, Suzen, Mehmet msu...@gmail.com wrote: On 14 January 2013 15:08, Cyrus Shaoul cyrus.sha...@uni-tuebingen.de wrote: La.svd Dear Cyrus, Have you tried running La.svd ; LAPACK only version (without R) via C/C++ or Fortran code? After all it can be a LAPACK issue and R-team has no control on that. David Winsemius 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.
Re: [R] readJPEG function cannot open jpeg files
On 14 January 2013 18:56, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: On 14/01/2013 16:26, Suzen, Mehmet wrote: Similar issue with URLs: Not a similar issue at all: a URL is not a file. That most functions in R itself open connections including URLs does not mean that contributed packages do. The package help is quite specific about its requirements. source: Either name of the file to read from or a raw vector representing the JPEG file content. Which suggests to you how you can do this, apart from download.file, of course. Something like readJPEG(readBin(yesWeCan, raw, 1e6)) Dear Prof. Ripley, Thank you for the correction. I was thinking in the lines of 'Everything is a file' concept. (http://en.wikipedia.org/wiki/Everything_is_a_file). Best, -m __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] random effects model
Hi, I get the error message. BP.gee8- gee(hibp14~time*Categ,data=BPsub7,id=CODEA,family=binomial,corstr=exchangeable,na.action=na.omit) #Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27 #Error in gee(hibp14 ~ time * Categ, data = BPsub7, id = CODEA, family = binomial, : # rank-deficient model matrix #Reason I mentioned before. If you want to see what is happening, you could check this: dat1-structure(list(CODEA = c(3L, 7L, 8L), IntScore = c(0L, 0L, 0L ), Obese14 = c(1L, 0L, 1L), Overweight14 = c(1L, 1L, 1L), Obese21 = c(1L, 1L, 0L), Overweight21 = c(1L, 1L, 0L), hibp14 = c(1L, 0L, 1L), hibp21 = c(0L, 1L, 0L)), .Names = c(CODEA, IntScore, Obese14, Overweight14, Obese21, Overweight21, hibp14, hibp21), class = data.frame, row.names = c(NA, -3L)) reshape(dat1,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long) #your code # CODEA IntScore hibp14 hibp21 time Obese Overweight #here hibp14/hibp21 (response variable) gets replicated i.e. hibp14 values are the same for time==1 and time==2 whereas Obese, Overweigh #values change #3.1 3 0 1 0 1 1 1 #7.1 7 0 0 1 1 0 1 #8.1 8 0 1 0 1 1 1 #3.2 3 0 1 0 2 1 1 #7.2 7 0 0 1 2 1 1 #8.2 8 0 1 0 2 0 0 A.K. - Original Message - From: rex2013 usha.nat...@gmail.com To: r-help@r-project.org Cc: Sent: Monday, January 14, 2013 3:04 AM Subject: Re: [R] random effects model Sorry I have corrected the mistakes: BP.stack3 - reshape(Copy.of.BP_2,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long) BP.stack3 head(BP.stack3) tail(BP.stack3) names(BP.stack3)[c(2,3,4,5,6,7)] - c(Sex,MaternalAge,Education,Birthplace,AggScore,IntScore) names(BP.stack3)[1:7] BP.stack3 - transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c(Male,Female)),MaternalAge=factor(MaternalAge,labels=c(39years or less,40-49 years,50 years or older)),Education=factor(Education,labels=c(Primary/special,Started secondary,Completed grade10, Completed grade12, College,University)),Birthplace=factor(Birthplace,labels=c(Australia,Other English-speaking,Other))) str(BP.stack3) table(BP.stack3$Sex) BP.stack3$Sex - factor(BP.stack3$Sex,levels=levels(BP.stack3$Sex)[c(2,1)]) levels(BP.stack3$Sex) BPsub6 - subset(BP.stack3,subset=!(is.na(Sex)| is.na(Education)|is.na (Birthplace)|is.na(Education)|is.na(hibp14)| is.na(hibp21))) summary(BPsub6) BPsub6$Categ[BPsub6$Overweight==1BPsub6$time==1BPsub6$Obese==0] - Overweight14 BPsub6$Categ[BPsub6$Overweight==1BPsub6$time==2BPsub6$Obese==0] - Overweight21 BPsub6$Categ[BPsub6$Obese==1BPsub6$time==1BPsub6$Overweight==0|BPsub6$Obese==1BPsub6$time==1BPsub6$Overweight==1 ] - Obese14 BPsub6$Categ[BPsub6$Obese==0BPsub6$time==1BPsub6$Overweight==0] - Normal14 BPsub6$Categ[BPsub6$Obese==0BPsub6$time==2BPsub6$Overweight==0] - Normal21 BPsub6$Categ[BPsub6$Obese==1BPsub6$time==2BPsub6$Overweight==0|BPsub6$Obese==1BPsub6$time==2BPsub6$Overweight==1] - Obese21 BPsub6$Categ - factor(BPsub6$Categ) BPsub6$time - factor(BPsub6$time) summary(BPsub6$Categ) BPsub7 - subset(BPsub6,subset=!(is.na(Categ))) BPsub7 - BPsub7[order(BPsub7$CODEA),] BPsub7$hibp14 - factor(BPsub7$hibp14) levels(BPsub7$hibp14) levels(BPsub7$Categ) names(BPsub7) head(BPsub7) tail(BPsub7) str(BPsub7) library(gee) BP.gee8 - gee(hibp14~ time*Categ, data=BPsub7,id=CODEA,family=binomial, corstr=exchangeable,na.action=na.omit) summary(BP.gee8) ## Can you try this out please? I am not clear where the defect is with model? One other previous model had no correlation between obese 14 and time. With this one, i cannot find anything wrong as such, but still wont work. Thanks On Mon, Jan 14, 2013 at 10:30 AM, arun kirshna [via R] ml-node+s789695n4655440...@n4.nabble.com wrote: HI, I think I mentioned to you before that when you reshape the columns excluding the response variable, response variable gets repeated (in this case hibp14 or hibp21) and creates the error I run your code, there are obvious problems in the code so I didn't reach up to BP.gee BP_2b-read.csv(BP_2b.csv,sep=\t) BP.stack3 - reshape(BP_2b,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long) BP.stack3 - transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c(Male,Female)),MaternalAge=factor(MaternalAge,labels=c(39years or less,40-49 years,50 years or older)),Education=factor(Education,labels=c(Primary/special,Started secondary,Completed grade10, Completed grade12, College,University)),Birthplace=factor(Birthplace,labels=c(Australia,Other
[R] Confidence intervel for regression line
Hi all, For the simple linear regression, I want to find the input x value so that the lower confidnece limit is a specific number, say 0.2. In other words, I want to find the value of x so that the lower confidence bound crosses the horizontal line 0.2. Is there a simple way (an R function) that can do this? Thanks. Hanna [[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] Determining sample size from power function
If you have a working function that gives the power for a given sample size then you can use the uniroot function to find which sample size will give the desired power (many of the standard power functions use this internally when computing anything other than power). You just create a function that accepts the sample size as the only argument then uses that (along with your other conditions) to compute the power and subtract from that the desired power, you pass this function to uniroot and it looks for the sample size that matches the power. On Wed, Jan 9, 2013 at 9:21 PM, Kaveh Zakeri kzak...@ucsd.edu wrote: Hello, I am trying to get the power function to report the sample size rather than the power. My goal is to input a variety of values for theta and then for the power function to report the corresponding sample sizes. I haven't had much luck trying to create my own function, something along the lines of: f - function (x) { power(N=z,a=6,f=6,pi=.5,alpha=.1,t0=10,theta=(1/x),CIFev0=.476,CIFcr0=0))=0.8 read(z) } In the above example, I am trying to fix the power at 0.80 and solve for z, which is the sample size. I would like x to be a random distribution of thetas. For instance: x=rnorm(30,.5,.2) and then receive the 30 corresponding sample sizes. Thank you! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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] Tukey HSD plot with lines indicating (non-)significance
må. den 14. 01. 2013 klokka 13.58 (-0500) skreiv Richard M. Heiberger: Please look at the MMC (Mean-mean Multiple Comparisons) plot in the HH package. It displays both the means and the differences. install.packages(HH) ## if you don't already have it. library(HH) ?MMC Thanks for the suggestion. That’s a very interesting and clever way of displaying both means and differences. It’s not what I was looking for, though, as it doesn’t display the actual data. For the record, here’s the syntax for using MMC on the dataset mentioned in my original posting: l.mmc=mmc(l, linfct = mcp(trt = Tukey)) plot(l.mmc) (It looks best on data where the group means aren’t very close; otherwise the labels might overlap.) -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] function coverage
Is there an easy way to identify all the functions called as a result of invoking a function? Getting the calling hierarchy too would be nice, but is definitely not essential. I'm trying to understand someone else's package, which is in a namespace and has some S3 functions. I could probably live without tracing the S3 functions. All the functions I want to trace are in R. The code passes functions around as arguments, so that the function being called is not always obvious from inspection of the source immediately around the call. I can imagine a solution that went something like this: 1. identify all functions by searching the sources for - function( (probably only at the left margin, to avoid attempting to trace functions defined inside of functions). 2. Write a function that wraps another function to record the fact that it has been called. 3. Somehow replace all functions with their wrapped equivalents. 4. make the top level call. 5. inspect the data constructed by the wrapper. The code is recursive and iterative; manual stepping does not seem feasible. The package includes a lot of earlier versions of the code, and so I suspect that a lot of the code is not active. Thanks. Ross Boylan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 coverage
Possibly you could trace() all the functions you're interested in. E.g., lapply(ls(package:stats), trace) # Untested. MW On Mon, Jan 14, 2013 at 9:08 PM, Ross Boylan r...@biostat.ucsf.edu wrote: Is there an easy way to identify all the functions called as a result of invoking a function? Getting the calling hierarchy too would be nice, but is definitely not essential. I'm trying to understand someone else's package, which is in a namespace and has some S3 functions. I could probably live without tracing the S3 functions. All the functions I want to trace are in R. The code passes functions around as arguments, so that the function being called is not always obvious from inspection of the source immediately around the call. I can imagine a solution that went something like this: 1. identify all functions by searching the sources for - function( (probably only at the left margin, to avoid attempting to trace functions defined inside of functions). 2. Write a function that wraps another function to record the fact that it has been called. 3. Somehow replace all functions with their wrapped equivalents. 4. make the top level call. 5. inspect the data constructed by the wrapper. The code is recursive and iterative; manual stepping does not seem feasible. The package includes a lot of earlier versions of the code, and so I suspect that a lot of the code is not active. Thanks. Ross Boylan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] function coverage
On 13-01-14 4:08 PM, Ross Boylan wrote: Is there an easy way to identify all the functions called as a result of invoking a function? Getting the calling hierarchy too would be nice, but is definitely not essential. I think codetools could do this reasonably well with the walkCode function, but I've never done it so I don't have sample code, and walkCode is mostly an internal function. The other way to do it is to run Rprof. It's only a sampling profiler, so you don't get complete coverage, but it sees what really happens at run-time. The proftools package can generate a call tree. (In R 3.0.0 you'll probably be able to extend this coverage analysis to the statement level, but it's not there yet.) I'm trying to understand someone else's package, which is in a namespace and has some S3 functions. I could probably live without tracing the S3 functions. All the functions I want to trace are in R. The code passes functions around as arguments, so that the function being called is not always obvious from inspection of the source immediately around the call. Right, that makes it hard. I don't know if walkCode could figure that stuff out, and the current Rprof won't know the original name if you do something like f - mean f(3) The new stuff should be able to help in cases where the called function is written in R and is slow enough to be caught by the profiler. If you want to try it out and can compile R-devel for yourself, write to me and I'll send you a patch offline. I can imagine a solution that went something like this: 1. identify all functions by searching the sources for - function( (probably only at the left margin, to avoid attempting to trace functions defined inside of functions). 2. Write a function that wraps another function to record the fact that it has been called. 3. Somehow replace all functions with their wrapped equivalents. 4. make the top level call. 5. inspect the data constructed by the wrapper. The code is recursive and iterative; manual stepping does not seem feasible. The package includes a lot of earlier versions of the code, and so I suspect that a lot of the code is not active. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error using the subset function in a for loop index
Hi all, I have attached the function file (revisedfunction) and the list of station IDs (StationIDs) in .pdf format documents. I have written a function to perform various operations on the station IDs in two groups. The first 6 station IDs require one less step than the remaining 68 station IDs. The file referenced at the beginning of the function is the file containing the StationIDs. I created a for loop to allow indexing through each set of station IDs. I have not been able to run the complete function because I can not subset the for loop index within the subset function. Is there a way to perform this operation: Sample - subset(Sample,station_id==[i]) within the indexed for loop using another built-in function or through the subset function? The attached file revisedfunction provides the full function code in which that line creating another instance of the variable Sample is excerpted from. Thank-you. Irucka Embry span id=m2wTlpfont face=Arial, Helvetica, sans-serif size=2 style=font-size:13.5px___BRGet the Free email that has everyone talking at a href=http://www.mail2world.com target=newhttp://www.mail2world.com/abr font color=#99Unlimited Email Storage #150; POP3 #150; Calendar #150; SMS #150; Translator #150; Much More!/font/font/span__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rbbg for 2.15.2
Dear R Users, Anyone know of a version of Rbbg compiled for R 2.15.2 . The current version does not appear to work with 2.15.2 install.packages(Rbbg, repos = http://r.findata.org;) Installing package(s) into ‘C:/Users/t_uzu_000/Documents/R/win-library/2.15’ (as ‘lib’ is unspecified) Warning: unable to access index for repository http://r.findata.org/src/contrib Warning message: package ‘Rbbg’ is not available (for R version 2.15.2) Thanks in advance, Tolga __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 coverage
I think codetools could do this reasonably well with the walkCode function, but I've never done it so I don't have sample code, and walkCode is mostly an internal function. There are a couple of approaches here: http://stackoverflow.com/questions/14276728/ Hadley -- Chief Scientist, RStudio 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.
[R] tabstop in graphics
Hi, I'm curious about Tab stops in graphics: plot(1) text(1.2, 1.2, Char\nMoreChar) works fine, but text(1.2, 0.8, Char\tMoreChar) doesn't. Exporting with pdf tells me that the sign width is unknown. I'm not into informatics, so I don't know how a tabstop actually works. Is this at all possible in graphical commands as it is in write.table and the like? I'm e.g. writing a legend with two colums. I solve this with addingvia paste to each element of the first column in one legend command, and then adding a second legend more to the right with the second column with bty=n. That's OK for the results, but not elegant programming... paste(ColumnOne, \t, ColumnTwo, sep=) would be more what I'd intuitively use. Any ideas are welcome! Berry (Potsdam, Germany) [[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] Changing MaxNWts with the mi() function (error message)
Hello, I am trying to impute data with the mi() function (mi package) and keep receiving an error message. When imputing the variable, sex, the mi() function accesses the mi.categorical() function, which then accesses the nnet() function. I then receive the following error message (preceded by my code below): imputed.england=mi(england.pre.imputed, n.iter=6, add.noise=FALSE) Beginning Multiple Imputation ( Mon Jan 14 13:39:49 2013 ): Iteration 1 Chain 1 : sex Error while imputing variable: sex , model: mi.categorical Error in nnet.default(X, Y, w, mask = mask, size = 0, skip = TRUE, softmax = TRUE, : too many (3432) weights The error message indicates that there are too many weights (3432). I know you can adjust the maximum weights with the mi.categorical() function (i.e., MaxNWts= 3500), but I do not see a way to do this with the mi() function. I found an R-help posting from two years ago with some instruction on how to change the max weights in mi(), but I can't seem to get it to work. The following is a link to the post: http://r.789695.n4.nabble.com/Changing-model-parameters-in-the-mi-package-td2288851.html#a2288933 And my implementation of the suggestion from that post: info=mi.info(england.pre.imputed) info[[sex]]$params$MaxNWts=3500 info[[sex]]$params $n.iter [1] 100 $MaxNWts [1] 3500 $missing.index NULL When I try the imputation again I receive the same error message as before: imputed.england=mi(england.pre.imputed, n.iter=6, add.noise=FALSE) Beginning Multiple Imputation ( Mon Jan 14 14:20:46 2013 ): Iteration 1 Chain 1 : sex* Error while imputing variable: sex , model: mi.categorical Error in nnet.default(X, Y, w, mask = mask, size = 0, skip = TRUE, softmax = TRUE, : too many (3432) weights So, I tried a few more things, and received the same error message. First... imputed.england=mi(england.pre.imputed,info=info) This yields the same error message. Then... inf=mi.info(england.pre.imputed) inf=update(inf, MaxNWts, list(sex=3500)) imputed.england=mi(england.pre.imputed, info=inf) Beginning Multiple Imputation ( Mon Jan 14 14:31:20 2013 ): Iteration 1 Chain 1 : sex* Error while imputing variable: sex , model: mi.categorical Error in nnet.default(X, Y, w, mask = mask, size = 0, skip = TRUE, softmax = TRUE, : too many (3432) weights Again, the same error message. For some reason, I am unable to successfully adjust the max weights. I would greatly appreciate any suggestions. Thanks in advance! -- Heather Hensman Kettrey PhD Candidate Department of Sociology Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] I'm trying to parse 1 column of a dataframe into 3 seperate columns
I have a factor called 'utm_medium' in the dataframe 'data' str(data$utm_medium) Factor w/ 396925 levels ,affiliateID=sessionID=821850667323ec6ae6cffd28f380etag=,..: 366183 355880 357141 20908 357513 365348 368088 360827 31704 364767 ... The data in this factor is delimited with ''. I basically want the affiliateID, sessionID and etag data separated. Ex. data$utm_medium[1:10] [1] affiliateID=4f3ac4b695e7dsessionID=993f4c447e68dfc36ed692223349f2e3eta g= [2] affiliateID=4f3ac4b695e7dsessionID=209dd9986ace55d50a450afeba62b78feta g= [3] affiliateID=4f3ac4b695e7dsessionID=2efdb8e1e1f5ac9c0d5baec355c78f85eta g= [4] affiliateID=sessionID=5a6ca9d41148f30ce694628427af7991etag= [5] affiliateID=4f3ac4b695e7dsessionID=331fbcdf1f3d5e7bac0d92c12e19f63deta g= [6] affiliateID=4f3ac4b695e7dsessionID=8fc27c8478e9bd30043ea4d3c7ddb29ceta g= [7] affiliateID=4f3ac4b695e7dsessionID=af467d480addffca43ffbdbce1edfdb4eta g= [8] affiliateID=4f3ac4b695e7dsessionID=598645e05a187ee63ff922a36360f021eta g= [9] affiliateID=sessionID=8895e21d0842ed45063ba8328dc3bc61etag= [10] affiliateID=4f3ac4b695e7dsessionID=88ca2998c5a91b6efbece0c4f79caeb7eta g= 396925 Levels: ... affiliateID=50bfbbbeed918sessionID=5c49c142cbf1b149c6a4647d1a4fc97beta g= I've parsed it via: test -as.character(data$utm_medium) test - strsplit(test, ) which results in a list, which I 'unlisted': test2 - unlist(test) and then attempted to extract into separate vectors: a - vector(mode = character, length = length(test2)) s - vector(mode = character, length = length(test2)) e - vector(mode = character, length = length(test2)) i - 1 j - 1 for (i in 1:length(test2)) { a[j] - test2[i] s[j] - test2[i+1] e[j] - test2[i+2] i - i + 3 j - j + 1 } This code runs, but I'm indexing it incorrectly and I can't figure out why. I'll sleep on it tonight and probably figure it out, but I can't help thinking that there's a much easier way to parse this data. Help! Please! joel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] random effects model
HI, BP_2b-read.csv(BP_2b.csv,sep=\t) BP_2bNM-na.omit(BP_2b) BP.stack3 - reshape(BP_2bNM,idvar=CODEA,timevar=time,sep=,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21),c(hibp14,hibp21)),v.names=c(Obese,Overweight,HiBP),times=factor(c(1,2)),direction=long) library(car) BP.stack3$Obese- recode(BP.stack3$Obese,1='Obese';0='Not Obese') BP.stack3$Overweight- recode(BP.stack3$Overweight,1='Overweight';0='Not Overweight') library(ggplot2) ggplot(BP.stack3,aes(x=factor(HiBP),fill=Obese))+geom_bar(position=fill) ggplot(BP.stack3,aes(x=factor(HiBP),fill=Overweight))+geom_bar(position=fill) You could try lmer() from lme4. library(lme4) fm1-lmer(HiBP~time+(1|CODEA), family=binomial,data=BP.stack3) #check codes, not sure print(dotplot(ranef(fm1,post=TRUE), scales = list(x = list(relation = free)))[[1]]) qmt1- qqmath(ranef(fm1, postVar=TRUE)) print(qmt1[[1]]) A.K. From: Usha Gurunathan usha.nat...@gmail.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org Sent: Monday, January 14, 2013 6:32 AM Subject: Re: [R] random effects model Hi AK I have been trying to create some plots. All being categorical variables, I am not getting any luck with plots. The few ones that have worked are below: barchart(~table(HiBP)|Obese,data=BP.sub3) ## BP.sub3 is the stacked data without missing values barchart(~table(HiBP)|Overweight,data=BP.sub3) plot(jitter(hibp14,factor=2)~jitter(Obese14,factor=2),col=gray,cex=0.7, data=Copy.of.BP_2) ## Copy.of.BP_2 is the original wide format ## not producing any good plots with mixed models as well. summary(lme.3 - lme(HiBP~time, data=BP.sub3,random=~1|CODEA, na.action=na.omit)) anova(lme.3) head(ranef(lme.3)) print(plot(ranef(lme.3))) ## Thanks for any help. On Mon, Jan 14, 2013 at 4:33 AM, arun smartpink...@yahoo.com wrote: HI, I think I mentioned to you before that when you reshape the columns excluding the response variable, response variable gets repeated (in this case hibp14 or hibp21) and creates the error I run your code, there are obvious problems in the code so I didn't reach up to BP.gee BP_2b-read.csv(BP_2b.csv,sep=\t) BP.stack3 - reshape(BP_2b,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long) BP.stack3 - transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c(Male,Female)),MaternalAge=factor(MaternalAge,labels=c(39years or less,40-49 years,50 years or older)),Education=factor(Education,labels=c(Primary/special,Started secondary,Completed grade10, Completed grade12, College,University)),Birthplace=factor(Birthplace,labels=c(Australia,Other English-speaking,Other))) BP.stack3$Sex - factor(BP.stack3$Sex,levels=levels(BP.stack3$Sex)[c(2,1)]) BP.sub3a - subset(BP.stack3,subset=!(is.na(Sex)| is.na(Education)|is.na(Birthplace)|is.na(Education)|is.na(hibp14)| is.na(hibp21))) nrow(BP.sub3a) #[1] 3364 BP.sub5a - BP.sub3a[order(BP.sub3a$CODEA),] # your code was BP.sub5a - BP.sub3a[order(BP.sub5a$CODEA),] ^ was not defined before #Next line BPsub3$Categ[BPsub6$Overweight==1BPsub3$time==1BPsub3$Obese==0]- Overweight14 #It should be BP.sub3 and what is BPsub6, it was not defined previously. #Error in BPsub3$Categ[BPsub6$Overweight == 1 BPsub3$time == 1 BPsub3$Obese == : #object 'BPsub3' not found A.K. From: Usha Gurunathan usha.nat...@gmail.com To: arun smartpink...@yahoo.com Sent: Sunday, January 13, 2013 1:51 AM Subject: Re: [R] random effects model HI AK Thanks a lot for explaining that. 1. With the chi sq. ( in order to find out if the diffce is significant between groups) do I have create a separate excel file and make a dataframe.How do I go about it? I have resent a mail to Jun Yan at a difft email ad( first add.didn't work, mail not delivered). 2. With my previous query ( reg. Obese/Overweight/ Normal at age 14 Vs change of blood pressure status at 21), even though I had compromised without the age-specific regression, but I am still keen to explore why the age-specific regression didn't work despite it looking okay. I have given below the syntax. If you get time, could you kindly look at it and see if it could work by any chance? Apologies for persisting with this query. BP.stack3 - reshape(Copy.of.BP_2,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long BP.stack3 head(BP.stack3) tail(BP.stack3) names(BP.stack3)[c(2,3,4,5,6,7)] - c(Sex,MaternalAge,Education,Birthplace,AggScore,IntScore) BP.stack3 -
Re: [R] I'm trying to parse 1 column of a dataframe into 3 seperate columns
How about a - sapply(test, function(x) x[1]) s - sapply(test, function(x) x[2]) e - sapply(test, function(x) x[3]) -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Joel Pulliam Sent: Monday, January 14, 2013 4:30 PM To: r-help@r-project.org Cc: pullia...@gmail.com Subject: [R] I'm trying to parse 1 column of a dataframe into 3 seperate columns I have a factor called 'utm_medium' in the dataframe 'data' str(data$utm_medium) Factor w/ 396925 levels ,affiliateID=sessionID=821850667323ec6ae6cffd28f380etag=,..: 366183 355880 357141 20908 357513 365348 368088 360827 31704 364767 ... The data in this factor is delimited with ''. I basically want the affiliateID, sessionID and etag data separated. Ex. data$utm_medium[1:10] [1] affiliateID=4f3ac4b695e7dsessionID=993f4c447e68dfc36ed692223349f2e3et a g= [2] affiliateID=4f3ac4b695e7dsessionID=209dd9986ace55d50a450afeba62b78fet a g= [3] affiliateID=4f3ac4b695e7dsessionID=2efdb8e1e1f5ac9c0d5baec355c78f85et a g= [4] affiliateID=sessionID=5a6ca9d41148f30ce694628427af7991etag= [5] affiliateID=4f3ac4b695e7dsessionID=331fbcdf1f3d5e7bac0d92c12e19f63det a g= [6] affiliateID=4f3ac4b695e7dsessionID=8fc27c8478e9bd30043ea4d3c7ddb29cet a g= [7] affiliateID=4f3ac4b695e7dsessionID=af467d480addffca43ffbdbce1edfdb4et a g= [8] affiliateID=4f3ac4b695e7dsessionID=598645e05a187ee63ff922a36360f021et a g= [9] affiliateID=sessionID=8895e21d0842ed45063ba8328dc3bc61etag= [10] affiliateID=4f3ac4b695e7dsessionID=88ca2998c5a91b6efbece0c4f79caeb7et a g= 396925 Levels: ... affiliateID=50bfbbbeed918sessionID=5c49c142cbf1b149c6a4647d1a4fc97bet a g= I've parsed it via: test -as.character(data$utm_medium) test - strsplit(test, ) which results in a list, which I 'unlisted': test2 - unlist(test) and then attempted to extract into separate vectors: a - vector(mode = character, length = length(test2)) s - vector(mode = character, length = length(test2)) e - vector(mode = character, length = length(test2)) i - 1 j - 1 for (i in 1:length(test2)) { a[j] - test2[i] s[j] - test2[i+1] e[j] - test2[i+2] i - i + 3 j - j + 1 } This code runs, but I'm indexing it incorrectly and I can't figure out why. I'll sleep on it tonight and probably figure it out, but I can't help thinking that there's a much easier way to parse this data. Help! Please! joel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Tukey HSD plot with lines indicating (non-)significance
When the group means are close together, the labels will overlap. This overlap is actually informative, indicating that the groups are close. For this common case, we provide the tiebreaker function matchMMC which is also documented and illustrated on the ?MMC page. I have never tried to put the data on the same scale. It should be easy. Let me try, and then post an example. Rich On Mon, Jan 14, 2013 at 3:53 PM, Karl Ove Hufthammer k...@huftis.orgwrote: må. den 14. 01. 2013 klokka 13.58 (-0500) skreiv Richard M. Heiberger: Please look at the MMC (Mean-mean Multiple Comparisons) plot in the HH package. It displays both the means and the differences. install.packages(HH) ## if you don't already have it. library(HH) ?MMC Thanks for the suggestion. Thats a very interesting and clever way of displaying both means and differences. Its not what I was looking for, though, as it doesnt display the actual data. For the record, heres the syntax for using MMC on the dataset mentioned in my original posting: l.mmc=mmc(l, linfct = mcp(trt = Tukey)) plot(l.mmc) (It looks best on data where the group means arent very close; otherwise the labels might overlap.) -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plotting two graphs on the same figure
I want to add a line that represents the relationship between x and y to a strip chart, I've tried the following functions: par(new=TRUE) points(x,y) lines(x,y) but nothing works, I get the strip chart but line doesn't show up. Here is my function: stripchart(hydfin$exp ~ hydfin$alt, vert = TRUE, pch = 1, method = jitter, jit = 0.05, xlab = Elevation, ylab = expression(paste(delta^{2}, H))) points(1:3, hydfin.M, pch = 16, cex = 1.5) arrows(1:3, hydfin.M, 1:3, hydfin.M + hydfin.se, lwd = 1.5, angle = 90, length = 0.1) arrows(1:3, hydfin.M, 1:3, hydfin.M - hydfin.se, lwd = 1.5, angle = 90, length = 0.1) par(new=TRUE) lines(hydfin$exp, hydfin$alt,type=l,col=red) Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting two graphs on the same figure
On Jan 14, 2013, at 3:32 PM, Lily Arias Chauca wrote: I want to add a line that represents the relationship between x and y to a strip chart, I've tried the following functions: par(new=TRUE) points(x,y) lines(x,y) but nothing works, I get the strip chart but line doesn't show up. Here is my function: stripchart(hydfin$exp ~ hydfin$alt, vert = TRUE, pch = 1, method = jitter, jit = 0.05, xlab = Elevation, ylab = expression(paste(delta^{2}, H))) points(1:3, hydfin.M, pch = 16, cex = 1.5) arrows(1:3, hydfin.M, 1:3, hydfin.M + hydfin.se, lwd = 1.5, angle = 90, length = 0.1) arrows(1:3, hydfin.M, 1:3, hydfin.M - hydfin.se, lwd = 1.5, angle = 90, length = 0.1) par(new=TRUE) lines(hydfin$exp, hydfin$alt,type=l,col=red) You are probably not plotting to the right coordinates. (You are reversing the x and y roles.) Please include the output of dput(head(hydfin)) -- David Winsemius 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.
[R] error in for loop in function (object not found)
Hi all, I have attached the function file (revisedfunction) and the list of station IDs (StationIDs) in .pdf format. I have written a function to perform various operations on the station IDs in two groups. The first 6 station IDs require one less step than the remaining 68 station IDs. The file referenced at the beginning of the function is the file containing the StationIDs. file = /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/example_setofstationsassociatedtosamegage.csv xynowget - xygetN(file, hasHeader = TRUE, separator =,) Error in is.data.frame(x) : object 'Sample' not found Can you assist me in fixing the attached function file? Thank-you. Irucka Embry span id=m2wTlpfont face=Arial, Helvetica, sans-serif size=2 style=font-size:13.5px___BRGet the Free email that has everyone talking at a href=http://www.mail2world.com target=newhttp://www.mail2world.com/abr font color=#99Unlimited Email Storage #150; POP3 #150; Calendar #150; SMS #150; Translator #150; Much More!/font/font/span__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Random Forest Error for Factor to Character column
Hi, Can someone please offer me some guidance? I imported some data. One of the columns called JOBTITLE when imported was imported as a factor column with 416 levels. I subset the data in such a way that only 4 levels have data in JOBTITLE and tried running randomForest but it complained about JOBTITLE having more than 32 categories. I know that is the limit in randomForest but I guess I don't understand enough about factors because I thought by subsetting the data this no longer would be an issue. BTW I can run randomForest on this dataset if I exclude JOBTITLE. So I then converted that column to a character vector: TRAINSET$JOBTITLE-as.character(TRAINSET$JOBTITLE) I ran Random Forest and got the below error. Why isn't this working? What do I need to do to get this working? library(randomForest) FOREST_model - randomForest(as.factor(TARGET)~., data=trainset, mtry=4, ntree=1000, +importance=TRUE, do.trace=100) Error in randomForest.default(m, y, ...) : NA/NaN/Inf in foreign function call (arg 1) In addition: Warning message: In data.matrix(x) : NAs introduced by coercion Your help will be greatly appreciated. Dan [[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] error in for loop in function (object not found)
Nothing attached. Please read the Webpage link and the Posting Guide more thoroughly. -- David. On Jan 14, 2013, at 5:31 PM, Irucka Embry wrote: Hi all, I have attached the function file (revisedfunction) and the list of station IDs (StationIDs) in .pdf format. I have written a function to perform various operations on the station IDs in two groups. The first 6 station IDs require one less step than the remaining 68 station IDs. The file referenced at the beginning of the function is the file containing the StationIDs. file = /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/example_setofstationsassociatedtosamegage.csv xynowget - xygetN(file, hasHeader = TRUE, separator =,) Error in is.data.frame(x) : object 'Sample' not found Can you assist me in fixing the attached function file? Thank-you. Irucka Embry snip R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 https://stat.ethz.ch/mailman/listinfo/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] Random Forest Error for Factor to Character column
After you subset the data, did you redeclare the factor? If not then R still thinks it has the potential for all those levels. TRAINSET$JOBTITLE - factor(TRAINSET$JOBTITLE) I hope this helps Andrew On Tuesday, January 15, 2013, Lopez, Dan wrote: Hi, Can someone please offer me some guidance? I imported some data. One of the columns called JOBTITLE when imported was imported as a factor column with 416 levels. I subset the data in such a way that only 4 levels have data in JOBTITLE and tried running randomForest but it complained about JOBTITLE having more than 32 categories. I know that is the limit in randomForest but I guess I don't understand enough about factors because I thought by subsetting the data this no longer would be an issue. BTW I can run randomForest on this dataset if I exclude JOBTITLE. So I then converted that column to a character vector: TRAINSET$JOBTITLE-as.character(TRAINSET$JOBTITLE) I ran Random Forest and got the below error. Why isn't this working? What do I need to do to get this working? library(randomForest) FOREST_model - randomForest(as.factor(TARGET)~., data=trainset, mtry=4, ntree=1000, +importance=TRUE, do.trace=100) Error in randomForest.default(m, y, ...) : NA/NaN/Inf in foreign function call (arg 1) In addition: Warning message: In data.matrix(x) : NAs introduced by coercion Your help will be greatly appreciated. Dan [[alternative HTML version deleted]] __ R-help@r-project.org javascript:; mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Andrew Robinson Director (A/g), ACERA Department of Mathematics and StatisticsTel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia (prefer email) http://www.ms.unimelb.edu.au/~andrewpr Fax: +61-3-8344-4599 http://www.acera.unimelb.edu.au/ FAwR: http://www.ms.unimelb.edu.au/~andrewpr/FAwR/ SPuR: http://www.ms.unimelb.edu.au/spuRs/ [[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] tabstop in graphics
On Jan 14, 2013, at 1:51 PM, Berry Boessenkool wrote: Hi, I'm curious about Tab stops in graphics: plot(1) text(1.2, 1.2, Char\nMoreChar) works fine, but text(1.2, 0.8, Char\tMoreChar) doesn't. Exporting with pdf tells me that the sign width is unknown. On my machine I get an empty box. Arguably your machines behavior is more correct. Scraping from pdf files that are arranged in columns produces some amusing results. In the Mac world, recent versions have had an option-select that allows one to capture columnar data, but before that people who did not have full version of Acrobat (not the Reader) were out of luck. I'm not into informatics, so I don't know how a tabstop actually works. Highly software dependent. In the old days there were metal fins that could be moved up to stop the typewriter carriage. The `print.data.frame` function examines the maximum width for a column and then pads with sufficient leading spaces to get the colunms to line up. Is this at all possible in graphical commands as it is in write.table and the like? `write.table` has no notion of tabs-widths. They are just used as separators and you are seeing some software viewer's behavior. I'm e.g. writing a legend with two colums. I solve this with addingvia paste to each element of the first column in one legend command, and then adding a second legend more to the right with the second column with bty=n. That's OK for the results, but not elegant programming... paste(ColumnOne, \t, ColumnTwo, sep=) would be more what I'd intuitively use. There is a phantom() function in plotmath that you could use to insert the proper width to column justify and then pad the missing space. Or you could use one of the Latex output devices. I get the sense that ggplot2 has the most code related to constructing legends but yours seems more like an annotation. Take a look at tableGrob in pkg::latticeExtra. -- David Winsemius 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.
Re: [R] error in for loop in function (object not found)
Hi David, thanks for letting me know about the missing attachments. This is the code for the function: xygetN - function(file, hasHeader = TRUE, separator = ,) { totalPath - paste(file, sep = ) tmp - read.csv(totalPath, header = hasHeader, sep = separator, fill = TRUE, comment.char = #, as.is = TRUE, stringsAsFactors = FALSE) retval - as.data.frame(tmp, stringsAsFactors = FALSE) if (ncol(retval) == 2) { names(retval) - c(x, y) } else if (ncol(retval) == 3) { names(retval) - c(x, y, lat_00600) } else if (ncol(retval) == 4) { names(retval) - c(x, y, lat_00600, lon_00600) } retval$y - as.numeric(retval$y) write.csv(Sample, file = /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/example_setofstationsassociatedtosamegages.csv) x - retval[,1] y - retval[,2] filenwissample - /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/da ta/Sample/nwis_wqdata_sc_n.csv for(i in seq(along=x[1:6])) { Sample - getSampleDataFromFilecustom(filenwissample, hasHeader = TRUE, separator =,) Sample - subset(Sample,station_id==i) Sample - subset(Sample, select=c(date, remark, value)) write.csv(Sample, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/da ta/SampleOutputFromNWIS/.nitrogen)) filesnwis - list.files(pattern=/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer -2012-Work/EGRET/data/SampleOutputFromNWIS/.nitrogen$) for(l in seq(along=filesnwis)) { Sample - getCustomSampleDataFromFile(filesnwis[l], hasHeader = TRUE, separator =,) #getJulian(2000-10-01) Sample - subset(Sample,Julian=55060) #getJulian(2004-09-30) Sample - subset(Sample,Julian=56520) Sample-removeDuplicates(Sample) summary(Sample) length(Sample$Date) } fileinfoN -/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ data/Info/info_n.csv INFO- getMetaDataFromFile(fileinfoN) for(g in seq(along=filesnwis)) { INFO- subset(INFO,site.no==g) } filesDV - list.files(pattern=/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer -2012-Work/EGRET/data/DVfromNWIS/DVfromNWIS_pooledforallMRB2sites/.rdb.g z$) for(m in seq(along=y)) { for(k in seq(along=filesDV)) { Daily - getDailyDataFromFileCustom(filesDV[k]) #getJulian(2000-10-01) Daily - subset(Daily,Julian=55060) #getJulian(2004-09-30) Daily - subset(Daily,Julian=56520) summary(Daily) Sample-mergeReport() } } modelEstimation(localDaily = Daily,localSample = Sample, localINFO = INFO, windowY=10, windowQ=2, windowS=0.5,minNumObs=10,minNumUncen=10, env=parent.frame()) INFO-setPA(window = 4) annualSeries-makeAnnualSeries() AnnualResults-setupYears() AnnualResults tableResults(localAnnualResults = AnnualResults, localINFO = INFO, qUnit = 1, fluxUnit = 13) yearPoints-c(2001,2002,2003,2004) tableChange(localAnnualResults = AnnualResults, localINFO = INFO, fluxUnit = 13, yearPoints) AnnualResults- setupYears(paLong = 3, paStart = 10, localDaily = Daily) yield - AnnualResults$Flux/INFO$drainSqKm write.table(INFO, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/Calibration_Results/.AnnualResults), append=T,col.names= NA, sep = ,) write.table(AnnualResults, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/Calibration_Results/.AnnualResults), append=T,col.names= NA, sep = ,) write.table(yield, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/Calibration_Results/.AnnualResults), append=T,col.names= NA, sep = ,) AnnualResults- setupYears(paLong = 3, paStart = 1, localDaily = Daily) yield - AnnualResults$Flux/INFO$drainSqKm write.table(AnnualResults, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/Calibration_Results/.AnnualResults), append=T,col.names= NA, sep = ,) write.table(yield, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/Calibration_Results/.AnnualResults), append=T,col.names= NA, sep = ,) AnnualResults- setupYears(paLong = 3, paStart = 4, localDaily = Daily) yield - AnnualResults$Flux/INFO$drainSqKm write.table(AnnualResults, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/Calibration_Results/.AnnualResults), append=T,col.names= NA, sep = ,) write.table(yield, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/Calibration_Results/.AnnualResults), append=T,col.names= NA, sep = ,) AnnualResults- setupYears(paLong = 3, paStart = 7, localDaily = Daily) yield - AnnualResults$Flux/INFO$drainSqKm write.table(AnnualResults, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/Calibration_Results/.AnnualResults), append=T,col.names= NA, sep = ,) write.table(yield, file=paste(i , /home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca libration/Calibration_Results/.AnnualResults), append=T,col.names= NA, sep = ,) }
[R] Optical Mark Recognition
Hey all, Has anyone ever altered an R package for image analysis to do optical mark recognition? I'm trying to find a way to semi-automate data entry of several thousand paper health surveys that are predominantly composed of check boxes. All the boxes are uniform size and shape, so it seems as if it should be possible to alter a package to recognize the boxes and output a 0 or 1 to correspond to whether the box is empty or not. From there, I could write if/then statements to convert the output into the relevant answers to the questions in the survey, and export it for analysis. I've been playing around with imageHTS and EBImage, but haven't been able to alter the configuration files that come with the packages for use in identifying cells, electrophorisis screens, etc. The surveys all have a line down the middle and an ID number on each page, which should serve as anchors for the program as it identifies the boxes. My question is whether or not anyone has ever tried anything like this, or if you even think it can be done. Having spent a week on this, I'm starting to doubt my initial assumption that it should be an easy alteration to make. Thanks for any input you might have, Kirsten Simmons -- Kirsten Simmons, MPH Polymath interested in productivity, how ideas spread, gardening, marketing, entrepreneurship and models of social networks and disease transmission [[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] Month name in English, not R running language
When ploting a timeseries, the months are shown with abbreviation in the current language of the system. For example, x - seq(from=as.Date(2000-04-01), length.out=100, by=1) y - rnorm(length(x), 5,2) plot(x, y) Show for me avi mai jui jul as I use R with French language localization. I see in the Windows FAQ how to completely change the language of R, but I search rather a way to change it for just the next command (also I run R in MacOS !). The solution will be to make myself the axis... except if someone has the trick to do it more easily. To generate the axis myself, it is not so simply to get one tick by month. I try axTicks(1) but it gives 5 ticks rather than 4 and as.Date(axTicks(1), 1970-01-01) [1] 2000-04-13 2000-05-03 2000-05-23 2000-06-12 2000-07-02 Is not what I expected. Plot with date object seems to use a special way to generate ticks. Thanks a lot Marc -- __ Marc Girondot, Pr Laboratoire Ecologie, Systématique et Evolution Equipe de Conservation des Populations et des Communautés CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079 Bâtiment 362 91405 Orsay Cedex, France Tel: 33 1 (0)1.69.15.72.30 Fax: 33 1 (0)1.69.15.73.53 e-mail: marc.giron...@u-psud.fr Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html Skype: girondot __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Month name in English, not R running language
Hello, ?Sys.setlocale HTH, Pascal Le 15/01/2013 15:28, Marc Girondot a écrit : When ploting a timeseries, the months are shown with abbreviation in the current language of the system. For example, x - seq(from=as.Date(2000-04-01), length.out=100, by=1) y - rnorm(length(x), 5,2) plot(x, y) Show for me avi mai jui jul as I use R with French language localization. I see in the Windows FAQ how to completely change the language of R, but I search rather a way to change it for just the next command (also I run R in MacOS !). The solution will be to make myself the axis... except if someone has the trick to do it more easily. To generate the axis myself, it is not so simply to get one tick by month. I try axTicks(1) but it gives 5 ticks rather than 4 and as.Date(axTicks(1), 1970-01-01) [1] 2000-04-13 2000-05-03 2000-05-23 2000-06-12 2000-07-02 Is not what I expected. Plot with date object seems to use a special way to generate ticks. Thanks a lot Marc __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Month name in English, not R running language
It works perfectly: Sys.setlocale(category = LC_TIME, locale=en_GB.UTF-8) [1] en_GB.UTF-8 x - seq(from=as.Date(2000-04-01), length.out=100, by=1) y - rnorm(length(x), 5,2) plot(x, y) Sys.setlocale(category = LC_TIME, locale=) [1] fr_FR.UTF-8 Thanks a lot Marc (I post the solution on the list as I have had some difficulties to find the good format for locale parameter. It could help others) Le 15/01/13 07:41, Pascal Oettli a écrit : Hello, ?Sys.setlocale HTH, Pascal Le 15/01/2013 15:28, Marc Girondot a écrit : When ploting a timeseries, the months are shown with abbreviation in the current language of the system. For example, x - seq(from=as.Date(2000-04-01), length.out=100, by=1) y - rnorm(length(x), 5,2) plot(x, y) Show for me avi mai jui jul as I use R with French language localization. I see in the Windows FAQ how to completely change the language of R, but I search rather a way to change it for just the next command (also I run R in MacOS !). The solution will be to make myself the axis... except if someone has the trick to do it more easily. To generate the axis myself, it is not so simply to get one tick by month. I try axTicks(1) but it gives 5 ticks rather than 4 and as.Date(axTicks(1), 1970-01-01) [1] 2000-04-13 2000-05-03 2000-05-23 2000-06-12 2000-07-02 Is not what I expected. Plot with date object seems to use a special way to generate ticks. Thanks a lot Marc -- __ Marc Girondot, Pr Laboratoire Ecologie, Systématique et Evolution Equipe de Conservation des Populations et des Communautés CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079 Bâtiment 362 91405 Orsay Cedex, France Tel: 33 1 (0)1.69.15.72.30 Fax: 33 1 (0)1.69.15.73.53 e-mail: marc.giron...@u-psud.fr Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html Skype: girondot __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Confidence intervel for regression line
On 01/15/2013 09:17 AM, li li wrote: Hi all, For the simple linear regression, I want to find the input x value so that the lower confidnece limit is a specific number, say 0.2. In other words, I want to find the value of x so that the lower confidence bound crosses the horizontal line 0.2. Is there a simple way (an R function) that can do this? I don't know of an extant R function, but it's simple enough. You just need to solve a quadratic equation. Here's my effort at writing an R function to effect this: xForCb - function(model,level,cb) { s2 - summary(model)$sigma^2 Cov - summary(model)$cov.unscaled*s2 ccc - coef(model) df - model$df.residual q - qt(level,df) A - ccc[2]^2 - q^2*Cov[2,2] B - 2*((cb-ccc[1])*(-ccc[2]) - q^2*Cov[1,2]) C - (cb - ccc[1])^2 - q^2 * Cov[1,1] r1 - (-B + sqrt(B^2 - 4*A*C))/(2*A) r2 - (-B - sqrt(B^2 - 4*A*C))/(2*A) y1 - ccc[1] + ccc[2]*r1 y2 - ccc[1] + ccc[2]*r2 res - c(r1,r2)[order(c(y2,y1))] names(res) - c(x.for.lb,x.for.ub) res } E.g. of use: set.seed(42) x- seq(0,10,length=101) y- 1.5 + 2.5*x + rnorm(101,0,5) fit - lm(y ~ x) pfit - predict(fit,interval=confidence,level=0.90) plot(x,y) lines(x,pfit[,fit]) lines(x,pfit[,upr],col=red) lines(x,pfit[,lwr],col=green) xx - xForCb(fit,0.95,5) abline(v=xx,col=blue) abline(h=5,col=blue) cheers, Rolf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.