Re: [R] Urgent help requested to modify a script
On 10/16/2009 11:01 PM, one2luv wrote: I am hoping someone will tak up this chalenge (I am new to R) I have inheritied an R script but need to change it. The script currently includes hardcoded file locations on lines 12,166 and 167. I need to modify this script to allow the folder to be passed as a command line argument to Rscript.exe Hi Ian, You can do something like this: pdfoutputfile-/home/jim/R/Rplots.pdf pdf(pdfoutputfile,...) and similarly for the other instances. Unfortunately, you can't just define a path and pass it as an argument, for functions like pdf and read.csv won't stick the path and filename together unless you write a wrapper for each function that creates the complete path/filename and then passes it to the original function. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Generating a stochastic matrix with a specified second dominant eigenvalue
Ravi Varadhan wrote: Hi, Given a positive integer N, and a real number \lambda such that 0 \lambda 1, I would like to generate an N by N stochastic matrix (a matrix with all the rows summing to 1), such that it has the second largest eigenvalue equal to \lambda (Note: the dominant eigenvalue of a stochastic matrix is 1). I don't care what the other eigenvalues are. The second eigenvalue is important in that it governs the rate at which the random process given by the stochastic matrix converges to its stationary distribution. An idea... Form a vector e of desired eigenvalues where the first eigenvalue is 1, the second is \lambda, and the remaining eigenvalues are whatever is convenient (i*\lambda_i/(N-2) where i=0:(N-3) for example if repeated eigenvalues would be inconvenient). Then form A=diag(e) and modify it to make the matrix stochastic by replacing the element just below lambda_i with (1-lambda_i) until you get to the lambda_N, where A[1,N] would be set to (1-lambda_N). If \lambda=0.8, then we could form e - c(1, 0.8, 0.6, 0.4, 0.2) then I think your desired matrix A is A - diag(e) A[3,2] - 1-e[2] A[4,3] - 1-e[3] A[5,4] - 1-e[4] A[1,5] - 1-e[5] eigen(A) -- --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Modify the plot from countCDFxt
Michelle DePrenger-Levin wrote: Hello, I am running the plot from countCDFxt (popbio). I would like to report the y-axis as a percent instead of the log scale (e^01...). I can add an axis with axis(2, 0:1, line =2) but I'm having trouble understanding how to assign the tic marks (with 'at ='). I'd like to tell it to make tics with the percent value (or decimal if that's my only option) at the equivalent of e^-1, e^-2, etc, but the values don't seem to line up correctly. I'd also like to replace the provided axis with my axis instead of just placing my axis out a line but I'm unsure how to do that. library(popbio) logNE - log(erbr$NEast[-1]/erbr$NEast[-6]) countCDFxt(mean(logNE), var(logNE), nt=5, Nc=1317, Ne=200) axis(2, 0:1, labels = c(0.018, 0.050, 0.135, 0.368, 1), at = c(0.018, 0.050, 0.135, 0.368, 1), line =1) YearNEast NWest 2004731 1732 2005898 2004 2006714 1130 20071748 1722 20081901 1661 20091317 1563 1. How do I tell axis() to report as a percent? The function countCDFxt() is unfortunately quite inflexible. The only way to change the axis is to modify the function. Fortunately, it's a pretty simple function. Just modify the plotting part. 2. Why don't my values in label and at match the given axis? Because you don't provide the correct at=...? You should be able to just set at=c(1e-2, 1e-1, ...) as displayed on the plot. 3. How do I replace the axis label in countCDFxt? Again, the only way is to rewrite the function, perhaps to allow additional graphics parameters like yaxt=n. What's that '0:1' doing in your axis() call? [Please look up the definition of reproducible. See bottom of this post.] -Peter Ehlers Thanks for any help, Michelle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to have tkchooseDirectory resize in windows?
David Gattrell wrote: R-2.8.0 / tcltk8.5 In windows, Rgui.exe has a directory browser that can be resized, but when I call tkchooseDirectory(), it is a fixed size. In linux, when I call tkchooseDirectory() it can be resized. How do I get a windows version that I can resize? You're at the mercy of Tcl/Tk itself here, and in turn they are at the mercy of Microsoft and back compatibility issues. (I.e. Windows itself has had a new-style dialog for a while, but Tk hasn't been setting the appropriate flag.) Judging by the thread at http://www.rhinocerus.net/forum/lang-tcl/556193-modernizing-windows-tk_choosedirectory-dialog.html a modernized Windows tk_chooseDirectory is going into Tcl/Tk 8.5.8. -- 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 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] sum two columns with same value
Hi, I've two dataframe: snag_totale AREA snag_ha 12 1.628128 23 10.274249 34 2.778503 45 73.764307 57 12.015985 log_totale AREAlog_ha 11 22.29846 22 17.16889 33 48.80377 44 144.18996 55 70.30962 66 61.81850 77 13.24876 How can I obtain a new data.frame, by the sum of value snag_ha + log_ha in the same AREA? Like this: AREA sum 11 22.29846 22 18.79702 33 59.07801 44 146.96847 55 144.07392 66 61.81850 77 25.26474 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] attach
Dieter Menne wrote: Christophe Dutang1 wrote: I would like to know what happens on the memory side when I use attach(inputdata) Is there a second allocation of memory for inputdata? Not, it just guides the syntax. Wrong. There's a virtual copy of data plus a conversion from data frame to attached environment on the search path. If you modify data in either of the original frame or the environment, you will get duplication. Christophe Dutang1 wrote: Is it better not to use attach function? A qualified yes in the sense of do not use it. I think it is used to much in old documentation, presumably because some S eggshells. I use with() if I have a nasty formula to unclutter; it acts locally only and you don't get unwanted side effects. Well, opinions vary. Having to qualify data frame access on each use does tend to get in the way of explorative work, at least it does so for me. -- 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 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] the number of components of the mixture model and the stratfied data
Hi,all with my data,there are more than 1000 quantitative results of antibody concentrations, there may be 2 components(positive and negative), or 3 components (may be strong positive, positive, and negative), or 4-6 components. Could you tell me how to determine the number of components of the mixture model? the anova.mix in mixdist of the R software seems not work. my data is a little complicated(TABLE ), there are more than 1000 quantitative results of antibody concentrations stratified by age.The overall density of results at age j, Fj, is a mixture of the component densities, so if there are 5 age groups, then there will be 5 mixture models. Do i have to analyse each stratum respectively? TABLE age Bin length freq 1 1 19.75 4 1 2 21.7510 11241.7536 2 1 19.75 4 2 2 21.7510 21241.7536 --- appreciated lybao -- View this message in context: http://www.nabble.com/the-number-of-components-of-the-mixture-model-and-the-stratfied-data-tp25935531p25935531.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum two columns with same value
On Sat, Oct 17, 2009 at 09:36:50AM +0200, Alfredo Alessandrini wrote: Hi, I've two dataframe: snag_totale AREA snag_ha 12 1.628128 23 10.274249 34 2.778503 45 73.764307 57 12.015985 log_totale AREAlog_ha 11 22.29846 22 17.16889 33 48.80377 44 144.18996 55 70.30962 66 61.81850 77 13.24876 How can I obtain a new data.frame, by the sum of value snag_ha + log_ha in the same AREA? one way would be: tmp - merge(snag_totale, log_totale, by=AREA) tmp$sum - tmp$snag_ha + tmp$log_ha regards, stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ozone data
On 10/17/09, Julius Tesoro jutes...@yahoo.com wrote: I am looking at the plyr package and I am intrigued at how data(i.e. ozone, baseball) is loaded without having to type data(ozone). Are they automatically loaded when i call library(plyr)? I want to do the same thing when I make my package. How does one accomplish this? I don't know how this is achieved, but try looking at the source code for the package. Also, are there any beginner guides on how to make a package? I would not call this a beginner's guide, but here's the standard reference [1]. This is what I wrote some time ago in an off-list message: When I published my first (and still only) R package I also found it daunting to get it working. Perhaps the easiest way to get it going---at least it worked for me---would be to: - take the source archive of an existing package with a very-simple-structure (nortest or even Rcmdr) or a package that would be very similar to what you need [consider the potential licence issues, though] - get rid of/replace files as needed - not forget to run R CMD check (to check that the code conforms to CRAN requirements) and R CMD build (to build the release tarball) - then what rests to do is drop the latter on the CRAN FTP server. It's been some time that I did this, so there might be some missing step. Hope this is of help. Best, Liviu [1] http://cran.r-project.org/doc/manuals/R-exts.pdf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ozone data
On 10/17/09, Julius Tesoro jutes...@yahoo.com wrote: wow thanks but how do i load data just by typing ozone on the console? It would probably suffice to include the dataset as an object in your package, and then `data(ozone)' should bring it up as soon as your package is loaded. Look at the source code of any package offering such data set (there are plenty built-in data sets: Angell, iris, maryo, mtcars, etc., etc.). You can use rseek or package(sos) to pinpoint the exact files of interest. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] avoiding loops in equation
thank you very much --- On Sat, 10/17/09, Kenn Konstabel lebats...@gmail.com wrote: From: Kenn Konstabel lebats...@gmail.com Subject: Re: [R] avoiding loops in equation Thank God for R-help mailing list. Thanks.. To: Julius Tesoro jutes...@yahoo.com Date: Saturday, October 17, 2009, 1:51 PM a3 - sapply(acc, function(x) pex(x,pga,std), simplify=FALSE) do.call(rbind, a3) # On Sat, Oct 17, 2009 at 5:51 AM, Julius Tesoro jutes...@yahoo.com wrote: To illustrate my problem, I have a complex code of several matrices and a vector. To simplify I only used two matrices and a vector as an example: pex-function(acc, pga, std){ (acc-pga)/std } acc-seq(.1,1,.1) pga-matrix(rnorm(9,4,.1),3,3) std-matrix(rnorm(9,4,.5),3,3) I tried calculating the above function for each element of acc using: for (x in 1:length(acc)){ a1-pex(acc[x],pga,std) if(x==1){a2-a1 }else {a2-rbind(a2,a1) } I want to recode the following using sapply a2-sapply(acc, function(x) pex(x,pga,std)) but what I get is a different result. Anyone knows how to rewrite the above function without using loops? Thanks everyone. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] custom selfStart model works with getInitial but not nls
On Fri, Oct 16, 2009 at 7:09 PM, Michael A. Gilchrist mi...@utk.edu wrote: Hello, I'm having problems creating and using a selfStart model with nlme. Briefly, I've defined the model, a selfStart object, and then combined them to make a selfStart.default model. If I apply getInitial to the selfStart model, I get results. However, if I try usint it with nls or nlsList, these routines complain about a lack of initial conditions. If someone could point out what I'm doing wrong, I'd greatly appreciate it. Thanks for providing the code. Could you also provide some data as a test case? Details: ## Nonlinear model I want to fit to the data const.PBMC.tcell.model - function(B0, t, aL, aN, T0){ Tb0 = B0; x = exp(-log(aL) + log(T0*aL+(-1+exp(t * aL))*Tb0 * aN) - t * aL); return(x); } ##Define selfStart routine const.PBMC.tcell.selfStart- function(mCall, LHS, data){ t0 = 0; t1 = 24; t2 = 48; ##Get B0 Value B0 = data[1, B0]; T0 = mean(data[data$Time==t0, Count]); T1 = mean(data[data$Time==t1, Count]); T2 = mean(data[data$Time==t2, Count]); if(T0 T2){ ##increase -- doesn't work stop(paste(Error in const.PBMC.tcell.start: T0 T2 for data: , data[1, ])); } ##Estimate aL based on exponential decline from t=0 to t=24 aLVal = -(log(T1) - log(T0))/(t1-t0); ##Estimate aNVal based on final value aNVal = aLVal*T2/B0; values = list(aLVal, aNVal, T0); names(values) - mCall[c(aL, aN, T0)]; #mimic syntax used by PB return(values) } ##Now create new model with selfStart attributes const.PBMC.tcell.modelSS- selfStart(model = const.PBMC.tcell.model, initial=const.PBMC.tcell.selfStart) ##Test routines using getInitial -- This works getInitial(Count ~ const.PBMC.tcell.modelSS(B0, Time,aL, aN, T0), data = tissueData) [1] 0.05720924 $aL [1] 0.05720924 $aN [1] 0.1981895 $T0 [1] 1360.292 ##Now try to use the SS model -- this doesn't work nls(Count ~ const.PBMC.tcell.modelSS(B0, Time,aL, aN, T0), data = tissueData) Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model In addition: Warning message: In nls(Count ~ const.PBMC.tcell.modelSS(B0, Time, aL, aN, T0), data = tissueData) : No starting values specified for some parameters. Intializing 'aL', 'aN', 'T0' to '1.'. Consider specifying 'start' or using a selfStart model __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Frequencies, proportions cumulative proportions
David, I use CrossTable, so that was my first guess. It'll do proportions/percents by row, column or total in a 2-way table. For 1-way tables, it still tries looks like a 2-way table, unless you specify max.width=1. Then it does one column, but no cumulative proportions (see below). I appreciate the idea though! Thanks, Bob CrossTable(Score, max.width=1) Cell Contents |-| | N | | N / Table Total | |-| Total Observations in Table: 1000 |70 | |---| |44 | | 0.044 | |---| |71 | |---| |42 | | 0.042 | |---| |72 | |---| |40 | | 0.040 | |---| |73 | |---| |40 | | 0.040 | |---| |74 | |---| |43 | | 0.043 | |---| |75 | |---| |45 | | 0.045 | |---| |76 | |---| |46 | | 0.046 | |---| |77 | |---| |40 | | 0.040 | |---| |78 | |---| |46 | | 0.046 | |---| |79 | |---| |43 | | 0.043 | |---| ... -Original Message- From: David Scott [mailto:d.sc...@auckland.ac.nz] Sent: Friday, October 16, 2009 8:42 PM To: Muenchen, Robert A (Bob) Cc: ted.hard...@manchester.ac.uk; r-help@r-project.org Subject: Re: [R] Frequencies, proportions cumulative proportions Muenchen, Robert A (Bob) wrote: Ted, I know how to do that. It's just such a standard display in SAS, SPSS and Stata that I figured someone had done it and I had just overlooked it. Thanks! Bob I don't think there is a ready-made one, but it is very little effort to make your own: mkMyTable - function(X){ Table - data.frame( table(X) ) Table$Prop - prop.table( Table$Freq ) Table$CumProp - cumsum( Table$Prop ) Table } myTable - mkMyTable(Score) Hoping this helps! Ted. I think CrossTable in gmodels does what Bob is after: CrossTable(gmodels) R Documentation Cross Tabulation with Tests for Factor Independence Description An implementation of a cross-tabulation function with output similar to S-Plus crosstabs() and SAS Proc Freq (or SPSS format) with Chi-square, Fisher and McNemar tests of the independence of all table factors. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum two columns with same value
Here are a few ways: Here are a few ways: # 1. using merge m - merge(snag_totale, log_totale, all = TRUE) m[is.na(m)] - 0 with(m, data.frame(AREA, sum = snag_ha + log_ha)) # 2. Use fact that AREA = 1:7 in log_totale sum_totale - log_totale; names(sum_totale)[2] - sum sum_totale$sum[snag_totale$AREA] - log_totale$log_ha[snag_totale$AREA] + snag_totale$snag_ha # 3. using merge.zoo # merge.zoo's fill=0 argument makes zero filling easier library(zoo) snag_zoo - read.zoo(snag_totale) log_zoo - read.zoo(log_totale) z - merge(snag_zoo, log_zoo, all = TRUE, fill = 0) # produce zoo object: z$snag_zoo + z$log_zoo # or produce data frame: data.frame(AREA = time(z), sum = coredata(z$snag_zoo + z$log_zoo)) On Sat, Oct 17, 2009 at 3:36 AM, Alfredo Alessandrini alfreal...@gmail.com wrote: Hi, I've two dataframe: snag_totale AREA snag_ha 1 2 1.628128 2 3 10.274249 3 4 2.778503 4 5 73.764307 5 7 12.015985 log_totale AREA log_ha 1 1 22.29846 2 2 17.16889 3 3 48.80377 4 4 144.18996 5 5 70.30962 6 6 61.81850 7 7 13.24876 How can I obtain a new data.frame, by the sum of value snag_ha + log_ha in the same AREA? Like this: AREA sum 1 1 22.29846 2 2 18.79702 3 3 59.07801 4 4 146.96847 5 5 144.07392 6 6 61.81850 7 7 25.26474 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum two columns with same value
smu wrote: On Sat, Oct 17, 2009 at 09:36:50AM +0200, Alfredo Alessandrini wrote: Hi, I've two dataframe: snag_totale AREA snag_ha 12 1.628128 23 10.274249 34 2.778503 45 73.764307 57 12.015985 log_totale AREAlog_ha 11 22.29846 22 17.16889 33 48.80377 44 144.18996 55 70.30962 66 61.81850 77 13.24876 How can I obtain a new data.frame, by the sum of value snag_ha + log_ha in the same AREA? one way would be: tmp - merge(snag_totale, log_totale, by=AREA) tmp$sum - tmp$snag_ha + tmp$log_ha That will drop the missing rows in snag_totale. Here's a variation that should work: tmp - merge(snag_totale, log_totale, all = TRUE) tmp$Sum - rowSums(tmp[, -1], na.rm = TRUE) tmp -Peter Ehlers regards, stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] custom selfStart model works with getInitial but not nls
On Sat, 17 Oct 2009, Douglas Bates wrote: On Fri, Oct 16, 2009 at 7:09 PM, Michael A. Gilchrist mi...@utk.edu wrote: Hello, I'm having problems creating and using a selfStart model with nlme. Briefly, I've defined the model, a selfStart object, and then combined them to make a selfStart.default model. If I apply getInitial to the selfStart model, I get results. However, if I try usint it with nls or nlsList, these routines complain about a lack of initial conditions. If someone could point out what I'm doing wrong, I'd greatly appreciate it. Thanks for providing the code. Could you also provide some data as a test case? Thanks for looking into this. I've learned a lot from reading your book on nlme (and still have a lot to learn). I've posted the data I've been working with at: www.tiem.utk.edu/~mikeg/software/R/selfStart/tissue.rda Mike Details: ## Nonlinear model I want to fit to the data const.PBMC.tcell.model - function(B0, t, aL, aN, T0){ Tb0 = B0; x = exp(-log(aL) + log(T0*aL+(-1+exp(t * aL))*Tb0 * aN) - t * aL); return(x); } ##Define selfStart routine const.PBMC.tcell.selfStart- function(mCall, LHS, data){ t0 = 0; t1 = 24; t2 = 48; ##Get B0 Value B0 = data[1, B0]; T0 = mean(data[data$Time==t0, Count]); T1 = mean(data[data$Time==t1, Count]); T2 = mean(data[data$Time==t2, Count]); if(T0 T2){ ##increase -- doesn't work stop(paste(Error in const.PBMC.tcell.start: T0 T2 for data: , data[1, ])); } ##Estimate aL based on exponential decline from t=0 to t=24 aLVal = -(log(T1) - log(T0))/(t1-t0); ##Estimate aNVal based on final value aNVal = aLVal*T2/B0; values = list(aLVal, aNVal, T0); names(values) - mCall[c(aL, aN, T0)]; #mimic syntax used by PB return(values) } ##Now create new model with selfStart attributes const.PBMC.tcell.modelSS- selfStart(model = const.PBMC.tcell.model, initial=const.PBMC.tcell.selfStart) ##Test routines using getInitial -- This works getInitial(Count ~ const.PBMC.tcell.modelSS(B0, Time,aL, aN, T0), data = tissueData) [1] 0.05720924 $aL [1] 0.05720924 $aN [1] 0.1981895 $T0 [1] 1360.292 ##Now try to use the SS model -- this doesn't work nls(Count ~ const.PBMC.tcell.modelSS(B0, Time,aL, aN, T0), data = tissueData) Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model In addition: Warning message: In nls(Count ~ const.PBMC.tcell.modelSS(B0, Time, aL, aN, T0), data = tissueData) : No starting values specified for some parameters. Intializing 'aL', 'aN', 'T0' to '1.'. Consider specifying 'start' or using a selfStart model __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] External signal in ODE written in C (using deSolve and approx1?)
Dear Glenn, dear list, this is just a short notice, that a new version 1.5 of package deSolve was released yesterday. It now supports the feature requested below. Details are documented in the package vignette Writing Code in Compiled Languages that comes with the package and is also available online: http://cran.r-project.org/web/packages/deSolve/vignettes/compiledCode.pdf See section 6. Using forcing functions. Thomas Petzoldt (co-author of deSolve) Glenn Woodart wrote: Dear list The deSolve package allows you to specify the model code in C or Fortran. Thanks to the excellent vignette this works fine. However I have not yet managed to use forcing functions in C code. In pure R code this works very well with approxfun() specified outside the model: [...] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] repeating values in levels()
Can someone help me understand this results? levels(as.factor(miset1$facts_convict)) [1] 1 1 2 3 4 5 6 converting to numeric and back doesn't seem to help: levels(as.factor(as.numeric(miset1$facts_convict))) [1] 1 1 2 3 4 5 6 It's messing up my ologits. Any way to correct this? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] generalization of tabulate()
On 16-Oct-09 11:27:06, Gabor Grothendieck wrote: Using the generalized inner product defined in this post: https://www.stat.math.ethz.ch/pipermail/r-help/2006-July/109311.html try this: cbind(S, d = rowSums(inner(S, obs, identical))) The function inner() is defined at the above URL as: # generalized crossproduct inner - function(a,b=a,f=crossprod) apply(b,2,function(x)apply(a,2,function(y)f(x,y))) In order for this approach to work with Robin's 'observation' = 'obs' and 'S' matrices as illustrated by Gabor above, the function inner() should instead be defined as # generalized crossproduct inner - function(a,b=a,f=crossprod) apply(b,1,function(x)apply(a,1,function(y)f(x,y))) i.e. it crosses all rows (dim=1) of 'obs' with all rows (dim=1) of S; using 2 instead of 1 does it by columns. Indeed, a possibly useful more general definition might be # generalized crossproduct inner - function(a,b=a,f=crossprod,dim1=1,dim2=1) apply(b,dim2,function(x)apply(a,dim1,function(y)f(x,y))) allowing either dimension of a to be crossed with either dimension of b. Ted. On Fri, Oct 16, 2009 at 4:29 AM, Robin Hankin rk...@cam.ac.uk wrote: Hi I want a generalization of tabulate() which works on rows of a matrix. Suppose I have an integer matrix 'observation': observation y1 y2 y3 1 4 0 1 4 0 2 0 3 4 1 0 0 5 0 0 1 4 2 0 3 Each row corresponds to a (multivariate) observation. _Note that the first two rows are identical: this means that data c(1,4,0) was observed twice. Now suppose I can list the sample space: S _ _ _ _ [1,] 5 0 0 [2,] 4 1 0 [3,] 3 2 0 [4,] 2 3 0 [5,] 1 4 0 [6,] 0 5 0 [7,] 4 0 1 [8,] 3 1 1 [9,] 2 2 1 [10,] 1 3 1 [11,] 0 4 1 [12,] 3 0 2 [13,] 2 1 2 [14,] 1 2 2 [15,] 0 3 2 [16,] 2 0 3 [17,] 1 1 3 [18,] 0 2 3 [19,] 1 0 4 [20,] 0 1 4 [21,] 0 0 5 (thus each row corresponds to a point in my sample space). Now what I need to do is to construct a new matrix, which uses the 'observation' matrix above, which is a sort of table: desired _ _ y1 y2 y3 d [1,] 5 0 0 0 [2,] 4 1 0 1 [3,] 3 2 0 0 [4,] 2 3 0 0 [5,] 1 4 0 2 [6,] 0 5 0 1 [7,] 4 0 1 0 [8,] 3 1 1 0 [9,] 2 2 1 0 [10,] 1 3 1 0 [11,] 0 4 1 0 [12,] 3 0 2 0 [13,] 2 1 2 0 [14,] 1 2 2 0 [15,] 0 3 2 0 [16,] 2 0 3 2 [17,] 1 1 3 0 [18,] 0 2 3 0 [19,] 1 0 4 0 [20,] 0 1 4 1 [21,] 0 0 5 0 Thus the 'd' column counts the number of times that each row occurs in variable 'observation'. _So desired[5,4]=2 because the observation corresponding to desired[5,1:3] (viz c(1,4,0)) occurred twice. _And desired[1,4]=0 because the observation corresponding to desired[1,1:3] (viz c(5,0,0)) did not occur once (it was not observed). In my application I have dim(S) ~= c(5,4e6). I've tried merge(), stack(), _reshape(), but the best I can do is the (derisory): require(partitions) obs - matrix(as.integer(c( _ _ _ _ _ _ _ 1, 4, 0, _ _ _ _ _ _ _ 1, 4, 0, _ _ _ _ _ _ _ 2, 0, 3, _ _ _ _ _ _ _ 4, 1, 0, _ _ _ _ _ _ _ 0, 5, 0, _ _ _ _ _ _ _ 0, 1, 4, _ _ _ _ _ _ _ 2, 0, 3 _ _ _ _ _ _ _ )),ncol=3,byrow=TRUE) S - t(compositions(5,3)) d - rep(0,nrow(S)) for(i in seq_len(nrow(obs))){ _for(j in seq_len(nrow(S))){ _ if(all(obs[i,,drop=TRUE] == S[j,,drop=TRUE])){ _ _ d[j] - d[j]+1 _ } _} } S - cbind(S,d) Anyone got anything better before I try C? -- Robin K. S. Hankin Uncertainty Analyst University of Cambridge 19 Silver Street Cambridge CB3 9EP 01223-764877 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 17-Oct-09 Time: 17:00:48 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 do I access with the name of a (passed) function
How would I do something like this: f - function(x, g) { s - as.character(g) # THIS DOES NOT WORK sprintf(The %s of x is %.0f\n, s, g(x)) } f(c(2,3,4), median) f(c(2,3,4), mean) and get the results The median of x is 3 The mean of x is 3 -- Ajay Shah http://www.mayin.org/ajayshah ajays...@mayin.org http://ajayshahblog.blogspot.com *(:-? - wizard who doesn't know the answer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] lmer function and Inverse mills ratio
Dear R users I have two questions, I have been on this problem for last 3 months, please help First question: *How can I use the lmer function for a three level probit ( ie please help me with the command syntax)?* The second question is, *how can I then subsequently calculate the Inverse Mills ratio after the above probit is calculated using lmer?* Is there any other way (if lmer does not do this) to get IMR of a 3 level probit Kindly help Thanks Saurav -- Dr.Saurav Pathak PhD, Univ.of.Florida Mechanical Engineering Doctoral Student Innovation and Entrepreneurship Imperial College Business School s.patha...@imperial.ac.uk 0044-7795321121 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Mixing LaTeX and R Code in Loops and Functions in Sweave
I have a question about mixing LaTeX and R code in loops and functions in Sweave. Here's my problem: I want to do something like this: = # some R code for a loop for(i in 1:10) { @ My LaTex code here would describe what I do in the loop. For instance, in this loop print out the numbers one through 10. Maybe I could even have Multiple sections in between the loop. For instance, \section{Part of 1 of the Loop} = cat(paste(Number,i)) } @ The problem is that Sweave evaluates the first chunk of code and throws an error because I haven't closed the loop. A similar problem happens when I want to have LaTeX code intermixed with a function. So how do I mix LaTex code with R chunks that alone may throw errors, but together with another chunk does not. Thanks in advance for your help! I am new to R and this is my first post on this list. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] doing a Tukey HSD post-hoc
Hi all I have a large spreadsheet (Excel) file with many rows and columns in it. I have four treatment groups and using the lm function shows that there is a significant omnibus R with respect to several of the variables. I want to do a Tukey HSD in R. How can I do this? Leslie J. Seltzer, Ph.D. Postdoctoral Fellow, CERL Department of Psychology and Waisman Center 385 Waisman (Assay Lab) University of Wisconsin-Madison 1500 Highland Ave Madison, WI 53705 WORK: (608) 890-2525 CELL: (608) 886-6067 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] More polyfit problems
Hi Everyone, I'm continuing to run into trouble with polyfit. I'm using the fitting function of the form; fit - lm(y ~ poly(x,degree,raw=TRUE)) and I have found that in some cases a polynomial of certain degree can't be fit, the coefficient won't be calculated, because of a singularity. If I use orthogonal polynomials I can fit a polynomial of any degree, but I don't get the proper coefficients. I'm having trouble solving this partly because I likely don't understand enough about polynomial fitting - and for that I have to apologize since I know this isn't supposed to be a forum for asking questions about mathematical process and rather for questions about the functionality of R. Nevertheless, can anyone provide guidance on this point? Is there a way to use orthogonal polynomials (the part about the fitting process that I don't quite understand) and still find the polynomial coefficients? Alternatively, what does one do about singularities using raw polynomials? It seems odd to me that the orthogonal polynomials can be used to fit the data, even visually once plotted, predicted values that are accurate can be derived from the function using predict(), but the coefficients are unknown. Any help is appreciated, Chris output below: --- archit[,1] [1] 1.8 1.3 2.0 2.1 1.9 1.9 1.3 1.9 2.8 x [1] 8752 8610 8554 8496 8482 8462 8438 8418 8384 archi_rooms - lm(archit[,1] ~ poly(x,4)) summary(archi_rooms) Call: lm(formula = archit[, 1] ~ poly(x, 4)) Residuals: 1 2 3 4 5 6 7 8 -0.001790 0.042008 -0.112756 0.083040 0.005183 0.175733 -0.330450 0.137128 9 0.001905 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 1.90.07077 26.691 1.17e-05 *** poly(x, 4)1 -0.475200.21230 -2.238 0.0888 . poly(x, 4)2 0.501160.21230 2.361 0.0776 . poly(x, 4)3 -0.208300.21230 -0.981 0.3821 poly(x, 4)4 0.942460.21230 4.439 0.0113 * --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 0.2123 on 4 degrees of freedom Multiple R-squared: 0.8865,Adjusted R-squared: 0.7731 F-statistic: 7.813 on 4 and 4 DF, p-value: 0.03570 archi_rooms - lm(archit[,1] ~ poly(x,4,raw=TRUE)) summary(archi_rooms) Call: lm(formula = archit[, 1] ~ poly(x, 4, raw = TRUE)) Residuals: 12345678 0.04665 -0.39399 0.34009 0.37112 0.13015 0.05111 -0.67957 -0.22202 9 0.35647 Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(|t|) (Intercept) 4.205e+04 9.107e+04 0.4620.664 poly(x, 4, raw = TRUE)1 -1.461e+01 3.191e+01 -0.4580.666 poly(x, 4, raw = TRUE)2 1.693e-03 3.726e-03 0.4540.669 poly(x, 4, raw = TRUE)3 -6.536e-08 1.450e-07 -0.4510.671 poly(x, 4, raw = TRUE)4 NA NA NA NA Residual standard error: 0.4623 on 5 degrees of freedom Multiple R-squared: 0.3275,Adjusted R-squared: -0.076 F-statistic: 0.8116 on 3 and 5 DF, p-value: 0.5397 _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] looking for reference that covers convergence in distribution
I am looking for a good probability book that describes convergence in distribution. I have looked through Introduction to Probability by Charles M. Grinstead, J. Laurie Snell, but I don't find any formal description on convergence in distribution. Could somebody recommend a good book that cover this topic? Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I access with the name of a (passed) function
Try this: show.name - function(x) deparse(substitute(x)) show.name(pi) [1] pi On Sat, Oct 17, 2009 at 7:26 AM, Ajay Shah ajays...@mayin.org wrote: How would I do something like this: f - function(x, g) { s - as.character(g) # THIS DOES NOT WORK sprintf(The %s of x is %.0f\n, s, g(x)) } f(c(2,3,4), median) f(c(2,3,4), mean) and get the results The median of x is 3 The mean of x is 3 -- Ajay Shah http://www.mayin.org/ajayshah ajays...@mayin.org http://ajayshahblog.blogspot.com *(:-? - wizard who doesn't know the answer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Mixing LaTeX and R Code in Loops and Functions in Sweave
Try this: results=latex,echo=false= for(i in 1:10) { cat(...latex code...) } @ or check out the brew package. On Fri, Oct 16, 2009 at 3:25 PM, Jacob R. Marcus jmar...@u.washington.edu wrote: I have a question about mixing LaTeX and R code in loops and functions in Sweave. Here's my problem: I want to do something like this: = # some R code for a loop for(i in 1:10) { @ My LaTex code here would describe what I do in the loop. For instance, in this loop print out the numbers one through 10. Maybe I could even have Multiple sections in between the loop. For instance, \section{Part of 1 of the Loop} = cat(paste(Number,i)) } @ The problem is that Sweave evaluates the first chunk of code and throws an error because I haven't closed the loop. A similar problem happens when I want to have LaTeX code intermixed with a function. So how do I mix LaTex code with R chunks that alone may throw errors, but together with another chunk does not. Thanks in advance for your help! I am new to R and this is my first post on this list. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Let's stay in touch on LinkedIn
LinkedIn John Cardinale requested to add you as a connection on LinkedIn: -- Arnaud, I'd like to add you to my professional network on LinkedIn. - John Accept invitation from John Cardinale http://www.linkedin.com/e/qlt6CtWzi7sEoE_As_C0_wMfEZD2c-gGLFL6LO/blk/I1513114462_2/pmpxnSRJrSdvj4R5fnhv9ClRsDgZp6lQs6lzoQ5AomZIpn8_cBYOdzgQcj4PcjkNiiZnhl4RbkpGcOYVcjsUdz4Pc3wLrCBxbOYWrSlI/EML_comm_afe/ View invitation from John Cardinale http://www.linkedin.com/e/qlt6CtWzi7sEoE_As_C0_wMfEZD2c-gGLFL6LO/blk/I1513114462_2/39vczoQd34NcP4RckALqnpPbOYWrSlI/svi/ -- DID YOU KNOW that LinkedIn can find the answers to your most difficult questions? Post those vexing questions on LinkedIn Answers to tap into the knowledge of the world's foremost business experts: http://www.linkedin.com/e/ask/inv-23/ -- (c) 2009, LinkedIn Corporation [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R292 on AIX53 using gcc
Hello -- I am unable to build R 2.9.2 on IBM PowerPC AIX5.3. I would appreciate any help in this matter. ===details== Machine: IBM PowerPC_POWER5 / 4 proc, 1499 MHz 64-bit / AIX 5.3.0.0 Building R 2.9.2 using gcc/g++/gfortran 4.2.4 Config.site changes are: OBJECT_MODE=64 CONFIG_SHELL=/usr/bin/bash LIBICONV=/opt/freeware/lib AR=ar -X64 CC=gcc -maix64 F77=gfortran -maix64 LDFLAGS=-L/opt/freeware/lib64 -L/opt/freeware/64/lib -L/opt/freeware/lib -L/usr/local/lib CXX=g++ -maix64 FC=gfortran -maix64 R_BROWSER=/opt/freeware/bin/firefox MAKE=/opt/freeware/bin/make Command for configure: ./configure --enable-R-shlib Looks like I have to set OBJECT_MODE explicitly on the command line. So, I enter: set OBJECT_MODE=64. It does not seem to help that I have it in config.site. make stops with the following error: gcc -maix64 -std=gnu99 -Wl,-brtl -Wl,-bexpall -Wl,-bpT:0x1 -Wl,-bpD:0x11000 -lc -L/opt/freeware/lib64 -L/opt/freeware/64/lib -L/opt/freeware/lib -L/usr/local/lib -o R.bin Rmain.o -L../../lib -lR ld: 0711-224 WARNING: Duplicate symbol: .memcpy ...duplicate symbol warning for: memcpy,bcopy,memset,fres ld: 0711-317 ERROR: Undefined symbol: R_running_as_main_program collect2: ld returned 8 exit status make: The error code from the last command is 1. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] looking for reference that covers convergence in distribution
Peng Yu wrote: I am looking for a good probability book that describes convergence in distribution. I have looked through Introduction to Probability by Charles M. Grinstead, J. Laurie Snell, but I don't find any formal description on convergence in distribution. Could somebody recommend a good book that cover this topic? Thank you! This mailing list is for R help, not general statistics help. May I respectfully request that you take your questions to a statistics help list instead? From the posting guide: Questions about statistics: The R mailing lists are primarily intended for questions and discussion about the R software. However, questions about statistical methodology are sometimes posted. If the question is well-asked and of interest to someone on the list, it may elicit an informative up-to-date answer. See also the Usenet groups sci.stat.consult (applied statistics and consulting) and sci.stat.math (mathematical stat and probability). -- View this message in context: http://www.nabble.com/looking-for-reference-that-covers-convergence-in-distribution-tp25940017p25941224.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] re peating values in levels()
Donald Braman wrote: Can someone help me understand this results? levels(as.factor(miset1$facts_convict)) [1] 1 1 2 3 4 5 6 converting to numeric and back doesn't seem to help: levels(as.factor(as.numeric(miset1$facts_convict))) [1] 1 1 2 3 4 5 6 It's messing up my ologits. Any way to correct this? If we can't reproduce this, we can't help. Would suggest that you dig back through the history of how the offending variable/data frame was created to see how it could have ended up that way (which is definitely pathological), and try to provide us with a reproducible example. Results of sessionInfo() ? -- View this message in context: http://www.nabble.com/repeating-values-in-levels%28%29-tp25938993p25941257.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] doing a Tukey HSD post-hoc
?TukeyHSD --- On Fri, 10/16/09, Leslie J Seltzer lselt...@wisc.edu wrote: From: Leslie J Seltzer lselt...@wisc.edu Subject: [R] doing a Tukey HSD post-hoc To: r-help@r-project.org Received: Friday, October 16, 2009, 5:38 PM Hi all I have a large spreadsheet (Excel) file with many rows and columns in it. I have four treatment groups and using the lm function shows that there is a significant omnibus R with respect to several of the variables. I want to do a Tukey HSD in R. How can I do this? Leslie J. Seltzer, Ph.D. Postdoctoral Fellow, CERL Department of Psychology and Waisman Center 385 Waisman (Assay Lab) University of Wisconsin-Madison 1500 Highland Ave Madison, WI 53705 WORK: (608) 890-2525 CELL: (608) 886-6067 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [[elided Yahoo spam]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] looking for reference that covers convergence in distribution
Ben Bolker wrote: Peng Yu wrote: I am looking for a good probability book that describes convergence in distribution. I have looked through Introduction to Probability by Charles M. Grinstead, J. Laurie Snell, but I don't find any formal description on convergence in distribution. Could somebody recommend a good book that cover this topic? Thank you! This mailing list is for R help, not general statistics help. May I respectfully request that you take your questions to a statistics help list instead? You may want to check out the R package ConvergenceConcepts, though. Supporting article due to appear in the next issue of the R Journal. -- 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 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Easy way to `iris[,-Petal.Length]' subsetting?
Dear all What is the easy way to drop a variable by using its name (and not its number)? Example: data(iris) head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa head(iris[,-3]) Sepal.Length Sepal.Width Petal.Width Species 1 5.1 3.5 0.2 setosa 2 4.9 3.0 0.2 setosa 3 4.7 3.2 0.2 setosa 4 4.6 3.1 0.2 setosa 5 5.0 3.6 0.2 setosa 6 5.4 3.9 0.4 setosa head(iris[,-which(names(iris)==Petal.Length)]) Sepal.Length Sepal.Width Petal.Width Species 1 5.1 3.5 0.2 setosa 2 4.9 3.0 0.2 setosa 3 4.7 3.2 0.2 setosa 4 4.6 3.1 0.2 setosa 5 5.0 3.6 0.2 setosa 6 5.4 3.9 0.4 setosa head(iris[,-Petal.Length]) Error in -Petal.Length : invalid argument to unary operator Is there something more straight-forward than `-which(names(iris)==Petal.Length)', to drop a variable using a string? Thank you Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] looking for reference that covers convergence in distribution
On Sat, Oct 17, 2009 at 3:28 PM, Peter Dalgaard p.dalga...@biostat.ku.dk wrote: Ben Bolker wrote: Peng Yu wrote: I am looking for a good probability book that describes convergence in distribution. I have looked through Introduction to Probability by Charles M. Grinstead, J. Laurie Snell, but I don't find any formal description on convergence in distribution. Could somebody recommend a good book that cover this topic? Thank you! This mailing list is for R help, not general statistics help. May I respectfully request that you take your questions to a statistics help list instead? You may want to check out the R package ConvergenceConcepts, though. Supporting article due to appear in the next issue of the R Journal. I have checked sci.stat.math before my original post. But it is seriously flooded with junk posts. Before this problem is fixed, it is probably not very helpful to post anything there. I know my question is rudimentary. There are so many probability and statistics textbook online, and it is difficult for me to figure out which one fits my need. If you happen to know which book is the best for me to learn convergence in distribution, please let me know. Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] optimization problem with constraints...
Dear R users, I need some advises on how to use R to optimize a nonlinear function with the following constraints. f(x1,x2,x3,x4,x5,x6) s.t 0 x1 1 0 x2 1 0 x1+x2 1 -inf x3 inf -inf x4 inf 0 x5 inf 0 x6 inf Is there any built-in function or something for these constraint?? Any suggestion will be greatly appreciated. Regards, Kathryn Lord -- View this message in context: http://www.nabble.com/optimization-problem-with-constraints...-tp25941686p25941686.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Putting names on a ggplot
Putting names on a ggplot Can anyone suggest what I am doing wrong here. I am plotting daily temperatures at Ottawa Ontario for 2008 broken down by months, I seperate them by lines and want to put the names of the months at the top of the chart ( with in the graphing area) Everything is working as I want until I try to add the names of the months. I did something similar a few days ago and I cannot see were I am doing anything very different. Also I tried to use year$month -- an interger variable -- to get the colour breakdown with no success and finally added the months variable ( character) to get it. Is this normal for ggplot? Thanks. CODE-- Data is below code == year[,5] - 1:length(year[,1]) names(year) - c('month','days','year','temps', duration) month.days - as.vector(table(year[,1])) months - rep(month.name[1:12], month.days) month.counts - cumsum(as.vector( table(year[,1]))) namposts - c(1, month.counts[1:11]) mlabs - month.name[1:12] temprange - range(year$temps, na.rm=TRUE) p - ggplot(year, aes(duration, temps, colour=months)) + geom_line() + opts(legend.position = none, title=Yearly temperatures, axis.text.x = theme_blank(), axis.ticks = theme_blank()) p p - p + geom_vline(xintercept=month.counts) + ylab(Temperature (C)) + xlab(Daily Temperatures) p # this is where I see the problem. p - p + geom_text(aes(x = namposts + 2.5, y = temprange[2], label = mlabs), data = year, size = 2.5, colour='black', hjust = 0, vjust = 0) p = DATA = year - structure(list(month = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L), days = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
Re: [R] Easy way to `iris[,-Petal.Length]' subsetting?
Try this: subset(iris, select = - Petal.Length) On Sat, Oct 17, 2009 at 4:49 PM, Liviu Andronic landronim...@gmail.com wrote: Dear all What is the easy way to drop a variable by using its name (and not its number)? Example: data(iris) head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa head(iris[,-3]) Sepal.Length Sepal.Width Petal.Width Species 1 5.1 3.5 0.2 setosa 2 4.9 3.0 0.2 setosa 3 4.7 3.2 0.2 setosa 4 4.6 3.1 0.2 setosa 5 5.0 3.6 0.2 setosa 6 5.4 3.9 0.4 setosa head(iris[,-which(names(iris)==Petal.Length)]) Sepal.Length Sepal.Width Petal.Width Species 1 5.1 3.5 0.2 setosa 2 4.9 3.0 0.2 setosa 3 4.7 3.2 0.2 setosa 4 4.6 3.1 0.2 setosa 5 5.0 3.6 0.2 setosa 6 5.4 3.9 0.4 setosa head(iris[,-Petal.Length]) Error in -Petal.Length : invalid argument to unary operator Is there something more straight-forward than `-which(names(iris)==Petal.Length)', to drop a variable using a string? Thank you Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Putting names on a ggplot
hi, On Sat, Oct 17, 2009 at 02:04:43PM -0700, John Kane wrote: Putting names on a ggplot p - p + geom_text(aes(x = namposts + 2.5, y = temprange[2], label = mlabs), data = year, size = 2.5, colour='black', hjust = 0, vjust = 0) you shouldn't use aes in this case since nampost, temprange, ... are not part of the dataframe year. It should also work with geom_text i guess, but I prefere annotate for thinks like that: p + annotate(text,x=namposts+2.5, y = temprange[2], label= mlabs,size=2.5,colour='black', hjust = 0, vjust = 0) regards, stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] repeating values in levels()
Donald Braman wrote: Can someone help me understand this results? levels(as.factor(miset1$facts_convict)) [1] 1 1 2 3 4 5 6 Don't know how you got your data that way, but I wonder if you've done str() on your data after whatever procedure you used to get to this stage. Here's one way to get this pathological state: set.seed(2) x - sample(5, 15, rep=TRUE) y - factor(x, levels=c(1, 1:5)) ## repeating level 1 levels(y) [1] 1 1 2 3 4 5 converting to numeric and back doesn't seem to help: levels(as.factor(as.numeric(miset1$facts_convict))) [1] 1 1 2 3 4 5 6 I suspect that miset1$facts_convict is already a factor [str() would tell you] and that the following comment from ?factor applies: In particular, as.numeric applied to a factor is meaningless ... If my guess is correct, you should be able to fix things with newy - factor(y) levels(newy) [1] 1 2 3 4 5 -Peter Ehlers It's messing up my ologits. Any way to correct this? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] predict factanal scores
Hello, how does one use factanal to produce factor scores for a new data set? I have a factor solution estimated from historical data. I have a 'new' data set I just like to create factor scores using the prior estimated factor model. I see a reference to a package tsfa, for time series factor analysis that has a predict function, but like to use the factanal function. Is there an equivalent to predict for the factanal function, i can say newdata= and extract the scores? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to cluster data for use with lmer
Dear R users My data set is e names(e) [1] yearctry discent age gender gemeduc gemhhinc ref_groupfearfail_ref knowent_ref nbgoodc_ref [11] nbstatus_ref estbbuso_ref lngdplngdpsq es_gdppcppp sq_gdppcppp estbbo_m es_gdpchg hear I have variables representing two levels, namely individual level and country level. My data is thus a 2 level data. the country level variables (level-2) are lngdplngdpsq es_gdppcppp sq_gdppcppp estbbo_m es_gdpchg grouped by yearctry and the rest of the variables are individual level (level-1). the number of Individual observations are 655078 and number of yearctry ie groups =239, however when I model a probit to see the influence of 4 individual level var (ie age gender gemeduc and gemhhinc) and one country level var (es_gdppcppp) using prb1-lmer(discent~age+gender+gemeduc+gemhhinc+es_gdppcppp+(1 | yearctry),family=binomial(link=probit),data=e) I get Generalized linear mixed model fit by the Laplace approximation Formula: discent ~ age + gender + gemeduc + gemhhinc + es_gdppcppp + (1 | yearctry) Data: e AICBIC logLik deviance 194043 194122 -97014 194029 Random effects: Groups NameVariance Std.Dev. yearctry (Intercept) 4.0708e-06 0.0020176 *Number of obs: 655078, groups: yearctry, 1* Fixed effects: Estimate Std. Error z value Pr(|z|) (Intercept) -7.578e-01 1.839e-02 -41.20 2e-16 *** age -2.441e-03 2.990e-04 -8.16 3.30e-16 *** gender -2.886e-01 7.710e-03 -37.43 2e-16 *** gemeduc 9.244e-05 6.930e-06 13.34 2e-16 *** gemhhinc-8.938e-07 1.359e-07 -6.58 4.75e-11 *** es_gdppcppp -2.459e-05 2.691e-07 -91.40 2e-16 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Correlation of Fixed Effects: (Intr) agegender gemedc gmhhnc age -0.580 gender -0.563 -0.138 gemeduc -0.373 0.166 0.011 gemhhinc-0.009 -0.132 -0.024 -0.201 es_gdppcppp -0.490 0.071 0.314 -0.297 0.256 *The model did not recognise group to be yearctry and shows 1 instead of 239,* can somebody help me as to how to make my model recognise es_gdppcppp as a country level variable grouped by yearctry (such that yeractry no of obs should be 239) Please help Thanks in advance Saurav -- Dr.Saurav Pathak PhD, Univ.of.Florida Mechanical Engineering Doctoral Student Innovation and Entrepreneurship Imperial College Business School s.patha...@imperial.ac.uk 0044-7795321121 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Putting names on a ggplot
hi, On Sat, Oct 17, 2009 at 02:04:43PM -0700, John Kane wrote: Putting names on a ggplot p - p + geom_text(aes(x = namposts + 2.5, y = temprange[2], label = mlabs), data = year, size = 2.5, colour='black', hjust = 0, vjust = 0) you shouldn't use aes in this case since nampost, temprange, ... are not part of the dataframe year. It should also work with geom_text i guess, but I prefere annotate for thinks like that: p + annotate(text,x=namposts+2.5, y = temprange[2], label = mlabs,size=2.5, colour='black', hjust = 0, vjust = 0) regards, stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Mixing LaTeX and R Code in Loops and Functions in Sweave
...or the R.rsp package. -H On Sat, Oct 17, 2009 at 10:37 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try this: results=latex,echo=false= for(i in 1:10) { cat(...latex code...) } @ or check out the brew package. On Fri, Oct 16, 2009 at 3:25 PM, Jacob R. Marcus jmar...@u.washington.edu wrote: I have a question about mixing LaTeX and R code in loops and functions in Sweave. Here's my problem: I want to do something like this: = # some R code for a loop for(i in 1:10) { @ My LaTex code here would describe what I do in the loop. For instance, in this loop print out the numbers one through 10. Maybe I could even have Multiple sections in between the loop. For instance, \section{Part of 1 of the Loop} = cat(paste(Number,i)) } @ The problem is that Sweave evaluates the first chunk of code and throws an error because I haven't closed the loop. A similar problem happens when I want to have LaTeX code intermixed with a function. So how do I mix LaTex code with R chunks that alone may throw errors, but together with another chunk does not. Thanks in advance for your help! I am new to R and this is my first post on this list. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RODBC sqlSave does not append the records to a DB2 table
Elaine: Try this. It works for me using my own database. Perhaps you don't have admin rights. Good luck library(RODBC) myDB - odbcConnectAccess(DB2.mdb,uid=admin,pwd=) sqlSave(myDB,se2,rownames=FALSE,append=TRUE) close(myDB) Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA --- On Fri, 10/16/09, Elaine Jones jon...@us.ibm.com wrote: From: Elaine Jones jon...@us.ibm.com Subject: [R] RODBC sqlSave does not append the records to a DB2 table To: r-help@r-project.org Date: Friday, October 16, 2009, 4:33 PM I am running R version 2.9.2 on Windows XP OS with RODBC version Version: 1.3-0. Has anyone out there in the R user community successfully appended records to a DB2 table on a remote database using the sqlSave function in the RODBC package? (or by any other means from R?) I posed a similar question a few months ago and unfortunately, did not receive a response. I was hoping recent upgrades to our DB2 on the database, and I installed the current version RODBC. Unfortunately, it did not bring any joy. I asked the database adminstrator try it, and she had a similar experience. No error message is returned, but the record is not inserted to the table. For testing purposes, I have a very simple one-row, three-column data.frame (se2) I want to insert into a DB2 table. sqlSave(channel, se2, tablename = STORAGE.TEST_APPEND2, append = TRUE, + rownames = FALSE, colnames = FALSE, + verbose = TRUE, + safer = TRUE, addPK = FALSE, + fast = FALSE, test = FALSE, nastring = NULL) Query: INSERT INTO STORAGE.TEST_APPEND2 ( MACRONAME, MACROUSER, MACRO_RT ) VALUES ( 's_ej_mach_config_vz', 'jones2', 5 ) I don't get any error message, but when I check the table row count, the record has not been added to the table. Any suggestions for how to resolve are appreciated! Sincerely, Elaine McGovern Jones ISC Tape and DASD Storage Products Characterization and Failure Analysis Engineering Phone: 408 705-9588 Internal tieline: 587-9588 jon...@us.ibm.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] function to convert lm model to LaTeX equation
Dear list, I've tried several times to wrap my head around the Design library, without much success. It does some really nice things, but I'm often uncomfortable because I don't understand exactly what it's doing. Anyway, one thing I really like is the latex.ols() function, which converts an R linear model formula to a LaTeX equation. So, I started writing a latex.lm() function (not actually using classes at this point, I just named it that for consistency). This turned out to be easy enough for simple cases (see code below), but now I'm wondering a) if anyone knows of existing functions that do this (again, for lm() models, I know I'm reinventing the wheel in as far as the Design library goes), or if not, b) if anyone has suggestions for improving the function below. Thanks, Ista ### Function to create LaTeX formula from lm() model. Needs amsmath package in LaTeX. ### latex.lm - function(object, file=, math.env=c($,$), estimates=none, abbreviate = TRUE, abbrev.length=8, digits=3) { # Get and format IV names co - c(Int, names(object$coefficients)[-1]) co.n - gsub(p.*), , co) if(abbreviate == TRUE) { co.n - abbreviate(gsub(p.*), , co), minlength=abbrev.length) } # Get and format DV m.y - strsplit((as.character(object$call[2])), ~ )[[1]][1] # Write coefficent labels b.x - paste(\\beta_{, co.n ,}, sep=) # Write error term e - \\epsilon_i # Format coefficint x variable terms m.x - sub(}Int,}, paste(b.x, co.n, + , sep=, collapse=)) # If inline estimates convert coefficient labels to values if(estimates == inline) { m.x - sub(Int, , paste(round(object$coefficients,digits=digits), co.n, + , sep=, collapse=)) m.x - gsub(\\+ \\-, -, m.x) } # Format regression equation eqn - gsub(:, \\times , paste(math.env[1], m.y, = , m.x, e, sep=)) # Write the opening math mode tag and the model cat(eqn, file=file) # If separae estimates format estimates and write them below the model if(estimates == separate) { est - gsub(:, \\times , paste(b.x, = , round(object$coefficients, digits=digits), , , sep=, collapse=)) cat(, \n \\text{where }, substr(est, 1, (nchar(est)-2)), file=file) } # Write the closing math mode tag cat(math.env[2], \n, file=file) } # END latex.lm Xvar1 - rnorm(20) Xvar2 - rnorm(20) Xvar3 - factor(rep(c(A,B),10)) Y.var - rnorm(20) D - data.frame(Xvar1, Xvar2, Xvar3, Y.var) x1 - lm(Y.var ~ pol(Xvar1, 3) + Xvar2*Xvar3, data=D) latex.lm(x1) -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RODBC sqlSave does not append the records to a DB2 table
Hello! Before you try from R. Can you tell us what happens when you use another DB2 client when you try with those credentials? One thing to note: If you are trying to access DB2 from ODBC on Linux on DB2 versions before 9.4 there are some particular issues and better check this http://holmwood.id.au/~lindsay//2007/10/26/setting-up-unixodbc-with-a-remote-db2/ Caveman On Sat, Oct 17, 2009 at 1:33 AM, Elaine Jones jon...@us.ibm.com wrote: I am running R version 2.9.2 on Windows XP OS with RODBC version Version: 1.3-0. Has anyone out there in the R user community successfully appended records to a DB2 table on a remote database using the sqlSave function in the RODBC package? (or by any other means from R?) I posed a similar question a few months ago and unfortunately, did not receive a response. I was hoping recent upgrades to our DB2 on the database, and I installed the current version RODBC. Unfortunately, it did not bring any joy. I asked the database adminstrator try it, and she had a similar experience. No error message is returned, but the record is not inserted to the table. For testing purposes, I have a very simple one-row, three-column data.frame (se2) I want to insert into a DB2 table. sqlSave(channel, se2, tablename = STORAGE.TEST_APPEND2, append = TRUE, + rownames = FALSE, colnames = FALSE, + verbose = TRUE, + safer = TRUE, addPK = FALSE, + fast = FALSE, test = FALSE, nastring = NULL) Query: INSERT INTO STORAGE.TEST_APPEND2 ( MACRONAME, MACROUSER, MACRO_RT ) VALUES ( 's_ej_mach_config_vz', 'jones2', 5 ) I don't get any error message, but when I check the table row count, the record has not been added to the table. Any suggestions for how to resolve are appreciated! Sincerely, Elaine McGovern Jones ISC Tape and DASD Storage Products Characterization and Failure Analysis Engineering Phone: 408 705-9588 Internal tieline: 587-9588 jon...@us.ibm.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.