Re: [R] 'singular gradient matrix? when using nls() and how to make the program skip nls( ) and run on
On Wed, Sep 05, 2007 at 04:43:19PM -0700, Yuchen Luo wrote: Dear friends. I use nls() and encounter the following puzzling problem: I have a function f(a,b,c,x), I have a data vector of x and a vectory y of realized value of f. Case1 I tried to estimate c with (a=0.3, b=0.5) fixed: nls(y~f(a,b,c,x), control=list(maxiter = 10, minFactor=0.5 ^2048),start=list(c=0.5)). The error message is: number of iterations exceeded maximum of 10 Case2 I then think maybe the value of a and be are not reasonable. So, I let nls() estimate (a,b,c) altogether: nls(y~f(a,b,c,x), control=list(maxiter = 10, minFactor=0.5 ^2048),start=list(a=0.3,b=0.5,c=0.5)). The error message is: singular gradient matrix at initial parameter estimates. This is what puzzles me, if the initial parameter of (a=0.3,b=0.5,c=0.5) can create 'singular gradient matrix', then why doesn't this 'singular gradient matrix' appear in Case1? I have tried to change the initial value of (a,b,c) around but the problem persists. I am wondering if there is a way out. My another question is, I need to run 220 of nls() in my program with different y and x. When one of the nls() encounter a problem, the whole program stops. In my case, the 3rd nls() runs into a problem. I would still need the program to run the remaining 217 nls( )! Is there a way to make the program skip the problematic nls() and complete the ramaining nls()'s? ?try Your help will be highly appreciated! Yuchen Luo [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] negative value for AIC and BIC
Oliver, I am attaching an HTML document in which I have plotted -2Log(x) vs. x. If you examine the plot you will see that -2Log(x) can be negative. Since -2Log(x) is part of AIC and BIC, AIC and BIC can be negative. John John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics Baltimore VA Medical Center GRECC, University of Maryland School of Medicine Claude D. Pepper OAIC, University of Maryland Clinical Nutrition Research Unit, and Baltimore VA Center Stroke of Excellence University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) [EMAIL PROTECTED] Hannu Kahra [EMAIL PROTECTED] 09/07/07 4:32 AM Olivier, type ?AIC and have a look at the description Description: Generic function calculating the Akaike information criterion for one or several fitted model objects for which a log-likelihood value can be obtained, according to the formula -2*log-likelihood + k*npar, where npar represents the number of parameters in the fitted model, and k = 2 for the usual AIC, or k = log(n) (n the number of observations) for the so-called BIC or SBC (Schwarz's Bayesian criterion). AIC = -2*log-likelihood + k*npar can be negative as SBC, too. Hannu On 9/7/07, Olivier MARTIN [EMAIL PROTECTED] wrote: Hi all, I obtained negative values for AIC and BIC criteria for a particular model that I have developped... I don't remember to have negative values for these crietria for others applications, so I am a little suprised... Could anyone tell me if something is wrong or his conclusion concerning my model? Best regards, Olivier. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. y = -2Log[x] Out[20]= -2 Log[x] In[22]:= RowBox[{Plot, [, RowBox[{y, ,, RowBox[{{, RowBox[{x, ,, 0.01, ,, 4}], }}], ,, AxesLabel#62754; {x, -2Log[x]}}], ]}] [Graphics:HTMLFiles/-2Log_10.gif] Out[22]= -Graphics- __ Created by [1]Mathematica (September 7, 2007) References 1. http://www.wolfram.com/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Running geeglm unstructured corstr
Dear Niccolo, a) your example program works for me and on a Pentium 4, 3 Ghz, 1GB ram, The model fit uses user system elapsed 146.920.76 143.32 library(geepack) set.seed(299) header - rep.int(seq(1:615),sample(seq(1:19),size=615,replace=T)) inr - rlnorm(length(header),0.8434359,0.3268392) group_cod - sample(c(0,1),size=length(header),replace=T) inside - sample(c(0,1),size=length(header),replace=T) gee.frame - data.frame(header,inr,group_cod,inside) geeglm.model- geeglm(inside~group_cod,family=binomial, data=gee.frame ,id=header,corstr=unstructured) Version of_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 5.1 year 2007 month 06 day27 svn rev42083 language R version.string R version 2.5.1 (2007-06-27) b) for costr= ar1 In my dataset I also have a variable weeks, that I use to specify waves in the geeglm. When I use this, the output for an autoregressive gee model gives me only the estimates, when I don't use it everything's alright. The problem's that I have unbalanced observations, so the use of waves could take this into account while estimating parameters. Is this a conflict between these options, or what? The argument waves should work in conjunction with the ar1 working correlation. Make sure that the observations are orderd wrt. cluster-id as it is said in ?geeglm for the 'id' argument c) if you build your own fixed-working correlation then there are two issues: 1) you must leave out clusters of size 1 in the construction of the zcor matrix: if the other clusters have the same size you can use geeglm with that zcor matrix Example: # using corstr=fixed the cluster with only 1 observation must be # left out from the construction of the zcor-vector. # the following example is for the case where clusters of size larger then 1 # have no missing observations and are of the same size library(geepack) data(seizure) ## Diggle, Liang, and Zeger (1994) pp166-168, compare Table 8.10 seiz.l - reshape(seizure, varying=list(c(base,y1, y2, y3, y4)), v.names=y, times=0:4, direction=long) seiz.l - seiz.l[order(seiz.l$id, seiz.l$time),] seiz.l$t - ifelse(seiz.l$time == 0, 8, 2) seiz.l$x - ifelse(seiz.l$time == 0, 0, 1) ## defining fixed correlation matrix cor.fixed - matrix(c(1, 0.5, 0.25, 0.125, 0.125, 0.5, 1, 0.25, 0.125, 0.125, 0.25, 0.25, 1, 0.5, 0.125, 0.125, 0.125, 0.5, 1, 0.125, 0.125, 0.125, 0.125, 0.125, 1), 5, 5) zcor - rep(cor.fixed[lower.tri(cor.fixed)], 59) g1 - geeglm(y ~ offset(log(t)) + x + trt + x:trt, id = id, data = seiz.l, family = poisson, corstr = fixed, zcor = zcor) #reducing clusters 1 ,3 and 58 to only one observation seiz.reduc-subset(seiz.l,!( (id==1 | id==3 | id==58) time0)) # zcor is only constructed for clusters with size larger than 1 n.larger.one-sum(table(seiz.reduc$id)1) zcor -c( rep(cor.fixed[lower.tri(cor.fixed)], n.larger.one)) g2- geeglm(y ~ offset(log(t)) + x + trt + x:trt, id = id, data = seiz.reduc, family = poisson, corstr = fixed, zcor = zcor) 2) if the clusters have different size than you must construct the zcor-matrix according to the missing structure, the usage of the wave-argument to specify the missing structure does not work. Example: # using corstr=fixed the for clusters with unbalanced number of observations # the wave argument does not work, the zcor-matrix must be constructed 'by-hand' library(geepack) data(seizure) ## Diggle, Liang, and Zeger (1994) pp166-168, compare Table 8.10 seiz.l - reshape(seizure, varying=list(c(base,y1, y2, y3, y4)), v.names=y, times=0:4, direction=long) seiz.l - seiz.l[order(seiz.l$id, seiz.l$time),] seiz.l$t - ifelse(seiz.l$time == 0, 8, 2) seiz.l$x - ifelse(seiz.l$time == 0, 0, 1) # transform time such that the initial time is 1 seiz.l$time-seiz.l$time+1 #taking only a subset of the data such the data are unbalanced wrt cluster -size set.seed(88) seiz-subset(seiz.l,!( (id==1 | id==3 | id==58) time2)) ## Construction of a fixed correlation matrix cor.fixed - matrix(c(1, 0.7, 0.5, 0.25, 0.12, 0.7, 1, 0.71, 0.125, 0.125, 0.5, 0.71, 1, 0.29, 0.123, 0.25, 0.125, 0.29, 1, 0.119, 0.120, 0.125, 0.123, 0.119, 1), 5, 5) # The zcor-vector is constructed only for times which exist in the data
[R] FW: variable format
Anybody? From: Cory Nissen Sent: Tue 9/4/2007 9:30 AM To: r-help@stat.math.ethz.ch Subject: variable format Okay, I want to do something similar to SAS proc format. I usually do this... a - NULL a$divisionOld - c(1,2,3,4,5) divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic), ncol=2, byrow=T) a$divisionNew[match(a$divisionOld, divisionTable[,1])] - divisionTable[,2] But how do I handle the case where... a$divisionOld - c(0,1,2,3,4,5) #no format available for 0, this throws an error. OR divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic, 6, East South Central, 7, West South Central, 8, Mountain, 9, Pacific), ncol=2, byrow=T) There are extra formats available... this throws a warning. Thanks Cory [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] SQL like function?
Others have already pointed out %in% but regarding your comment about SQL, you can use SQL to manipulate R data frames using the sqldf package which provides an interface to lower level RSQLite (and RMySQL in the future) routines. The following examples use SQLite underneath: DF - data.frame(observation = c(1,2,3,4,5)) ID - data.frame(ID = c(1, 3, 4)) library(sqldf) sqldf(select observation, observation in (select * from ID) `ID?` from DF) # or sqldf(select observation, observation in (1, 3, 4) `ID?` from DF) See home page at: http://sqldf.googlecode.com On 9/7/07, Takatsugu Kobayashi [EMAIL PROTECTED] wrote: Hi RUsers, I am wonder if I can search observations whose IDs matches any of the values in another vector, such as in MySQL. While I am learing MySQL for future database management, I appreciate if anyone could give me a hint. Suppose I have one 5*1 vector containing observation IDs and frequencies, and one 3*1 vector containing observation IDs. observation-c(1,2,3,4,5) ID-c(1,3,4) Then, I would like to program a code that returns a results showing matched observations like result: TRUE FALSE TRUE TRUE FALSE I am reading S programming, but I cannot find a way to do this. Thank you very much. Taka __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R survey package again
Hi R-users!! I have some trouble with the survey pakage and i would be very glad if you can give me an advice. I have a sample from a survey where household were interviewed. The sample has 4 criteria on which the stratification was based: REGION, SIZE OF HOUSEHOLD, SIZE OF LOCALITY, AGE OF HEAD OF HOUSEHOLD. Since i don't have the whole information in each cell of the cross region*sizehh*sizeloc*age i can't use the postStratify function from Survey package. Is that correct? (I think so but i need a competent answer) The only additional info that i have is the size of a cell from a 2*2 crossing (eg: I know the population size for all the strata defined by region*sizehh, region*sizeloc, sizeloc*age) so i have the behaviour of the population but in a 2 by 2 cross for each of these criteria. Now, i want to use this info but i don't know the proper way: could i use the svydesign function as here d- svydesign (id=~1, data=tabel, strata = c(region*sizehh,region*sizeloc.), nest=T) and then dd- poststratify(d, data.frame (region*size, region*sizeloc, ), population= data.frame(Nh region*sizehh, Nh region*sizeloc..) or raking would be better for this type of joint distribution while specifying in the svydesign strata =~ region+sizehh+sizeloc+agehhh. Thank you! Bye! - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] text in boxplots
Hi Greg, Actually, I'm using the scatterplot function in the car namespace. My understanding is that the scatterplot is turned into a boxplot when the x variable is a factor, but I can't see that in the code of the function. I've successfully modified the function to output regression stats (R^^2, etc.) with the method 'text', but I can't seem to get any text printed when the result of a call to scatterplot is a bunch of boxplots. I don't know how boxplots end up being generated (I like it though) in a call to car:scatterplot. The same data in ggobi would show the standard scatterplot with data aligned vertically in lines along the values of the x (factor) variable but car:scatterplot draws nice boxes around the data as a bonus. I guess I'll need to follow with some debugging tool. I find it odd that mtext works though. Or maybe some graphics parameter is set such that text doesn't show. Thanx Greg. -- View this message in context: http://www.nabble.com/text-in-boxplots-tf4394528.html#a12553104 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help on replacing values
Your columns are factors, not character strings. Use as.is = TRUE as an argument to read.table. Also its a bit dangerous to use T although not wrong. Its safer to use TRUE. On 9/7/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Dear List, I have a newbie question. I have read in a data.frame as follows: data = read.table(table.txt, header = T) data X1 X2 X3 X4 A AB AC AB AC B AB AC AA AB C AA AB AA AB D AA AB AB AC E AB AA AA AB F AB AA AB AC B AB AC AB AA I would like to replace AA values by BB in column X2. I have tried using replace() with no success, although I am not sure this is the right function. This is the code I have used: data$X2 - replace(data$X2, data$X2 ==AA,BB) Warning message: invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list, value = BB) What is wrong with the code? How can I get this done? how about changing AA values by BB in all 4 columns simultaneously? Actually this is a small example dataframe, the real one would have about 1000 columns. Extendind this, I found a similar thread dated July 2006 that used replace() on iris dataset, but I have tried reproducing it obtaining same warning message iris$Species - replace(iris$Species, iris$Species == setosa,NewName) Warning message: invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list, value = NewName) Thanks in advance your help, David __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] variable format
A matrix is for situations where every element is of the same class but your columns have different classes so use a data frame: DF - data.frame(a = 11:15, b = letters[1:5], stringsAsFactors = FALSE) subset(DF, a %in% 11:13) subset(DF, a %in% c(0, 11:13)) # same Suggest you review the Introduction to R manual and look at ?data.frame, ?subset and ?%in% On 9/4/07, Cory Nissen [EMAIL PROTECTED] wrote: Okay, I want to do something similar to SAS proc format. I usually do this... a - NULL a$divisionOld - c(1,2,3,4,5) divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic), ncol=2, byrow=T) a$divisionNew[match(a$divisionOld, divisionTable[,1])] - divisionTable[,2] But how do I handle the case where... a$divisionOld - c(0,1,2,3,4,5) #no format available for 0, this throws an error. OR divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic, 6, East South Central, 7, West South Central, 8, Mountain, 9, Pacific), ncol=2, byrow=T) There are extra formats available... this throws a warning. Thanks Cory [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help on replacing values
Dear List, I have a newbie question. I have read in a data.frame as follows: data = read.table(table.txt, header = T) data X1 X2 X3 X4 A AB AC AB AC B AB AC AA AB C AA AB AA AB D AA AB AB AC E AB AA AA AB F AB AA AB AC B AB AC AB AA I would like to replace AA values by BB in column X2. I have tried using replace() with no success, although I am not sure this is the right function. This is the code I have used: data$X2 - replace(data$X2, data$X2 ==AA,BB) Warning message: invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list, value = BB) What is wrong with the code? How can I get this done? how about changing AA values by BB in all 4 columns simultaneously? Actually this is a small example dataframe, the real one would have about 1000 columns. Extendind this, I found a similar thread dated July 2006 that used replace() on iris dataset, but I have tried reproducing it obtaining same warning message iris$Species - replace(iris$Species, iris$Species == setosa,NewName) Warning message: invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list, value = NewName) Thanks in advance your help, David __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Finding convex hull? [Broadcast]
From: Dong-hyun Oh Dear UseRs, I would like to know which function is the most efficient in finding convex hull of points in 3(or 2)-dimensional case? Functions for finding convex hull is the following: convex.hull (tripack), chull (grDevices), in.chull (sgeostat), convhulln (geometry), convexhull.xy (spatstat), calcConvexHull (PBSmapping). I also would like to know if there is a function that can be used for finding convex hull in multi-dimensional case, that is more than 3- dimension. If you had look a bit more carefully, you should have seen that convhulln (geometry) will handle more than 3 dimensions. Andy Thank you in advance. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Notice: This e-mail message, together with any attachments,...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ploting missing data
Try this: library(zoo) plot(na.approx(zoo(as.matrix(data[-1]), data[,1])), plot.type = single) See ?na.approx, ?plot.zoo, ?xyplot.zoo and vignette(zoo) On 9/7/07, Markus Schmidberger [EMAIL PROTECTED] wrote: Hello, I have this kind of dataframe and have to plot it. data - data.frame(sw= c(1,2,3,4,5,6,7,8,9,10,11,12,15), zehn = c(33.44,20.67,18.20,18.19,17.89,19.65,20.05,19.87,20.55,22.53,NA,NA,NA), zwanzig = c(61.42,NA,26.60,23.28,NA,24.90,24.47,24.53,26.41,28.26,NA,29.80,35.49), fuenfzig = c(162.51,66.08,49.55,43.40,NA,37.77,35.53,36.46,37.25,37.66,NA,42.29,47.80) ) The plot should have lines: lines(fuenfzig~sw, data=data) lines(zwanzig~sw, data=data) But now I have holes in my lines for the missing values (NA). How to plot the lines without the holes? The missing values should be interpolated or the left and right point directly connected. The function approx interpolates the whole dataset. Thats not my goal! Is there no plotting function to do this directly? Best Markus -- Dipl.-Tech. Math. Markus Schmidberger Ludwig-Maximilians-Universität München IBE - Institut für medizinische Informationsverarbeitung, Biometrie und Epidemiologie Marchioninistr. 15, D-81377 Muenchen URL: http://ibe.web.med.uni-muenchen.de Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help on replacing values
Thanks a lot Gabor, that was very helpful. All sorted now! Best David Your columns are factors, not character strings. Use as.is = TRUE as an argument to read.table. Also its a bit dangerous to use T although not wrong. Its safer to use TRUE. On 9/7/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Dear List, I have a newbie question. I have read in a data.frame as follows: data = read.table(table.txt, header = T) data X1 X2 X3 X4 A AB AC AB AC B AB AC AA AB C AA AB AA AB D AA AB AB AC E AB AA AA AB F AB AA AB AC B AB AC AB AA I would like to replace AA values by BB in column X2. I have tried using replace() with no success, although I am not sure this is the right function. This is the code I have used: data$X2 - replace(data$X2, data$X2 ==AA,BB) Warning message: invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list, value = BB) What is wrong with the code? How can I get this done? how about changing AA values by BB in all 4 columns simultaneously? Actually this is a small example dataframe, the real one would have about 1000 columns. Extendind this, I found a similar thread dated July 2006 that used replace() on iris dataset, but I have tried reproducing it obtaining same warning message iris$Species - replace(iris$Species, iris$Species == setosa,NewName) Warning message: invalid factor level, NAs generated in: `[-.factor`(`*tmp*`, list, value = NewName) Thanks in advance your help, David __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] text in boxplots
The posting guide (a link at the bottom of every e-mail from the list) suggests including a small example of what you are trying to do. Without an example, we have to guess at what you are trying to do. I am still guessing since you still did not include an example. It appears that part of the problem may be that the scatterplot function from the car package does not leave the user coordinate system in a state that matches intuitively with the data. Your call to text is probably placing the text outside of the plotting region where it is not visible (possibly even in someone elses cubicle/office). The mtext function is not affected as much by this since it uses a different coordinate system (based on the margins rather than the user coordinates). To place text on the plot, you need to find the cooresponding coordinates. There are a few different ways to do this: 1. use par('usr') to find out what the current user coordinates are and compute your coordinates based on that. 2. use par(usr=c(...)) to set the user coordinates to match where you want to plot. 3. use the locator function to interactively choose the locations and use the resulting coordinates. 4. use the cnvrt.coords function from the TeachingDemos package to convert from figure or device coordinates to the current user coordinate system. 5. contact the author of the function and ask him to set the user coordinates to something more intuitive before exiting and wait for the change. Look at the help for par for more information, specifically look at the 'usr' entry and possibly the 'xpd' entry if you want to add text to the marginal boxplots. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Yves Moisan Sent: Friday, September 07, 2007 5:05 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] text in boxplots Hi Greg, Actually, I'm using the scatterplot function in the car namespace. My understanding is that the scatterplot is turned into a boxplot when the x variable is a factor, but I can't see that in the code of the function. I've successfully modified the function to output regression stats (R^^2, etc.) with the method 'text', but I can't seem to get any text printed when the result of a call to scatterplot is a bunch of boxplots. I don't know how boxplots end up being generated (I like it though) in a call to car:scatterplot. The same data in ggobi would show the standard scatterplot with data aligned vertically in lines along the values of the x (factor) variable but car:scatterplot draws nice boxes around the data as a bonus. I guess I'll need to follow with some debugging tool. I find it odd that mtext works though. Or maybe some graphics parameter is set such that text doesn't show. Thanx Greg. -- View this message in context: http://www.nabble.com/text-in-boxplots-tf4394528.html#a12553104 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Automatic detachment of dependent packages
Dear All, When one loads certain packages, some other dependent packages are loaded as well. Is there some way of detaching them automatically when one detaches the first package loaded? For instance, library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto but detach(package:sqldf) search() [1] .GlobalEnvpackage:gsubfnpackage:proto [4] package:RSQLite package:DBI package:stats [7] package:graphics package:grDevices package:utils [10] package:datasets package:methods Autoloads [13] package:base The packages RSQLite DBI gsubfn proto were not detached. Thanks in advance, Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ploting missing data
Markus Schmidberger wrote: Hello, I have this kind of dataframe and have to plot it. data - data.frame(sw= c(1,2,3,4,5,6,7,8,9,10,11,12,15), zehn = c(33.44,20.67,18.20,18.19,17.89,19.65,20.05,19.87,20.55,22.53,NA,NA,NA), zwanzig = c(61.42,NA,26.60,23.28,NA,24.90,24.47,24.53,26.41,28.26,NA,29.80,35.49), fuenfzig = c(162.51,66.08,49.55,43.40,NA,37.77,35.53,36.46,37.25,37.66,NA,42.29,47.80) ) The plot should have lines: lines(fuenfzig~sw, data=data) lines(zwanzig~sw, data=data) But now I have holes in my lines for the missing values (NA). How to plot the lines without the holes? The missing values should be interpolated or the left and right point directly connected. The function approx interpolates the whole dataset. Thats not my goal! Is there no plotting function to do this directly? Just get rid of the NAs: lines(fuenfzig~sw, data=data, subset=!is.na(fuenfzig)) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] computing distance in miles or km between 2 street
Phil, If you have only a list of addresses and nothing else - i have to recognize i am lost. But if you have more info you can use a GIS software and it will calculate your distance automatically for all your addresses. To have your distance in miles or Km you need to have a projection in your data which will establish your units. The very basic principle is that for each address you have a set of coordinates, x, y and you actually use these to calculate distances. If your file is for exaple a point shape file (standard for ESRI ArcGIS products) you can very simply perform this task using either shortest driving route or as the crow flies - again depending on what other info you have in the file. A shape file is actually a group of files with with data attributes, projection info and so on - so even if you don't see xy coordinates, they actually are imbeded in the file. I suspect Mapquest or any other mapping web product has a database with all those addresses with xy coordinates. The user needs to know only the address and behind doors there is an sql process which selects particular addresses together with all the other attributes attached to it and calculate distances because it knows coordinates, a network of roads and so on. I am not sure this helps but at least maybe gives you some ideas where to look next. Monica Message: 53Date: Thu, 06 Sep 2007 14:42:32 -0400From: Philip James Smith [EMAIL PROTECTED]Subject: [R] computing distance in miles or km between 2 streetaddressesTo: [EMAIL PROTECTED]: [EMAIL PROTECTED]Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi R-ers: I need to compute the distance between 2 street addresses in either km or miles. I do not care if the distance is a shortest driving route or if it is as the crow flies. Does anybody know how to do this? Can it be done in R? I have thousands of addresses, so I think that Mapquest is out of the question! Please rely to: [EMAIL PROTECTED] Thank you!Phil Smith _ Hotmail®. NOW with 5GB storage. ration_HM_mini_5G_0907 [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] text in boxplots
6. set the reset.par argument to FALSE in calling scatterplot as it states in the documentation for scatterplot. (still look at the help on 'xpd' argment to par if you want to add text to the margins). Hi Greg, That seems to have done it partly. I set it to false once and then I could see some text afterwards, even with reset.par set to TRUE. About my not following posting guidelines, I'm sorry but I thought my question didn't require me to post code. I suspected graphics parameter to be off, so the question was why a difference between mtext and text. Also, I mentioned earlier that I had succeeded in writing text to the plot for regression stats (in the reg function of scatterplot.formula) where I did use what seem to be the normal tricks [e.g. par(usr)]. I couldn't figure out why setting new graph variables in the main scatterplot.formula function in the form of usrGlobal - par(usr) then calling text(usrGlobal[2]-50,usrGlobal[4]-50,paste(Moyenne = ,r ...) did not show any text whereas it did in the reg function. But of course, pasting code could have been shorter for people to read ;-). Thanx for your help. -- View this message in context: http://www.nabble.com/text-in-boxplots-tf4394528.html#a12558160 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ploting missing data
Hello, I have this kind of dataframe and have to plot it. data - data.frame(sw= c(1,2,3,4,5,6,7,8,9,10,11,12,15), zehn = c(33.44,20.67,18.20,18.19,17.89,19.65,20.05,19.87,20.55,22.53,NA,NA,NA), zwanzig = c(61.42,NA,26.60,23.28,NA,24.90,24.47,24.53,26.41,28.26,NA,29.80,35.49), fuenfzig = c(162.51,66.08,49.55,43.40,NA,37.77,35.53,36.46,37.25,37.66,NA,42.29,47.80) ) The plot should have lines: lines(fuenfzig~sw, data=data) lines(zwanzig~sw, data=data) But now I have holes in my lines for the missing values (NA). How to plot the lines without the holes? The missing values should be interpolated or the left and right point directly connected. The function approx interpolates the whole dataset. Thats not my goal! Is there no plotting function to do this directly? Best Markus -- Dipl.-Tech. Math. Markus Schmidberger Ludwig-Maximilians-Universität München IBE - Institut für medizinische Informationsverarbeitung, Biometrie und Epidemiologie Marchioninistr. 15, D-81377 Muenchen URL: http://ibe.web.med.uni-muenchen.de Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: variable format
Dear Cory, I am not familiar with SAS, but is this what you are looking for? divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic, 6, East South Central, 7, West South Central, 8, Mountain, 9, Pacific), ncol=2, byrow=T) a - NULL a$divisionOld - c(0,1,2,3,4,5) a$divisionNew - as.character(factor(a$divisionOld,levels=divisionTable[,1],labels=divisionTable[,2])) a$divisionNew [1] NA New EnglandMiddle Atlantic [4] East North Central West North Central South Atlantic Kind regards, Martin Cory Nissen schrieb: Anybody? From: Cory Nissen Sent: Tue 9/4/2007 9:30 AM To: r-help@stat.math.ethz.ch Subject: variable format Okay, I want to do something similar to SAS proc format. I usually do this... a - NULL a$divisionOld - c(1,2,3,4,5) divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic), ncol=2, byrow=T) a$divisionNew[match(a$divisionOld, divisionTable[,1])] - divisionTable[,2] But how do I handle the case where... a$divisionOld - c(0,1,2,3,4,5) #no format available for 0, this throws an error. OR divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic, 6, East South Central, 7, West South Central, 8, Mountain, 9, Pacific), ncol=2, byrow=T) There are extra formats available... this throws a warning. Thanks Cory [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] PCA IN R
hi, A very quick search of PCA in R results in a lot of packages involving that function. Just wondering which one is generally used for fat data like microarray, esp. when the number of features is really big? Thanks for comments -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. Did you always know? No, I did not. But I believed... ---Matrix III __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] text in boxplots
Looking at the help for scatterplot, it looks like there is a 6th option (which is probably the preferred method): 6. set the reset.par argument to FALSE in calling scatterplot as it states in the documentation for scatterplot. (still look at the help on 'xpd' argment to par if you want to add text to the margins). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Greg Snow Sent: Friday, September 07, 2007 9:01 AM To: Yves Moisan; r-help@stat.math.ethz.ch Subject: Re: [R] text in boxplots The posting guide (a link at the bottom of every e-mail from the list) suggests including a small example of what you are trying to do. Without an example, we have to guess at what you are trying to do. I am still guessing since you still did not include an example. It appears that part of the problem may be that the scatterplot function from the car package does not leave the user coordinate system in a state that matches intuitively with the data. Your call to text is probably placing the text outside of the plotting region where it is not visible (possibly even in someone elses cubicle/office). The mtext function is not affected as much by this since it uses a different coordinate system (based on the margins rather than the user coordinates). To place text on the plot, you need to find the cooresponding coordinates. There are a few different ways to do this: 1. use par('usr') to find out what the current user coordinates are and compute your coordinates based on that. 2. use par(usr=c(...)) to set the user coordinates to match where you want to plot. 3. use the locator function to interactively choose the locations and use the resulting coordinates. 4. use the cnvrt.coords function from the TeachingDemos package to convert from figure or device coordinates to the current user coordinate system. 5. contact the author of the function and ask him to set the user coordinates to something more intuitive before exiting and wait for the change. Look at the help for par for more information, specifically look at the 'usr' entry and possibly the 'xpd' entry if you want to add text to the marginal boxplots. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Yves Moisan Sent: Friday, September 07, 2007 5:05 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] text in boxplots Hi Greg, Actually, I'm using the scatterplot function in the car namespace. My understanding is that the scatterplot is turned into a boxplot when the x variable is a factor, but I can't see that in the code of the function. I've successfully modified the function to output regression stats (R^^2, etc.) with the method 'text', but I can't seem to get any text printed when the result of a call to scatterplot is a bunch of boxplots. I don't know how boxplots end up being generated (I like it though) in a call to car:scatterplot. The same data in ggobi would show the standard scatterplot with data aligned vertically in lines along the values of the x (factor) variable but car:scatterplot draws nice boxes around the data as a bonus. I guess I'll need to follow with some debugging tool. I find it odd that mtext works though. Or maybe some graphics parameter is set such that text doesn't show. Thanx Greg. -- View this message in context: http://www.nabble.com/text-in-boxplots-tf4394528.html#a12553104 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Delete query in sqldf?
Yes but delete does not return anything so its not useful. In the devel version of sqldf you can pass multiple command so try this using the builtin data frame BOD noting that the record with demand = 8.3 was removed: library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto # overwrite with devel version of the sqldf.R file source(http://sqldf.googlecode.com/svn/trunk/R/sqldf.R;) sqldf(c(delete from BOD where demand = 8.3, select * from BOD)) Time__1 demand 1 2 10.3 2 3 19.0 3 4 16.0 4 5 15.6 5 7 19.8 On 9/7/07, Paul Smith [EMAIL PROTECTED] wrote: Dear All, Is sqldf equipped with delete queries? I have tried delete queries but with no success. Thanks in advance, Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automatic detachment of dependent packages
Paul Smith wrote: Dear All, When one loads certain packages, some other dependent packages are loaded as well. Is there some way of detaching them automatically when one detaches the first package loaded? For instance, library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto but detach(package:sqldf) search() [1] .GlobalEnvpackage:gsubfnpackage:proto [4] package:RSQLite package:DBI package:stats [7] package:graphics package:grDevices package:utils [10] package:datasets package:methods Autoloads [13] package:base The packages RSQLite DBI gsubfn proto were not detached. The danger here is that after attaching sqldf you might attach some other package that needs, say, DBI, then when your cleanup routine detaches DBI that other package dies because DBI isn't there. The way to do it would be to detach any packages that are only depended on by the package you are detaching. You'd have to call packageDescription(foo, fields=Depends) for currently attached packages to build the dependency tree and then work out which ones you can remove... There's a bit of recursive tree-walking in there, but it should be simple... Ummm... Barry __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting to stdout
On 9/7/2007 12:36 PM, Gene Selkov wrote: I have found two prior instances of this question in R-help, but I can't find the answer, and I'm giving up on mindless tinkering. http://tolstoy.newcastle.edu.au/R/help/03a/5994.html https://stat.ethz.ch/pipermail/r-help/2004-December/062259.html I must be able to pipe the poltting commands to stdin and receive the plot on stdout, with errors written to stderr, should any occur. Here's what I tried: file test.r: ~~ postscript(stdout()) plot(0) ~~ This command: cat test.r | r --vanilla --slave writes the output to a file named 1 I have also tried: postscript(file=stdout()) postscript(file=file(stdout)) In the latter case, the output goes to the file named 3. Other graphics devices do the same thing. It is interesting that write.table() supports the file=stdout() idiom. If there is no official option to do this, I will appreciate a hint about the spot in the code where I can fix it. The ?postscript man page suggests that postscript(file=, command=cat) should do what you want (or maybe something other than cat for the passthrough). The file arg is described as a character string, not a connection, so I wouldn't expect stdout() to work. For write.table(), the arg is defined to be either the name of a file or an open connection. Duncan Murdoch Thanks, --Gene ~ sessionInfo() R version 2.5.1 (2007-06-27) i386-apple-darwin8.10.1 locale: C attached base packages: [1] stats graphics grDevices utils datasets methods [7] base __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plotting to stdout
I have found two prior instances of this question in R-help, but I can't find the answer, and I'm giving up on mindless tinkering. http://tolstoy.newcastle.edu.au/R/help/03a/5994.html https://stat.ethz.ch/pipermail/r-help/2004-December/062259.html I must be able to pipe the poltting commands to stdin and receive the plot on stdout, with errors written to stderr, should any occur. Here's what I tried: file test.r: ~~ postscript(stdout()) plot(0) ~~ This command: cat test.r | r --vanilla --slave writes the output to a file named 1 I have also tried: postscript(file=stdout()) postscript(file=file(stdout)) In the latter case, the output goes to the file named 3. Other graphics devices do the same thing. It is interesting that write.table() supports the file=stdout() idiom. If there is no official option to do this, I will appreciate a hint about the spot in the code where I can fix it. Thanks, --Gene ~ sessionInfo() R version 2.5.1 (2007-06-27) i386-apple-darwin8.10.1 locale: C attached base packages: [1] stats graphics grDevices utils datasets methods [7] base __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] negative value for AIC and BIC
Olivier, type ?AIC and have a look at the description Description: Generic function calculating the Akaike information criterion for one or several fitted model objects for which a log-likelihood value can be obtained, according to the formula -2*log-likelihood + k*npar, where npar represents the number of parameters in the fitted model, and k = 2 for the usual AIC, or k = log(n) (n the number of observations) for the so-called BIC or SBC (Schwarz's Bayesian criterion). AIC = -2*log-likelihood + k*npar can be negative as SBC, too. Hannu On 9/7/07, Olivier MARTIN [EMAIL PROTECTED] wrote: Hi all, I obtained negative values for AIC and BIC criteria for a particular model that I have developped... I don't remember to have negative values for these crietria for others applications, so I am a little suprised... Could anyone tell me if something is wrong or his conclusion concerning my model? Best regards, Olivier. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Q: loess-like function that allows more predictors?
I have a feeling that this may be a stupid question, but here goes anyway: is there a function that I can use to replace loess but which allows a larger number of predictors? (I have a situation in which it would be very convenient to use 5 predictors, which violates the constraint in loess that the number of predictors be in the range from 1 to 4.) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Survey package
On 7/9/07 12:36 AM, eugen pircalabelu wrote: I'm trying to use the Survey package for a stratified sample which has 4 criteria on which the stratification is based. I would like to get the corrected weights and for every element i get a weight of 1 E.g: tipping design - svydesign (id=~1, strata= ~regiune + size_loc + age_rec_hhh + size_hh, data= tabel) and then weights(design) gives me: 1,1,1,1,1,1,1,1,1,1,1,... for each element The weights are all 1 because you haven't told R how they should be calculated. If the sampling weights should be constant within strata, you can simply specify the population figures for each stratum in svydesign's fpc argument and it will calculate the weights for you. Various techniques for adjusting the weights are also supported; see http://faculty.washington.edu/tlumley/survey/example-poststrat.html James -- James Reilly Department of Statistics, University of Auckland Private Bag 92019, Auckland, New Zealand __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Q: loess-like function that allows more predictors?
locfit() in the locfit package can do that. Andy From: D. R. Evans I have a feeling that this may be a stupid question, but here goes anyway: is there a function that I can use to replace loess but which allows a larger number of predictors? (I have a situation in which it would be very convenient to use 5 predictors, which violates the constraint in loess that the number of predictors be in the range from 1 to 4.) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Notice: This e-mail message, together with any attachments,...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] SQL like function?
observation %in% ID --- Takatsugu Kobayashi [EMAIL PROTECTED] wrote: Hi RUsers, I am wonder if I can search observations whose IDs matches any of the values in another vector, such as in MySQL. While I am learing MySQL for future database management, I appreciate if anyone could give me a hint. Suppose I have one 5*1 vector containing observation IDs and frequencies, and one 3*1 vector containing observation IDs. observation-c(1,2,3,4,5) ID-c(1,3,4) Then, I would like to program a code that returns a results showing matched observations like result: TRUE FALSE TRUE TRUE FALSE I am reading S programming, but I cannot find a way to do this. Thank you very much. Taka __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automatic detachment of dependent packages
If its good enough just to get rid of all attached packages since after startup you could just do repeated detaches like this making use of the fact that search() has 9 components on startup: replicate(length(search()) - 9, detach()) On 9/7/07, Paul Smith [EMAIL PROTECTED] wrote: Dear All, When one loads certain packages, some other dependent packages are loaded as well. Is there some way of detaching them automatically when one detaches the first package loaded? For instance, library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto but detach(package:sqldf) search() [1] .GlobalEnvpackage:gsubfnpackage:proto [4] package:RSQLite package:DBI package:stats [7] package:graphics package:grDevices package:utils [10] package:datasets package:methods Autoloads [13] package:base The packages RSQLite DBI gsubfn proto were not detached. Thanks in advance, Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] write geotiff with projection - RGDAL package
On Thu, 6 Sep 2007, Monica Pisica wrote: Hi, Doing more search i've discovered package RGDAL that can write a geotiff file with projection. I saved a geotiff file in UTM projection and if i read the file back in R and check the projection seems that everything is OK. But if i load the file in ArcGIS (ESRI product) i get the warning that the file is missing spatial reference so it cannot be projected, but it is displayed correctly. I guess somewhere i am doing a mistake when i define the projection in R. My code follows: data.grid - read.csv(x, header=TRUE) gridded(data.grid) = ~East.m.+North.m. proj4string(data.grid) = CRS(+proj=tmerc +lat_0=0.000 +lon_0=-81.000 +k=0.9996 +x_0=50.00 +y_0=0.000 +ellps=GRS80 +units=m) tr - e:\\JELA_veg\\test_gtiff\\test.tif writeGDAL(data.grid[class.pca], tr) mg3 - readGDAL(tr) proj4string(mg3) [1] +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs I will really appreciate if anybody can point me in the right dirrection. In my previous reply, I suggested that you visit: http://www.gdal.org/frmt_gtiff.html There you will find that for ESRI products, you may need to set options=TFW=YES at least, because ESRI products do not honour the projection information already encoded inside the GTiff file. The information is there, it is just that ESRI products only look for it in places they have thought of, not in the proper places. If necessary, showWKT() can make a *.prj file. Otherwise just override ESRI. Roger Thanks, Monica _ News, entertainment and everything you care about at Live.com. Get it now! http://www.live.com/getstarted.aspx -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Matlab's lsqnonlin
On Fri, Sep 07, 2007 at 08:34:45PM +0200, Jose Luis Aznarte M. wrote: Hi! I'm translating some code from Matlab to R and I found a problem. I need to translate Matlab's function 'lsqnonlin' (http://www-ccs.ucsd.edu/matlab/toolbox/optim/lsqnonlin.html) into R, Do you want the nls function in R for nonlinear least squares? -- Daniel Lakeland [EMAIL PROTECTED] http://www.street-artists.org/~dlakelan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] negative value for AIC and BIC
Hi all, I obtained negative values for AIC and BIC criteria for a particular model that I have developped... I don't remember to have negative values for these crietria for others applications, so I am a little suprised... Could anyone tell me if something is wrong or his conclusion concerning my model? Best regards, Olivier. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automatic detachment of dependent packages
On 9/7/07, Barry Rowlingson [EMAIL PROTECTED] wrote: When one loads certain packages, some other dependent packages are loaded as well. Is there some way of detaching them automatically when one detaches the first package loaded? For instance, library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto but detach(package:sqldf) search() [1] .GlobalEnvpackage:gsubfnpackage:proto [4] package:RSQLite package:DBI package:stats [7] package:graphics package:grDevices package:utils [10] package:datasets package:methods Autoloads [13] package:base The packages RSQLite DBI gsubfn proto were not detached. The danger here is that after attaching sqldf you might attach some other package that needs, say, DBI, then when your cleanup routine detaches DBI that other package dies because DBI isn't there. The way to do it would be to detach any packages that are only depended on by the package you are detaching. You'd have to call packageDescription(foo, fields=Depends) for currently attached packages to build the dependency tree and then work out which ones you can remove... There's a bit of recursive tree-walking in there, but it should be simple... Ummm... Thanks, Barry and Gabor. Please, look at the following: library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto packageDescription(sqldf, fields=Depends) [1] R (= 2.5.1), RSQLite (= 0.5-5), gsubfn packageDescription does not mention the packages DBI and proto. Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Matlab's lsqnonlin
The thread you linked to regarding Levenberg-Marquardt's supposed lack of availability is from 2001; it has been possible to get to the MINPACK implementation of Levenberg-Marquardt within R via the package minpack.lm (http://cran.r-project.org/src/contrib/Descriptions/minpack.lm.html) since 2005. Katharine Mullen mail: Department of Physics and Astronomy, Faculty of Sciences Vrije Universiteit Amsterdam, de Boelelaan 1081 1081 HV Amsterdam, The Netherlands room: T.1.06 tel: +31 205987870 fax: +31 205987992 e-mail: [EMAIL PROTECTED] homepage: http://www.nat.vu.nl/~kate/ On Fri, 7 Sep 2007, Jose Luis Aznarte M. wrote: Hi! I'm translating some code from Matlab to R and I found a problem. I need to translate Matlab's function 'lsqnonlin' (http://www-ccs.ucsd.edu/matlab/toolbox/optim/lsqnonlin.html) into R, and at the beginning I thought it would be the same as R's 'optim'. But then I looked at the definition of 'lsqnonlin' and I don't quite see how to make 'optim' to do the same thing. Does anyone have an idea? This is apart from the fact that I would like to use the Levenberg Marquardt algorithm which is not implemented in R (some discussion about this: http://tolstoy.newcastle.edu.au/R/help/00b/2492.html). Thank you! All the best, -- -- Jose Luis Aznarte M. http://decsai.ugr.es/~jlaznarte Department of Computer Science and Artificial Intelligence Universidad de Granada Tel. +34 - 958 - 24 04 67 GRANADA (Spain) Fax: +34 - 958 - 24 00 79 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Matlab's lsqnonlin
Hi! I'm translating some code from Matlab to R and I found a problem. I need to translate Matlab's function 'lsqnonlin' (http://www-ccs.ucsd.edu/matlab/toolbox/optim/lsqnonlin.html) into R, and at the beginning I thought it would be the same as R's 'optim'. But then I looked at the definition of 'lsqnonlin' and I don't quite see how to make 'optim' to do the same thing. Does anyone have an idea? This is apart from the fact that I would like to use the Levenberg Marquardt algorithm which is not implemented in R (some discussion about this: http://tolstoy.newcastle.edu.au/R/help/00b/2492.html). Thank you! All the best, -- -- Jose Luis Aznarte M. http://decsai.ugr.es/~jlaznarte Department of Computer Science and Artificial Intelligence Universidad de Granada Tel. +34 - 958 - 24 04 67 GRANADA (Spain) Fax: +34 - 958 - 24 00 79 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting to stdout
Thanks a ton, Duncan! So I have verified that this line works: echo postscript(file=\\, command=\cat\); plot(0) | r --vanilla --slave Wonderful! (albeit a little unobvious) --Gene On Fri, 7 Sep 2007, Duncan Murdoch wrote: On 9/7/2007 12:36 PM, Gene Selkov wrote: I have found two prior instances of this question in R-help, but I can't find the answer, and I'm giving up on mindless tinkering. http://tolstoy.newcastle.edu.au/R/help/03a/5994.html https://stat.ethz.ch/pipermail/r-help/2004-December/062259.html I must be able to pipe the poltting commands to stdin and receive the plot on stdout, with errors written to stderr, should any occur. Here's what I tried: file test.r: ~~ postscript(stdout()) plot(0) ~~ This command: cat test.r | r --vanilla --slave writes the output to a file named 1 I have also tried: postscript(file=stdout()) postscript(file=file(stdout)) In the latter case, the output goes to the file named 3. Other graphics devices do the same thing. It is interesting that write.table() supports the file=stdout() idiom. If there is no official option to do this, I will appreciate a hint about the spot in the code where I can fix it. The ?postscript man page suggests that postscript(file=, command=cat) should do what you want (or maybe something other than cat for the passthrough). The file arg is described as a character string, not a connection, so I wouldn't expect stdout() to work. For write.table(), the arg is defined to be either the name of a file or an open connection. Duncan Murdoch Thanks, --Gene ~ sessionInfo() R version 2.5.1 (2007-06-27) i386-apple-darwin8.10.1 locale: C attached base packages: [1] stats graphics grDevices utils datasets methods [7] base __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Delete query in sqldf?
On 9/7/07, Gabor Grothendieck [EMAIL PROTECTED] wrote: Yes but delete does not return anything so its not useful. In the devel version of sqldf you can pass multiple command so try this using the builtin data frame BOD noting that the record with demand = 8.3 was removed: library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto # overwrite with devel version of the sqldf.R file source(http://sqldf.googlecode.com/svn/trunk/R/sqldf.R;) sqldf(c(delete from BOD where demand = 8.3, select * from BOD)) Time__1 demand 1 2 10.3 2 3 19.0 3 4 16.0 4 5 15.6 5 7 19.8 I see, Gabor, but I would expect as more natural to have sqldf(delete from BOD where demand = 8.3) working, with no second command. Paul On 9/7/07, Paul Smith [EMAIL PROTECTED] wrote: Dear All, Is sqldf equipped with delete queries? I have tried delete queries but with no success. Thanks in advance, Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: variable format
This was what I was looking for. I figured factor was the way to go, but I wasn't sure how to implement it. The car recommendation looks good too, but I want to try to stay away from having to download another package if I can. Thanks cn From: Martin Becker [mailto:[EMAIL PROTECTED] Sent: Fri 9/7/2007 10:55 AM To: Cory Nissen Cc: r-help@stat.math.ethz.ch Subject: Re: [R] FW: variable format Dear Cory, I am not familiar with SAS, but is this what you are looking for? divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic, 6, East South Central, 7, West South Central, 8, Mountain, 9, Pacific), ncol=2, byrow=T) a - NULL a$divisionOld - c(0,1,2,3,4,5) a$divisionNew - as.character(factor(a$divisionOld,levels=divisionTable[,1],labels=divisionTable[,2])) a$divisionNew [1] NA New EnglandMiddle Atlantic [4] East North Central West North Central South Atlantic Kind regards, Martin Cory Nissen schrieb: Anybody? From: Cory Nissen Sent: Tue 9/4/2007 9:30 AM To: r-help@stat.math.ethz.ch Subject: variable format Okay, I want to do something similar to SAS proc format. I usually do this... a - NULL a$divisionOld - c(1,2,3,4,5) divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic), ncol=2, byrow=T) a$divisionNew[match(a$divisionOld, divisionTable[,1])] - divisionTable[,2] But how do I handle the case where... a$divisionOld - c(0,1,2,3,4,5) #no format available for 0, this throws an error. OR divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic, 6, East South Central, 7, West South Central, 8, Mountain, 9, Pacific), ncol=2, byrow=T) There are extra formats available... this throws a warning. Thanks Cory [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Optimization under an absolute value constraint
I need to optimize a multivariate function f(w, x, y, z, ...) under an absolute value constraint. For instance: min { (2x+y) (w-z) } under the constraint: |w| + |x| + |y| + |z| = 1.0 . Is there any R function that does this? Thank you for your help! Phil Xiang __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting to stdout
On 9/7/2007 2:15 PM, Gene Selkov wrote: Thanks a ton, Duncan! So I have verified that this line works: echo postscript(file=\\, command=\cat\); plot(0) | r --vanilla --slave Wonderful! (albeit a little unobvious) I would include an explicit dev.off() after the plotting; I'm not sure all devices guarantee a clean shutdown when R quits. Duncan Murdoch --Gene On Fri, 7 Sep 2007, Duncan Murdoch wrote: On 9/7/2007 12:36 PM, Gene Selkov wrote: I have found two prior instances of this question in R-help, but I can't find the answer, and I'm giving up on mindless tinkering. http://tolstoy.newcastle.edu.au/R/help/03a/5994.html https://stat.ethz.ch/pipermail/r-help/2004-December/062259.html I must be able to pipe the poltting commands to stdin and receive the plot on stdout, with errors written to stderr, should any occur. Here's what I tried: file test.r: ~~ postscript(stdout()) plot(0) ~~ This command: cat test.r | r --vanilla --slave writes the output to a file named 1 I have also tried: postscript(file=stdout()) postscript(file=file(stdout)) In the latter case, the output goes to the file named 3. Other graphics devices do the same thing. It is interesting that write.table() supports the file=stdout() idiom. If there is no official option to do this, I will appreciate a hint about the spot in the code where I can fix it. The ?postscript man page suggests that postscript(file=, command=cat) should do what you want (or maybe something other than cat for the passthrough). The file arg is described as a character string, not a connection, so I wouldn't expect stdout() to work. For write.table(), the arg is defined to be either the name of a file or an open connection. Duncan Murdoch Thanks, --Gene ~ sessionInfo() R version 2.5.1 (2007-06-27) i386-apple-darwin8.10.1 locale: C attached base packages: [1] stats graphics grDevices utils datasets methods [7] base __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automatic detachment of dependent packages
On 9/7/2007 2:05 PM, Paul Smith wrote: On 9/7/07, Barry Rowlingson [EMAIL PROTECTED] wrote: When one loads certain packages, some other dependent packages are loaded as well. Is there some way of detaching them automatically when one detaches the first package loaded? For instance, library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto but detach(package:sqldf) search() [1] .GlobalEnvpackage:gsubfnpackage:proto [4] package:RSQLite package:DBI package:stats [7] package:graphics package:grDevices package:utils [10] package:datasets package:methods Autoloads [13] package:base The packages RSQLite DBI gsubfn proto were not detached. The danger here is that after attaching sqldf you might attach some other package that needs, say, DBI, then when your cleanup routine detaches DBI that other package dies because DBI isn't there. The way to do it would be to detach any packages that are only depended on by the package you are detaching. You'd have to call packageDescription(foo, fields=Depends) for currently attached packages to build the dependency tree and then work out which ones you can remove... There's a bit of recursive tree-walking in there, but it should be simple... Ummm... Thanks, Barry and Gabor. Please, look at the following: library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto packageDescription(sqldf, fields=Depends) [1] R (= 2.5.1), RSQLite (= 0.5-5), gsubfn packageDescription does not mention the packages DBI and proto. They are part of the recursive tree-walking that Barry mentioned, i.e. dependencies of RSQLite or gsubfn: packageDescription(RSQLite, fields=Depends) [1] R (= 2.3.0), methods, DBI (= 0.2-3) packageDescription(gsubfn, fields=Depends) [1] R (= 2.4.0), proto But you can get R to do the walking for you, using the pkgDepends function from the tools package: pkgDepends(sqldf) $Depends [1] DBI (= 0.2-3) gsubfn methods [4] proto RSQLite (= 0.5-5) ... [ more stuff deleted ] ... Watch out though: you may not want to detach methods when you detach sqldf, because it was already there. Essentially you need some sort of snapshot of the state beforehand, and then you could restore it. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Optimization under an absolute value constraint
this should be possible in the lasso2 package. url:www.econ.uiuc.edu/~rogerRoger Koenker email[EMAIL PROTECTED]Department of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Sep 7, 2007, at 1:17 PM, Phil Xiang wrote: I need to optimize a multivariate function f(w, x, y, z, ...) under an absolute value constraint. For instance: min { (2x+y) (w-z) } under the constraint: |w| + |x| + |y| + |z| = 1.0 . Is there any R function that does this? Thank you for your help! Phil Xiang __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: variable format
Martin Becker wrote: Dear Cory, I am not familiar with SAS, but is this what you are looking for? divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic, 6, East South Central, 7, West South Central, 8, Mountain, 9, Pacific), ncol=2, byrow=T) How about just divisionTable - c('New England', 'Middle Atlantic', ...) then factor(old, 1:9, divisionTable) ? Frank a - NULL a$divisionOld - c(0,1,2,3,4,5) a$divisionNew - as.character(factor(a$divisionOld,levels=divisionTable[,1],labels=divisionTable[,2])) a$divisionNew [1] NA New EnglandMiddle Atlantic [4] East North Central West North Central South Atlantic Kind regards, Martin Cory Nissen schrieb: Anybody? From: Cory Nissen Sent: Tue 9/4/2007 9:30 AM To: r-help@stat.math.ethz.ch Subject: variable format Okay, I want to do something similar to SAS proc format. I usually do this... a - NULL a$divisionOld - c(1,2,3,4,5) divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic), ncol=2, byrow=T) a$divisionNew[match(a$divisionOld, divisionTable[,1])] - divisionTable[,2] But how do I handle the case where... a$divisionOld - c(0,1,2,3,4,5) #no format available for 0, this throws an error. OR divisionTable - matrix(c(1, New England, 2, Middle Atlantic, 3, East North Central, 4, West North Central, 5, South Atlantic, 6, East South Central, 7, West South Central, 8, Mountain, 9, Pacific), ncol=2, byrow=T) There are extra formats available... this throws a warning. Thanks Cory [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] aggregate factor
Hi, I am using aggregate to compute means for later plotting. There are two factors involved and the problem is that the values of the second factor ( Age ) in the means are not in the right order because 10 comes inbetween 1 and 2 What I really want is the numeric value of Age but as.numeric and as.integer returns the level value instead. Is there a way to easily get the numeric value? I am using Windows R 2.5.1 Thanks, str(fishdata) 'data.frame': 372 obs. of 6 variables: $ Lake: Factor w/ 3 levels EVANS,JOLLIET,..: 3 3 3 3 3 3 3 3 3 3 ... $ Age : int 1 1 1 1 1 1 1 1 1 1 ... $ TL : int 132 120 125 115 130 120 115 110 117 116 ... $ W : int 10 10 10 10 10 10 10 10 10 20 ... $ Sex : Factor w/ 3 levels F,I,M: 1 1 2 2 2 1 1 1 2 2 ... $ WT : num 0.23 0.23 0.23 0.23 0.23 0.23 0.23 0.23 0.23 0.23 ... fishdatameans=aggregate(fishdata$TL, list(Lake = fishdata$Lake, Age=fishdata$Age), mean) # Now Age is a Factor but 10 is in the wrong position. fishdatameans$Age [1] 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 6 6 6 7 8 9 10 Levels: 0 1 10 2 3 4 5 6 7 8 9 as.numeric(fishdatameans$Age) [1] 1 2 2 2 4 4 4 5 5 5 6 6 6 7 7 8 8 8 9 10 11 3 # What I want is 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 6 6 6 7 8 9 10 Bill __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Running a PERL script from R
Is there a way to run a simple perl script from R? Kenneth B. Pierce Jr. Research Ecologist Landscape Ecology, Modeling, Mapping and Analysis Team PNW Research Station - USDA-FS 3200 SW Jefferson Way, Corvallis, OR 97331 [EMAIL PROTECTED] 541 750-7393 http://www.fsl.orst.edu/lemma/gnnfire http://www.fsl.orst.edu/R_users/index.php [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] aggregate factor
Try this. as.numeric(levels(fishdata$Age))[fishdata$Age] HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Bill Szkotnicki Verzonden: vrijdag 7 september 2007 21:10 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] aggregate factor Hi, I am using aggregate to compute means for later plotting. There are two factors involved and the problem is that the values of the second factor ( Age ) in the means are not in the right order because 10 comes inbetween 1 and 2 What I really want is the numeric value of Age but as.numeric and as.integer returns the level value instead. Is there a way to easily get the numeric value? I am using Windows R 2.5.1 Thanks, str(fishdata) 'data.frame': 372 obs. of 6 variables: $ Lake: Factor w/ 3 levels EVANS,JOLLIET,..: 3 3 3 3 3 3 3 3 3 3 ... $ Age : int 1 1 1 1 1 1 1 1 1 1 ... $ TL : int 132 120 125 115 130 120 115 110 117 116 ... $ W : int 10 10 10 10 10 10 10 10 10 20 ... $ Sex : Factor w/ 3 levels F,I,M: 1 1 2 2 2 1 1 1 2 2 ... $ WT : num 0.23 0.23 0.23 0.23 0.23 0.23 0.23 0.23 0.23 0.23 ... fishdatameans=aggregate(fishdata$TL, list(Lake = fishdata$Lake, Age=fishdata$Age), mean) # Now Age is a Factor but 10 is in the wrong position. fishdatameans$Age [1] 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 6 6 6 7 8 9 10 Levels: 0 1 10 2 3 4 5 6 7 8 9 as.numeric(fishdatameans$Age) [1] 1 2 2 2 4 4 4 5 5 5 6 6 6 7 7 8 8 8 9 10 11 3 # What I want is 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 6 6 6 7 8 9 10 Bill __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with color coded bar graph
I have a list of observations that are -1, 1 or 0. I would like to represent them in a horizontal bar color coded based on value like a stacked bar graph. I can achieve this in the form of a png with the following code: A = floor(runif(10)*3) - 1 png(width=100, height=10) par(mar=c(0,0,0,0)) image(matrix(A), col=grey(c(0.1, 0.5, 0.9))) dev.off() However I would like to do this with one of the standard plotting tools (i.e. barplot) to take advantage of labels and multiple series. Any help would be appreciated. - Luis Naver __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] confusion matrix - better code?
Hi, Ive written some code to obtain a confusion matrix when the true classification and the predicted classification are known. Suppose true classification is called tr and predicted classification is pr. I have 4 classes in tr, but only 3 classes out of 4 are predicted in pr. Following is my code, but looks quite clunky to me. I wonder if you have any suggestions to improve it. Thanks, Monica - tr - c(1,2,2,3,3,3,2,4,1,1) pr-c(1,2,1,3,3,3,1,2,1,2) dat - data.frame(tr, pr) class - c(1:length(tr)) m - max(c(length(unique(tr)), length(unique(pr for(i in 1:length(class)) { class[i] - sub(' ','',paste(dat[i,1],dat[i,2])) } dat - data.frame(dat, class) mat - matrix(0, nrow=m, ncol=m) for (i in 1:m){ for (j in 1:m){ mat[i,j] - sub(' ','',paste(i,j)) }} cat - matrix(0, nrow=(m+1), ncol=(m+1)) for (i in 1:m){ for(j in 1:m){ cat[i,j]- nrow(dat[dat$class==mat[i,j],]) }} for (i in 1:m){ cat[(m+1),i]-sum(cat[1:m,i]) cat[i,(m+1)]- sum(cat[i,1:m]) cat[(m+1),(m+1)] - sum(cat[1:m,(m+1)]) } cat [,1] [,2] [,3] [,4] [,5] [1,]21003 [2,]21003 [3,]00303 [4,]01001 [5,]4330 10 The 5th row / col represents the sum on each row / col respectively. _ Gear up for Halo® 3 with free downloads and an exclusive offer. Its our way of saying thanks for using Windows Live. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Delete query in sqldf?
All sqldf does is pass the command to sqlite and retrieve whatever it sends back translating the two directions to and from R. sqldf does not change the meaning of any sql statements. Perhaps the meaning you expect is desirable but its not how sqlite works. If sqlite were changed to adopt that meaning then sqldf would automatically get it too. Here is an example which does not involve R at all which illustrates that delete returns nothing. C:\ sqlite3 SQLite version 3.4.0 Enter .help for instructions sqlite sqlite create table t1(a,b); sqlite insert into T1 values(1,2); sqlite insert into T1 values(1,3); sqlite insert into T1 values(2,4); sqlite delete from t1 where b = 2; sqlite select * from t1; 1|3 2|4 On 9/7/07, Paul Smith [EMAIL PROTECTED] wrote: On 9/7/07, Gabor Grothendieck [EMAIL PROTECTED] wrote: Yes but delete does not return anything so its not useful. In the devel version of sqldf you can pass multiple command so try this using the builtin data frame BOD noting that the record with demand = 8.3 was removed: library(sqldf) Loading required package: RSQLite Loading required package: DBI Loading required package: gsubfn Loading required package: proto # overwrite with devel version of the sqldf.R file source(http://sqldf.googlecode.com/svn/trunk/R/sqldf.R;) sqldf(c(delete from BOD where demand = 8.3, select * from BOD)) Time__1 demand 1 2 10.3 2 3 19.0 3 4 16.0 4 5 15.6 5 7 19.8 I see, Gabor, but I would expect as more natural to have sqldf(delete from BOD where demand = 8.3) working, with no second command. Paul On 9/7/07, Paul Smith [EMAIL PROTECTED] wrote: Dear All, Is sqldf equipped with delete queries? I have tried delete queries but with no success. Thanks in advance, Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] confusion matrix - better code?
Dear Monica, try this: cm = table(tr, pr) cm pr tr 1 2 3 1 2 1 0 2 2 1 0 3 0 0 3 4 0 1 0 rowSums(cm) colSums(cm) Best wishes Wolfgang Huber Monica Pisica ha scritto: Hi, I�ve written some code to obtain a confusion matrix when the true classification and the predicted classification are known. Suppose true classification is called �tr� and predicted classification is �pr�. I have 4 classes in tr, but only 3 classes out of 4 are predicted in �pr�. Following is my code, but looks quite �clunky� to me. I wonder if you have any suggestions to improve it. Thanks, Monica - tr - c(1,2,2,3,3,3,2,4,1,1) pr-c(1,2,1,3,3,3,1,2,1,2) dat - data.frame(tr, pr) class - c(1:length(tr)) m - max(c(length(unique(tr)), length(unique(pr for(i in 1:length(class)) { class[i] - sub(' ','',paste(dat[i,1],dat[i,2])) } dat - data.frame(dat, class) mat - matrix(0, nrow=m, ncol=m) for (i in 1:m){ for (j in 1:m){ mat[i,j] - sub(' ','',paste(i,j)) }} cat - matrix(0, nrow=(m+1), ncol=(m+1)) for (i in 1:m){ for(j in 1:m){ cat[i,j]- nrow(dat[dat$class==mat[i,j],]) }} for (i in 1:m){ cat[(m+1),i]-sum(cat[1:m,i]) cat[i,(m+1)]- sum(cat[i,1:m]) cat[(m+1),(m+1)] - sum(cat[1:m,(m+1)]) } cat [,1] [,2] [,3] [,4] [,5] [1,]21003 [2,]21003 [3,]00303 [4,]01001 [5,]4330 10 The 5th row / col represents the sum on each row / col respectively. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting to stdout
On Fri, Sep 07, 2007 at 02:27:00PM -0400, Duncan Murdoch wrote: On 9/7/2007 2:15 PM, Gene Selkov wrote: Thanks a ton, Duncan! So I have verified that this line works: echo postscript(file=\\, command=\cat\); plot(0) | r --vanilla --slave Wonderful! (albeit a little unobvious) I would include an explicit dev.off() after the plotting; I'm not sure all devices guarantee a clean shutdown when R quits. And for the record, both littler and Rscript can do that without the need for double quotes, at least under Linux. E.g. both $ r -e 'postscript(file=, command=cat); plot(0)' | head $ Rscript -e 'postscript(file=, command=cat); plot(0)' | head provide the same output (of the beginning of the postscript output). Our r is as usual somewhat faster, not that this matters in this non-repeat context. Dirk -- Three out of two people have difficulties with fractions. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Running a PERL script from R
On Fri, Sep 07, 2007 at 12:15:51PM -0700, Pierce, Ken wrote: Is there a way to run a simple perl script from R? ?system Hth, Dirk -- Three out of two people have difficulties with fractions. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with color coded bar graph
On Fri, 2007-09-07 at 12:45 -0700, Luis Naver wrote: I have a list of observations that are -1, 1 or 0. I would like to represent them in a horizontal bar color coded based on value like a stacked bar graph. I can achieve this in the form of a png with the following code: A = floor(runif(10)*3) - 1 png(width=100, height=10) par(mar=c(0,0,0,0)) image(matrix(A), col=grey(c(0.1, 0.5, 0.9))) dev.off() However I would like to do this with one of the standard plotting tools (i.e. barplot) to take advantage of labels and multiple series. Any help would be appreciated. - Luis Naver How about this: barplot(rep(1, length(A)), col = black, space = 0, border = 0) barplot(A, col = grey(0.9), space = 0, border = 0, add = TRUE) The first call sets the plot region to black, ensuring that the x and y axes are consistent with the second call. Alternatively, you can use barplot2() in the gplots CRAN package to do this in a single call, as it has an argument to color the plot region. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with color coded bar graph
On Fri, 7 Sep 2007, Luis Naver wrote: I have a list of observations that are -1, 1 or 0. I would like to represent them in a horizontal bar color coded based on value like a stacked bar graph. I can achieve this in the form of a png with the following code: A = floor(runif(10)*3) - 1 png(width=100, height=10) par(mar=c(0,0,0,0)) image(matrix(A), col=grey(c(0.1, 0.5, 0.9))) dev.off() If I understand you correctly, you want a sequence of bars with equal height and colors coded by A (treated like a factor). So Maybe something like cA - grey.colors(3)[factor(A)] barplot(rep(1, length(A)), col = cA, border = cA) or barplot(rep(1, length(A)), col = cA, border = cA, space = 0, xaxs = i, axes = FALSE) ? hth, Z However I would like to do this with one of the standard plotting tools (i.e. barplot) to take advantage of labels and multiple series. Any help would be appreciated. - Luis Naver __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with color coded bar graph
On Fri, 2007-09-07 at 15:07 -0500, Marc Schwartz wrote: On Fri, 2007-09-07 at 12:45 -0700, Luis Naver wrote: I have a list of observations that are -1, 1 or 0. I would like to represent them in a horizontal bar color coded based on value like a stacked bar graph. I can achieve this in the form of a png with the following code: A = floor(runif(10)*3) - 1 png(width=100, height=10) par(mar=c(0,0,0,0)) image(matrix(A), col=grey(c(0.1, 0.5, 0.9))) dev.off() However I would like to do this with one of the standard plotting tools (i.e. barplot) to take advantage of labels and multiple series. Any help would be appreciated. - Luis Naver How about this: barplot(rep(1, length(A)), col = black, space = 0, border = 0) barplot(A, col = grey(0.9), space = 0, border = 0, add = TRUE) The first call sets the plot region to black, ensuring that the x and y axes are consistent with the second call. Alternatively, you can use barplot2() in the gplots CRAN package to do this in a single call, as it has an argument to color the plot region. Actually, here is an easier way: barplot(rep(1, length(A)), col = ifelse(A == 0, black, grey(0.9)), space = 0, border = 0) Just set 'col' based upon the value in 'A'. HTH, Marc __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] 'initial value not feasible' in constrOptim
Dear friends. I am using function constrOptim(c(0.5,0.3,0.5), fit.error, fit.error.grr, ui=-1*ui,ci=-1*ci) and I am confronted with error message initial value not feasible I plug in the initial value of (0.5,0.3,0.5) to function fit.error and fit.error.grr and have pretty reasonable result. I inequality ui %*% theta - ci = 0 as suggested in the R manual and it is satisfied. In case that this is a typo of the manual, I let ui=-ui and ci=-ci and try constrOptim again but the same warning message pops up. Could you please point me a way out of this? I am actually trying to translate a fortran code to R and the function I want to replace is DBCPOL, which used 'the complex method described in Nelder and Mead (1965) and Gill et al. (1981). I believe contrOptim is better than it because it is newer, is it? Best Wishes Yuchen Luo [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to obtain parameters of a mixture model of two lognormal distributions
Dear List, I have read that a lognormal mixture model having a pdf of the form f(x)=w1*f1(x)+(1-w1)*f2(x) fits most data sets quite well, where f1 and f2 are lognormal distributions. Any pointers on how to create a function that would produce the 5 parameters of f(x) would be greatly appreciated. version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 5.1 year 2007 month 06 day27 svn rev42083 language R version.string R version 2.5.1 (2007-06-27) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Running a PERL script from R
I've tried various configurations of .script, system and shell to no avail. It seems to pause and run something but then no output is created. -Original Message- From: Dirk Eddelbuettel [mailto:[EMAIL PROTECTED] Sent: Friday, September 07, 2007 1:11 PM To: Pierce, Ken Cc: r-help Subject: Re: [R] Running a PERL script from R On Fri, Sep 07, 2007 at 12:15:51PM -0700, Pierce, Ken wrote: Is there a way to run a simple perl script from R? ?system Hth, Dirk -- Three out of two people have difficulties with fractions. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] enable object name to be called as object (a dataset)
What I am trying to do is as follows: - I have listed names of all wanted objects (datasets A,B,C... ) in current workspace as a vector: obj - c('A','B','C') - then i need to use these objects, say to extract all the 1st columns and bind to an existing dataset ('data'): for ( i in 1:3){ newdata - obj[i] data - cbind(data,newdata [[1]] ) } Obviously, it doesn't work since obj[i] is just a string of dataset name. Here is my question: how to call it as a original dataset? Thanks. -- View this message in context: http://www.nabble.com/enable-object-name-to-be-called-as-object-%28a-dataset%29-tf4403933.html#a12563767 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] multiphasic growth curve analysis
Dear Petr, I tried replying directly to you but my communication was rejected as spam. On second thought, it is possible that it is. Thank you very much for taking the time and interest to answer my enquiry to the R Help Group. My interest isnt so much in the particular data set as in how to conduct such an analysis in R. The URL of the article where Bates was a coauthor which describes the technique is http://jds.fass.org/cgi/content/abstract/75/2/580 http://jds.fass.org/cgi/content/abstract/75/2/580 I enclose the IV Rabbit weight (age (a) in days, weight (w) in grams) data set from Koops 1986:171 (citation given in the original communication). a w 0 35 10103 20181 30300 40395 40479 60561 70641 80720 90810 100 892 110 958 120 1013 130 1072 140 1118 150 1168 160 1195 170 1208 The published results are (Koops 1986:173) Table 2: Constant estimates for the multiphasic growth curve Data set a1b1c1a1b2c2 a3b3c3 Rabbit 198 .048 24.8 352 .025 82.7 62 .051 140.2 Constants ai is in grams and ci in days. Constants bi in 1/(age-units). Table 3. Information about the fit in a stepwise procedure Data set number oferror residualR-square Durbin-Watson phases(n) dfvariance statistic Rabbit 1 151268 .9928 .35 2 1297 .9996 1.39 3 9 40 . 2.78 4 6 47 . 3.19 My question is if it is possible to effect a multiphasic analysis in R and if so how? Thank you very much, Peter B. Laboratorio de Informática, Facultad de Medicina, UASLP, SLP, SLP, MEX Departamento de Epidemiología Clínica, Facultad de Medicina, UASLP, SLP, SLP, MEX Peter B. Mandeville cel:444 860 3204 tel: 52 444 826 2346-49 ext 532 fax: 52 444 826 2350 P.D. Favor de confirmar la llegada de este correo. Gracias. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] tcl/tk help
I am running R 2.5 on a Mac platform and have a difficulty loading the Tcl/Tk package. Specifically: Rlibrary(tcltk) Loading Tcl/Tk interface ... Error in fun(...) : couldn't connect to display :0 Error : .onLoad failed in 'loadNamespace' for 'tcltk' Error: package/namespace load failed for 'tcltk' Is there an explanation to this problem? Thank you very much. Jon Loehrke Fisheries Graduate Research Assistant School for Marine Science and Technology UMASS-Dartmouth 838 S. Rodney French Blvd. New Bedford, MA 02744 Phone: 508-910-6393 Fax: 508-910-6396 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with color coded bar graph
Thanks to all who replied (and very quickly). Unfortunatly I was not clear enough as to my intentions. My goal is to replicate a graph I saw in the work by Perry, Miller and Enright in A comparison of methods for the statistical analysis of spatial point patterns in plant ecology (http://www.springerlink.com/content/ 013275pp7376v0hx). For those without the article here is a copy of the graph in question (replicated without permission) http:// img511.imageshack.us/img511/8720/barexamplejl8.png. As you can see in the example, there are several hoizontal bars, colored by the values in an array (one for each bar). I've been thinking of following your examples but setting it to stack, such that all the elements would be placed one on top another. While this may work it seems particularly ungraceful. Again, thanks for the help. -Luis Naver On Sep 7, 2007, at 1:21 PM, Marc Schwartz wrote: On Fri, 2007-09-07 at 15:07 -0500, Marc Schwartz wrote: On Fri, 2007-09-07 at 12:45 -0700, Luis Naver wrote: I have a list of observations that are -1, 1 or 0. I would like to represent them in a horizontal bar color coded based on value like a stacked bar graph. I can achieve this in the form of a png with the following code: A = floor(runif(10)*3) - 1 png(width=100, height=10) par(mar=c(0,0,0,0)) image(matrix(A), col=grey(c(0.1, 0.5, 0.9))) dev.off() However I would like to do this with one of the standard plotting tools (i.e. barplot) to take advantage of labels and multiple series. Any help would be appreciated. - Luis Naver How about this: barplot(rep(1, length(A)), col = black, space = 0, border = 0) barplot(A, col = grey(0.9), space = 0, border = 0, add = TRUE) The first call sets the plot region to black, ensuring that the x and y axes are consistent with the second call. Alternatively, you can use barplot2() in the gplots CRAN package to do this in a single call, as it has an argument to color the plot region. Actually, here is an easier way: barplot(rep(1, length(A)), col = ifelse(A == 0, black, grey(0.9)), space = 0, border = 0) Just set 'col' based upon the value in 'A'. HTH, Marc __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] enable object name to be called as object (a dataset)
This should work: do.call(cbind, lapply(1:length(obj), function(i) get(obj[i])[,1])) Best, Giovanni Date: Fri, 07 Sep 2007 14:42:07 -0700 (PDT) From: runner [EMAIL PROTECTED] Sender: [EMAIL PROTECTED] Precedence: list What I am trying to do is as follows: - I have listed names of all wanted objects (datasets A,B,C... ) in current workspace as a vector: obj - c('A','B','C') - then i need to use these objects, say to extract all the 1st columns and bind to an existing dataset ('data'): for ( i in 1:3){ newdata - obj[i] data - cbind(data,newdata [[1]] ) } Obviously, it doesn't work since obj[i] is just a string of dataset name. Here is my question: how to call it as a original dataset? Thanks. -- View this message in context: http://www.nabble.com/enable-object-name-to-be-called-as-object-%28a-dataset%29-tf4403933.html#a12563767 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Giovanni Petris [EMAIL PROTECTED] Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tcl/tk help
See http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#TclTk-issues Gabor On Fri, Sep 07, 2007 at 05:59:31PM -0400, Jon Loehrke wrote: I am running R 2.5 on a Mac platform and have a difficulty loading the Tcl/Tk package. Specifically: Rlibrary(tcltk) Loading Tcl/Tk interface ... Error in fun(...) : couldn't connect to display :0 Error : .onLoad failed in 'loadNamespace' for 'tcltk' Error: package/namespace load failed for 'tcltk' Is there an explanation to this problem? Thank you very much. Jon Loehrke Fisheries Graduate Research Assistant School for Marine Science and Technology UMASS-Dartmouth 838 S. Rodney French Blvd. New Bedford, MA 02744 Phone: 508-910-6393 Fax: 508-910-6396 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Csardi Gabor [EMAIL PROTECTED]MTA RMKI, ELTE TTK __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] enable object name to be called as object (a dataset)
get might be good enough for you: a - 10 name - a get(a) [1] 10 get(name) [1] 10 Gabor On Fri, Sep 07, 2007 at 02:42:07PM -0700, runner wrote: What I am trying to do is as follows: - I have listed names of all wanted objects (datasets A,B,C... ) in current workspace as a vector: obj - c('A','B','C') - then i need to use these objects, say to extract all the 1st columns and bind to an existing dataset ('data'): for ( i in 1:3){ newdata - obj[i] data - cbind(data,newdata [[1]] ) } Obviously, it doesn't work since obj[i] is just a string of dataset name. Here is my question: how to call it as a original dataset? Thanks. -- View this message in context: http://www.nabble.com/enable-object-name-to-be-called-as-object-%28a-dataset%29-tf4403933.html#a12563767 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Csardi Gabor [EMAIL PROTECTED]MTA RMKI, ELTE TTK __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Optimization under an absolute value constraint
On 9/7/07, Phil Xiang [EMAIL PROTECTED] wrote: I need to optimize a multivariate function f(w, x, y, z, ...) under an absolute value constraint. For instance: min { (2x+y) (w-z) } under the constraint: |w| + |x| + |y| + |z| = 1.0 . Is there any R function that does this? Thank you for your help! I think that the minimum value of the function f(x) := -2*x*(1-x), with 0 = x = 1 is also the minimum value of the objective function of your problem (but correct me if I am wrong). Thus, x y w z -0.50 0 -0.5 -0.50 0.1 -0.4 -0.50 0.3 -0.2 0.5 0 -0.50 -0.50 0.5 0 0.5 0 -0.40.1 0.5 0 -0.20.3 0.5 0 0 0.5 are all solutions for your problem. Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plotting lines to sets of points
I am using R to plot baseball spray charts from play-by-play data. I have used the following command to plot the diamond: plot (0:250, -250:0, type=n, bg=white) lines(c(125,150,125,100,125),c(-210,-180,-150,-180,-210), col=c(black)) I have also plotted different hit locations using commands such as the following: points(subset(framename$hit_x, framename$hit_traj==line_drive), subset(-framename$hit_y, framename$hit_traj==line_drive), pch=20, col=c(red)) My question: Is there any easy way to plot a line from the origin (home plate) to each point on the graph? Preferably the line would share the same color as the dot that denotes where the ball landed. I have tried searching Google and these forums, and most graphing questions have to do with scatterplots or other varieties of graphs I am not using. Thanks very much in advance. -Jason -- View this message in context: http://www.nabble.com/Plotting-lines-to-sets-of-points-tf4404235.html#a12564704 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] negative value for AIC and BIC
Sure -2*log(x) can be negative, and it can outweigh the k*npar term. Just do: curve(-2*log(x)+2, 0.1, 10) # for AIC with npar = 1 abline(h=0, v=exp(1), lty=3) However, that only happens for x exp(1) or even bigger if npar 1. I think Olivier's real question is: do we believe in likelihoods 1 ? Cheers, Mike. Hannu Kahra wrote: Olivier, type ?AIC and have a look at the description Description: Generic function calculating the Akaike information criterion for one or several fitted model objects for which a log-likelihood value can be obtained, according to the formula -2*log-likelihood + k*npar, where npar represents the number of parameters in the fitted model, and k = 2 for the usual AIC, or k = log(n) (n the number of observations) for the so-called BIC or SBC (Schwarz's Bayesian criterion). AIC = -2*log-likelihood + k*npar can be negative as SBC, too. Hannu On 9/7/07, Olivier MARTIN [EMAIL PROTECTED] wrote: Hi all, I obtained negative values for AIC and BIC criteria for a particular model that I have developped... I don't remember to have negative values for these crietria for others applications, so I am a little suprised... Could anyone tell me if something is wrong or his conclusion concerning my model? Best regards, Olivier. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/negative-value-for-AIC-and-BIC-tf4400285.html#a12565296 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] remove particular elements in a vector
Hi, Is there any build-in function allowing us to remove a particular group of elements in a vector? For example, if I want to remove all the NA in the output of answer function . Please help. Thanks answer(100) [1] 1 2 NA 4 NA NA 7 8 NA NA 11 NA 13 14 NA 16 17 NA 19 NA NA 22 23 NA NA [26] 26 NA 28 29 NA 31 32 NA 34 NA NA 37 38 NA NA 41 NA 43 44 NA 46 47 NA 49 NA [51] NA 52 53 NA NA 56 NA 58 59 NA 61 62 NA 64 NA NA 67 68 NA NA 71 NA 73 74 NA [76] 76 77 NA 79 NA NA 82 83 NA NA 86 NA 88 89 NA 91 92 NA 94 NA NA 97 98 NA NA -- View this message in context: http://www.nabble.com/remove-particular-elements-in-a-vector-tf4404489.html#a12565480 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] sqldf rocks
Man, I love this package and the guy who contributes it! -- === I am dying with the help of too many physicians. - Alexander the Great, on his deathbed === WenSui Liu (http://spaces.msn.com/statcompute/blog) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Running a PERL script from R
On Fri, 7 Sep 2007, Pierce, Ken wrote: I've tried various configurations of .script, system and shell to no avail. It seems to pause and run something but then no output is created. Works for me: cat( 'print Hello World\n;',file=hello.pl ) system(perl hello.pl) Hello World Maybe a path issue? -Original Message- From: Dirk Eddelbuettel [mailto:[EMAIL PROTECTED] Sent: Friday, September 07, 2007 1:11 PM To: Pierce, Ken Cc: r-help Subject: Re: [R] Running a PERL script from R On Fri, Sep 07, 2007 at 12:15:51PM -0700, Pierce, Ken wrote: Is there a way to run a simple perl script from R? ?system Hth, Dirk -- Three out of two people have difficulties with fractions. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to obtain parameters of a mixture model of two lognormal distributions
On Fri, 7 Sep 2007, Jacques Wagnor wrote: Dear List, I have read that a lognormal mixture model having a pdf of the form f(x)=w1*f1(x)+(1-w1)*f2(x) fits most data sets quite well, where f1 and f2 are lognormal distributions. Whoa! There have to be a lot of qualifiers on an assertion like that!! It will not fit these data well: y - rnorm(100) Any pointers on how to create a function that would produce the 5 parameters of f(x) would be greatly appreciated. Produce? Do you mean _estimate_ perchance? The usual advice: Read the posting guide and follow the advice there, which would include trying stuff like the following... ?lognormal # fails but suggests help.search(lognormal) help.search(lognormal) # bingo! It was 'Lognormal' I needed ?Lognormal # now read the help page and find dlnorm RSiteSearch(fit mixture) help.search(mle) and so on. And isn't a mixture of lognormals also a mixture of normals if you log transform the data? ;-) If so, you are almost done, thanks to the hits in RSiteSearch(fit mixture). Chuck p.s. if all you want is to 'fit data', try the logspline package or any of the other density estimation tools in R or on CRAN. version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 5.1 year 2007 month 06 day27 svn rev42083 language R version.string R version 2.5.1 (2007-06-27) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem with the aggregate command
Dear friends, I have a data set with 23 columns and 38000 rows. It is a panel running from the years 1991 through 2005. I want to aggregate the data and get the medians of each of the 23 columns for each of the years. In other words my output should be like this Year Median 1991123 1992145 1993132 etc. The sample lines of code to do this operation is set1 - subset(as.data.frame(dataset),rep1==1) set2 - subset(as.data.frame(dataset),rep1==0) lst - list(unique(yeara)) y1 - aggregate(set1,lst,median) y2 - aggregate(set2,lst,median) However I'm getting an error as follows Error in FUN(X[[1]], ...) : arguments must have same length Can somebody please help me with what I'm doing wrong here? Thanks in advance Regards Anup - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R first.id last.id function error
This function should do it for you: file1 - read.table(textConnection( id rx week dv1 + 1 1 11 1 + 2 1 12 1 + 3 1 13 2 + 4 2 11 3 + 5 2 12 4 + 6 2 13 1 + 7 3 11 2 + 8 3 12 3 + 9 3 13 4 + 10 4 11 2 + 11 4 12 6 + 12 4 13 5 + 13 5 21 7 + 14 5 22 8 + 15 5 23 5 + 16 6 21 2 + 17 6 22 4 + 18 6 23 6 + 19 7 21 7 + 20 7 22 8 + 21 8 21 9 + 22 9 21 4 + 23 9 22 5), header=TRUE) mark.function - + function(df){ + df - df[order(df$id, df$week),] + # create 'diff' of 'id' to determine where the breaks are + breaks - diff(df$id) + # the first entry will be TRUE, and then every occurance of non-zero in breaks + df$first.id - c(TRUE, breaks != 0) + # the last entry is TRUE and every non-zero breaks + df$last.id - c(breaks != 0, TRUE) + df + } mark.function(file1) id rx week dv1 first.id last.id 1 1 11 1 TRUE FALSE 2 1 12 1FALSE FALSE 3 1 13 2FALSETRUE 4 2 11 3 TRUE FALSE 5 2 12 4FALSE FALSE 6 2 13 1FALSETRUE 7 3 11 2 TRUE FALSE 8 3 12 3FALSE FALSE 9 3 13 4FALSETRUE 10 4 11 2 TRUE FALSE 11 4 12 6FALSE FALSE 12 4 13 5FALSETRUE 13 5 21 7 TRUE FALSE 14 5 22 8FALSE FALSE 15 5 23 5FALSETRUE 16 6 21 2 TRUE FALSE 17 6 22 4FALSE FALSE 18 6 23 6FALSETRUE 19 7 21 7 TRUE FALSE 20 7 22 8FALSETRUE 21 8 21 9 TRUETRUE 22 9 21 4 TRUE FALSE 23 9 22 5FALSETRUE On 9/7/07, Gerard Smits [EMAIL PROTECTED] wrote: Hi R users, I have a test dataframe (file1, shown below) for which I am trying to create a flag for the first and last ID record (equivalent to SAS first.id and last.id variables. Dump of file1: file1 id rx week dv1 1 1 11 1 2 1 12 1 3 1 13 2 4 2 11 3 5 2 12 4 6 2 13 1 7 3 11 2 8 3 12 3 9 3 13 4 10 4 11 2 11 4 12 6 12 4 13 5 13 5 21 7 14 5 22 8 15 5 23 5 16 6 21 2 17 6 22 4 18 6 23 6 19 7 21 7 20 7 22 8 21 8 21 9 22 9 21 4 23 9 22 5 I have written code that correctly assigns the first.id and last.id variabes: require(Hmisc) #for Lags #ascending order to define first dot file1- file1[order(file1$id, file1$week),] file1$first.id - (Lag(file1$id) != file1$id) file1$first.id[1]-TRUE #force NA to TRUE #descending order to define last dot file1- file1[order(-file1$id,-file1$week),] file1$last.id - (Lag(file1$id) != file1$id) file1$last.id[1]-TRUE #force NA to TRUE #resort to original order file1- file1[order(file1$id,file1$week),] I am now trying to get the above code to work as a function, and am clearly doing something wrong: first.last - function (df, idvar, sortvars1, sortvars2) + { + #sort in ascending order to define first dot + df- df[order(sortvars1),] + df$first.idvar - (Lag(df$idvar) != df$idvar) + #force first record NA to TRUE + df$first.idvar[1]-TRUE + + #sort in descending order to define last dot + df- df[order(-sortvars2),] + df$last.idvar - (Lag(df$idvar) != df$idvar) + #force last record NA to TRUE + df$last.idvar[1]-TRUE + + #resort to original order + df- df[order(sortvars1),] + } Function call: first.last(df=file1, idvar=file1$id, sortvars1=c(file1$id,file1$week), sortvars2=c(-file1$id,-file1$week)) R Error: Error in as.vector(x, mode) : invalid argument 'mode' I am not sure about the passing of the sort strings. Perhaps this is were things are off. Any help greatly appreciated. Thanks, Gerard [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting lines to sets of points
?segments On 9/7/07, lawnboy34 [EMAIL PROTECTED] wrote: I am using R to plot baseball spray charts from play-by-play data. I have used the following command to plot the diamond: plot (0:250, -250:0, type=n, bg=white) lines(c(125,150,125,100,125),c(-210,-180,-150,-180,-210), col=c(black)) I have also plotted different hit locations using commands such as the following: points(subset(framename$hit_x, framename$hit_traj==line_drive), subset(-framename$hit_y, framename$hit_traj==line_drive), pch=20, col=c(red)) My question: Is there any easy way to plot a line from the origin (home plate) to each point on the graph? Preferably the line would share the same color as the dot that denotes where the ball landed. I have tried searching Google and these forums, and most graphing questions have to do with scatterplots or other varieties of graphs I am not using. Thanks very much in advance. -Jason -- View this message in context: http://www.nabble.com/Plotting-lines-to-sets-of-points-tf4404235.html#a12564704 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem with the Aggregate command (PS)
Dear Friends, I forgot to add, the idea is to aggregate the entire dataset based on year and get the median value for each of the columns. Hence the output should be like this YearX1 X2X3 ... 1991102030... 199230 2010... 1993 4 5 6.. .... .... .... 2005100200300.. Thanks and Regards Anup - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] remove particular elements in a vector
x - answer(100) x - x[!is.na(x)] # remove NAs On 9/7/07, kevinchang [EMAIL PROTECTED] wrote: Hi, Is there any build-in function allowing us to remove a particular group of elements in a vector? For example, if I want to remove all the NA in the output of answer function . Please help. Thanks answer(100) [1] 1 2 NA 4 NA NA 7 8 NA NA 11 NA 13 14 NA 16 17 NA 19 NA NA 22 23 NA NA [26] 26 NA 28 29 NA 31 32 NA 34 NA NA 37 38 NA NA 41 NA 43 44 NA 46 47 NA 49 NA [51] NA 52 53 NA NA 56 NA 58 59 NA 61 62 NA 64 NA NA 67 68 NA NA 71 NA 73 74 NA [76] 76 77 NA 79 NA NA 82 83 NA NA 86 NA 88 89 NA 91 92 NA 94 NA NA 97 98 NA NA -- View this message in context: http://www.nabble.com/remove-particular-elements-in-a-vector-tf4404489.html#a12565480 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with the aggregate command
Your 'lst' is not the same length as either set1 or set2. If one of your columns in the dataframe is the year, then you should have: aggregate(set1, set1$year, median) On 9/7/07, Anup Nandialath [EMAIL PROTECTED] wrote: Dear friends, I have a data set with 23 columns and 38000 rows. It is a panel running from the years 1991 through 2005. I want to aggregate the data and get the medians of each of the 23 columns for each of the years. In other words my output should be like this Year Median 1991123 1992145 1993132 etc. The sample lines of code to do this operation is set1 - subset(as.data.frame(dataset),rep1==1) set2 - subset(as.data.frame(dataset),rep1==0) lst - list(unique(yeara)) y1 - aggregate(set1,lst,median) y2 - aggregate(set2,lst,median) However I'm getting an error as follows Error in FUN(X[[1]], ...) : arguments must have same length Can somebody please help me with what I'm doing wrong here? Thanks in advance Regards Anup - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lisp-like primitives in R
[Duncan Murdoch] You could also look at Ross Ihaka's paper that is online here: http://cran.r-project.org/doc/html/interface98-paper/paper.html Interesting read. Thanks for this reference! -- François Pinard http://pinard.progiciels-bpi.ca __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lisp-like primitives in R
[Roland Rau] [François Pinard] I wonder what happened, for R to hide the underlying Scheme so fully, at least at the level of the surface language (despite there are hints). To further foster portability, we chose to write R in ANSI C Yes, of course. Scheme is also (often) implemented in C. I meant that R might have implemented a Scheme engine (or part of a Scheme engine, extended with appropriate data types) with a surface language (nearly the S language) which is purposely not Scheme, but could have been. If the gap is not extreme, one could dare dreaming that the Scheme engine in R be completed, and Scheme offered as an alternate extension language. If you allow me to continue dreaming awake -- they told me they will let me free as long as I do not get dangerous! :-) -- part of the interest lies in the fact there are excellent Scheme compilers. If we could only find or devise some kind of marriage between a mature Scheme and R, so to speed up the non-vectorisable parts of R scripts... If we are lucky and one of the original authors reads this thread they might explain the situation further and better [...]. In r-devel, maybe! We would be lucky if the authors really had time to read r-help. :-) -- François Pinard http://pinard.progiciels-bpi.ca __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R first.id last.id function error
A slightly easier way to construct first and last if the vector x is sorted (as is assumed in SAS) is: first - !duplicated(x) last - !duplicated(x, fromLast = TRUE) where the fromLast= argument is added in R 2.6.0. On 9/7/07, Gerard Smits [EMAIL PROTECTED] wrote: Hi R users, I have a test dataframe (file1, shown below) for which I am trying to create a flag for the first and last ID record (equivalent to SAS first.id and last.id variables. Dump of file1: file1 id rx week dv1 1 1 11 1 2 1 12 1 3 1 13 2 4 2 11 3 5 2 12 4 6 2 13 1 7 3 11 2 8 3 12 3 9 3 13 4 10 4 11 2 11 4 12 6 12 4 13 5 13 5 21 7 14 5 22 8 15 5 23 5 16 6 21 2 17 6 22 4 18 6 23 6 19 7 21 7 20 7 22 8 21 8 21 9 22 9 21 4 23 9 22 5 I have written code that correctly assigns the first.id and last.id variabes: require(Hmisc) #for Lags #ascending order to define first dot file1- file1[order(file1$id, file1$week),] file1$first.id - (Lag(file1$id) != file1$id) file1$first.id[1]-TRUE #force NA to TRUE #descending order to define last dot file1- file1[order(-file1$id,-file1$week),] file1$last.id - (Lag(file1$id) != file1$id) file1$last.id[1]-TRUE #force NA to TRUE #resort to original order file1- file1[order(file1$id,file1$week),] I am now trying to get the above code to work as a function, and am clearly doing something wrong: first.last - function (df, idvar, sortvars1, sortvars2) + { + #sort in ascending order to define first dot + df- df[order(sortvars1),] + df$first.idvar - (Lag(df$idvar) != df$idvar) + #force first record NA to TRUE + df$first.idvar[1]-TRUE + + #sort in descending order to define last dot + df- df[order(-sortvars2),] + df$last.idvar - (Lag(df$idvar) != df$idvar) + #force last record NA to TRUE + df$last.idvar[1]-TRUE + + #resort to original order + df- df[order(sortvars1),] + } Function call: first.last(df=file1, idvar=file1$id, sortvars1=c(file1$id,file1$week), sortvars2=c(-file1$id,-file1$week)) R Error: Error in as.vector(x, mode) : invalid argument 'mode' I am not sure about the passing of the sort strings. Perhaps this is were things are off. Any help greatly appreciated. Thanks, Gerard [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ggplot legend consolidation
Hello Everyone, I have recently been introduced to the ggplot package by Hadley Wickham and must say I am quite impressed so far at how easy it is to make attractive plots, but one thing I am struggling over is how to consolidate legends. I have 3 plots that I would like to put on a single page and all 3 map the same dimension of the data to the colour aesthetic. Right now, when I plot all three graphs on the page, I get the three graphs and three legends. The legends are exactly the same. I do not see a reason to have all 3 legends and I would like to partition a section of the page exclusively for a single legend that would apply to all graphs. How does one exract the legend for this purpose? Does anyone know how to do this with the ggplot package? Here is some example code: --- BEGIN CODE library(ggplot2) data(mtcars) grid.newpage() pushViewport(viewport(layout = grid.layout(2, 2))) p - ggplot(data = mtcars) + geom_point(mapping = aes(x = hp, y = mpg, colour = cyl)) pushViewport(viewport(layout.pos.col = 1, layout.pos.row = 1)) print(p, vp = current.viewport()) upViewport() p - ggplot(data = mtcars) + geom_point(mapping = aes(x = drat, y = disp, colour = cyl)) pushViewport(viewport(layout.pos.col = 2, layout.pos.row = 1)) print(p, vp = current.viewport()) upViewport() p - ggplot(data = mtcars) + geom_point(mapping = aes(x = qsec, y = mpg, colour = cyl)) pushViewport(viewport(layout.pos.col = 1, layout.pos.row = 2)) print(p, vp = current.viewport()) upViewport() pushViewport(viewport(layout.pos.col = 2, layout.pos.row = 2)) grid.rect() grid.text(We want to remove\nall other legends\nand place a\nsingle one here) --- END CODE See how there are 3 legends when there only needs to be one? I would like to remove the 3 legends and place them with a single legend in the space in the lower right. Thanks for your help. Regards, Kaom Te Charles Schwab Investment Management (CSIM) 120 Kearny Street, 14th Floor San Francisco, CA 94108 E-mail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] WARNING: All email sent to or from the Charles Schwab corporate email system is subject to archiving, monitoring and/or review by Schwab personnel. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.