Hi, I am trying to runn a age-period-cohort model, but here is what I am having problem with, hope you can help me! This is what I am trying to do: sumzero_a<-((A-min(A))/5+1) - mean((A-min(A))/5+1) where A is my age variable (numeric, the mid-point of a five-year age group), but I got the following error: Error in min(..., na.rm = na.rm) : invalid 'mode' of argument I am pretty sure I have the variable "A" in my data, can you see why this happens? Thanks. Yanyan =====================================Yanyan Gong, MSc Senior Research Associate Ontario Cervical Screening Program Cancer Care Ontario 620 University Ave, 11th Floor Toronto ON M5G 2L7 (416) 971-9800, ext 3304 yanyan.gong@cancercare.on.ca ===================================== This e-mail message (and any attachments) may contain confid...{{dropped}}
On Mon, 2006-04-17 at 10:17 -0400, Gong, Yanyan wrote:> Hi, I am trying to runn a age-period-cohort model, but here is what I am > having problem with, hope you can help me! > > This is what I am trying to do: > sumzero_a<-((A-min(A))/5+1) - mean((A-min(A))/5+1) where A is my age > variable (numeric, the mid-point of a five-year age group), but I got the > following error: > > Error in min(..., na.rm = na.rm) : invalid 'mode' of argument > > I am pretty sure I have the variable "A" in my data, can you see why this > happens? > > Thanks. > > Yanyan'A' does exist or you should get something like the following:> min(A)Error in min(A) : object "A" not found More than likely, 'A' is not a numeric vector. It could be a character vector, a list or some other non-atomic data type. It is not a factor, lest you get something like the following: Error in Summary.factor(..., na.rm = na.rm) : min not meaningful for factors See ?is.atomic for some additional information. Without your code, it would be difficult to ascertain how 'A' is created. However, consider the following example:> L <- LETTERS> L[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" [18] "R" "S" "T" "U" "V" "W" "X" "Y" "Z"> min(L)Error in min(..., na.rm = na.rm) : invalid 'mode' of argument> mode(L)[1] "character" I would use: str(A) or mode(A) to see what 'A' is. That should give you a hint. HTH, Marc Schwartz
Hi Marc, I figured out the problem, when I ran a glm model earlier, I used A as it's name. Now the program is working.., a good lesson to learn. Thank you so much for you help! Yanyan -----Original Message----- From: Marc Schwartz (via MN) [mailto:mschwartz@mn.rr.com] Sent: Monday, April 17, 2006 2:20 PM To: Gong, Yanyan Subject: RE: [R] help On Mon, 2006-04-17 at 13:40 -0400, Gong, Yanyan wrote:> Hi Marc, > > I checked, A is a numeric field, here is my data frame: > > `data.frame': 91 obs. of 4 variables: > $ A: num 22.5 27.5 32.5 37.5 42.5 47.5 52.5 57.5 62.5 67.5 ... > $ P: int 1970 1970 1970 1970 1970 1970 1970 1970 1970 1970 ... > $ D: int 55 180 303 349 437 489 386 383 334 229 ... > $ Y: int 1602127 1340887 1122499 1043250 1005940 926649 766054 > 700415 613063 537763 ... > > But when I do "min(A)", I got "Error in min(..., na.rm = na.rm) : > invalid 'mode' of argument". I checked mode(A), it says it is a > "list". I am sure A was created as a numeric variable, and the program > used to work. After I changed the working directory, I kept getting > problems. The weird thing is the following works: > > sumzero_p<-((P-min(P))/5+1) - mean((P-min(P))/5+1) > sumzero_c<-((cohort-min(cohort))/5+1) - mean((cohort-min(cohort))/5+1) > > In which, p is numeric variable for period, cohort is another numeric > variable for birth year. > > Hope this gives you a hint of my problem. Thanks very much! > > Sincerely. > > YanyanYep...'A' is numeric, but it is a column in a data frame. You might want to review An Introduction to R, specifically section 6 and forward regarding the means by which one refers to columns in a data frame. http://cran.r-project.org/doc/manuals/R-intro.html#Lists-and-data-frames I would check to see which 'P' is being referred to in your code above. Did you use: attach(data.frame) at some point? If not, then 'P' is _not_ the P in your data frame, but some other locally created 'P'. You can use: ls() to list the current objects that you have created. If you don't want to use attach/detach, you can use: data.frame$A to refer to 'A'. Similar syntax for the other columns. Also, remember that R is case sensitive, so: p != P If you elect to use attach(), be sure that you use the complementary detach() as well. BTW, using 'data.frame' as the name for your data frame is bad, since it is also the name of a function, data.frame(). In most cases, R will be able to tell the difference, but you risk getting bitten by an occasion where it cannot. Lastly, while I don't mind helping, when replying to a post on the list, please respond back to the list as well (ie. Reply to All), so that the thread integrity is maintained to help others via the list archive and to enable others to respond. HTH, Marc This e-mail message (and any attachments) may contain confid...{{dropped}}
Hi, I was trying to calculate an age adjusted rate for which we have the formula as sum(weight*rate)/sum(weight). I am using the framingham dataset called fram here.I cant figure out how I could change the logical statement I have for the standard dataset (in red) to calculate weight and calculating the wevents and atrisk(in red) Below is my code: attach(fram) dset1<-cbind(AGE,BMI,DEATH) BMIGRP1<-cut(BMI,breaks=c(14,20,25,57),right=TRUE) levels(BMIGRP1) BMIGRP<-as.numeric(BMIGRP1) AGEGRP<-floor(AGE/10)-2 dset<-cbind(AGEGRP,BMIGRP,DEATH) std<-cbind(AGEGRP) maxage<-max(dset[,1]) minage<-min(dset[,1]) maxcls<-max(dset[,2], na.rm=T) mincls<-min(dset[,2],na.rm=T) nage<-maxage-minage+1 nclass<-maxcls-mincls+1 nsub<-nrow(dset) weight <- matrix(0,nage,1) for ( i in minage:maxage ) weight[i-minage+1,1] = sum(std=i) atrisk = matrix(0,nclass,nage) wevents = matrix(0,nclass,nage) for( i in minage : maxage) for( j in mincls : maxcls) atrisk[j-mincls+1,i-minage+1] sum((dset[,1]=i)& (dset[,2]=j)) wevents[j-mincls+1,i-minage+1] sum((dset[,1]=i)& (dset[,2]=j)&(dset[,3]=1)) #vtit = char(t(mincls:maxcls),5,0) // {Total}; #htit = {'at risk' 'events' 'rate/1000'}; atrisk2 = atrisk // atrisk[+,1:nage]; event2 = wevents // wevents[+,1:nage]; atrisk3 = choose(atrisk2=0,1,atrisk2); rate = event2/atrisk3; this was done using sas macro. Thanks so much! --------------------------------- [[alternative HTML version deleted]]
Anamika Chaudhuri <canamika16 <at> yahoo.com> writes:> I was trying to calculate an age adjusted rate for which we have theformula as> sum(weight*rate)/sum(weight). I am using the framingham dataset called framhere.I cant figure out how I> could change the logical statement I have for the standard dataset (in red)to calculate weight and> calculating the wevents and atrisk(in red)... lengthy code follows If you want to get an answer, provide as good subject line and a data set (e.g. part of Framingham). Nobody loves to wade through so many lines of code without the chance to check out what is intended. Dieter
Hi I agree with Dieter. I think you are probably looking for some aggregation function (aggregate, tapply, by,...), but it is only a guess. Sometimes it help me to answer my questions myself before I actually post it to Rhelp when I try to elaborate an example using artificial simple data for others to understand what I am trying to do and how I fail. HTH Petr On 27 Apr 2006 at 6:20, Dieter Menne wrote: To: r-help at stat.math.ethz.ch From: Dieter Menne <dieter.menne at menne-biomed.de> Date sent: Thu, 27 Apr 2006 06:20:44 +0000 (UTC) Subject: Re: [R] help> Anamika Chaudhuri <canamika16 <at> yahoo.com> writes: > > > I was trying to calculate an age adjusted rate for which we have > > the > formula as > > sum(weight*rate)/sum(weight). I am using the framingham dataset > > called fram > here.I cant figure out how I > > could change the logical statement I have for the standard dataset > > (in red) > to calculate weight and > > calculating the wevents and atrisk(in red) > > ... lengthy code follows > > If you want to get an answer, provide as good subject line and a data > set (e.g. part of Framingham). Nobody loves to wade through so many > lines of code without the chance to check out what is intended. > > Dieter > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
Dear Sir, I’am a French Student. I’am a new user of the « R » Software. I don’t success to import data from Excel spreadsheet either using the function (read.table) and the function (Rodbc). In addition, I don’t understand very well the help of the R Software. Could you please help me and give a simple numerical example using this procedure : read.table(file, header = FALSE, sep = "", quote = "\"'", dec = ".", row.names, col.names, as.is = FALSE, na.strings = "NA", colClasses = NA, nrows = -1, skip = 0, check.names = TRUE, fill = !blank.lines.skip, strip.white = FALSE, blank.lines.skip = TRUE, comment.char = "#", allowEscapes = FALSE, flush = FALSE) read.csv(file, header = TRUE, sep = ",", quote="\"", dec=".", fill = TRUE, ...) read.csv2(file, header = TRUE, sep = ";", quote="\"", dec=",", fill = TRUE, ...) read.delim(file, header = TRUE, sep = "\t", quote="\"", dec=".", fill = TRUE, ...) read.delim2(file, header = TRUE, sep = "\t", quote="\"", dec=",", fill = TRUE, ...) This is my e-mail: karimmgo@laposte.net Accédez au courrier électronique de La Poste : www.laposte.net ; 3615 LAPOSTENET (0,34 €/mn) ; tél : 08 92 68 13 50 (0,34€/mn) [[alternative HTML version deleted]]
Hi as you are raised on Excel probably the best way for you would be: Start R Select the reagion in Excel you want to copy, preferably with a line of column headers Press Ctrl-C In R write my.first.data<-read.delim("clipboard") and you transferred your data to do analysis. However I recommend you to read some tutorials mentioned on CRAN or elsewhere and start with examples from these tutorials. As regarding the help pages (or man pages) they usually have some examples which you can copy to R console and see the results. Don't be afraid, you probably will not harm yourself or your computer by such trial and error attempts. ;-) HTH Petr On 17 May 2006 at 9:59, karim99.karim wrote: Date sent: Wed, 17 May 2006 09:59:32 +0200 From: "karim99.karim" <karim99.karim at laposte.net> To: "R-help" <R-help at stat.math.ethz.ch> Subject: [R] help> Dear Sir, > > I?am a French Student. I?am a new user of the ? R ? Software. I don?t > success to import data from Excel spreadsheet either using the > function (read.table) and the function (Rodbc). In addition, I don?t > understand very well the help of the R Software. Could you please help > me and give a simple numerical example using this procedure : > read.table(file, header = FALSE, sep = "", quote = "\"'", dec = ".", > row.names, col.names, as.is = FALSE, na.strings = "NA", colClasses > NA, nrows = -1, skip = 0, check.names = TRUE, fill > !blank.lines.skip, strip.white = FALSE, blank.lines.skip = TRUE, > comment.char = "#", allowEscapes = FALSE, flush = FALSE) > read.csv(file, header = TRUE, sep = ",", quote="\"", dec=".", fill > TRUE, ...) read.csv2(file, header = TRUE, sep = ";", quote="\"", > dec=",", fill = TRUE, ...) read.delim(file, header = TRUE, sep = "\t", > quote="\"", dec=".", fill = TRUE, ...) read.delim2(file, header > TRUE, sep = "\t", quote="\"", dec=",", fill = TRUE, ...) > > > This is my e-mail: karimmgo at laposte.net > > > Acc?dez au courrier ?lectronique de La Poste : www.laposte.net ; 3615 > LAPOSTENET (0,34 ?/mn) ; t?l : 08 92 68 13 50 (0,34?/mn) > > > > [[alternative HTML version deleted]] > >Petr Pikal petr.pikal at precheza.cz