Re: [R] kalman filter estimation
On Thu, 15 Nov 2007, [EMAIL PROTECTED] wrote: Hi, Following convention below: y(t) = Ax(t)+Bu(t)+eps(t) # observation eq x(t) = Cx(t-1)+Du(t)+eta(t) # state eq I modified the following routine (which I copied from: http://www.stat.pitt.edu/stoffer/tsa2/Rcode/Kall.R) to accommodate u(t), an exogenous input to the system. for (i in 2:N){ xp[[i]]=C%*%xf[[i-1]] Pp[[i]]=C%*%Pf[[i-1]]%*%t(C)+Q siginv=A[[i]]%*%Pp[[i]]%*%t(A[[i]])+R sig[[i]]=(t(siginv)+siginv)/2 # make sure sig is symmetric siginv=solve(sig[[i]]) # now siginv is sig[[i]]^{-1} K=Pp[[i]]%*%t(A[[i]])%*%siginv innov[[i]]=as.matrix(yobs[i,])-A[[i]]%*%xp[[i]] xf[[i]]=xp[[i]]+K%*%innov[[i]] Pf[[i]]=Pp[[i]]-K%*%A[[i]]%*%Pp[[i]] like= like + log(det(sig[[i]])) + t(innov[[i]])%*%siginv%*%innov[[i]] } like=0.5*like list(xp=xp,Pp=Pp,xf=xf,Pf=Pf,like=like,innov=innov,sig=sig,Kn=K) } I tried to fit my problem and observe that I got positive log likelihood mainly because the log of determinant of my variance matrix is largely negative. That's not good because they should be positive. Have anyone experience this kind of instability? Why are you expecting that? The magnitude of the log-likelihood depends on the scale of your data, and hence so does the sign of its log. Also, I realize that I have about 800 sample points. The above routine when being plugged to optim becomes very slow. Could anyone share a faster way to compute kalman filter? Try help.search(kalman, agrep=FALSE) kalsmo.car(cts) Compute Components with the Kalman Smoother kalsmo.comp(cts)Estimate Componenents with the Kalman Smoother nbkal(repeated) Negative Binomial Models with Kalman Update extended(sspir) Iterated Extended Kalman Smoothing kfilter(sspir) Kalman filter for Gaussian state space model kfs(sspir) (Iterated extended) Kalman smoother smoother(sspir) Kalman smoother for Gaussian state space model tsmooth(timsac) Kalman Filter KalmanLike(stats) Kalman Filtering And my last problem is, optim with my defined feasible space does not converge. I have about 20 variables that I need to identify using MLE method. Is there any other way that I can try out? I tried most of the methods available in optim already. They do not converge at all.. Most likely because of errors in your code. Optim solves quite large Kalman filter problems for arima(). -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] histogram plot as step function
Hi I want to plot a histogram (not cumulative!) as a step-function. Any idea how achieve this? 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] what is the right way to obtain frequencies of vector values?
Vlad Skvortsov vss at 73rus.com writes: Let's say I have vector x with positive integer values ranging from 1 to N. I need to obtain another vector y of size N where y[i] contains the number of times value i occurs in x. It is in a sense similar to hist() (with appropriate number of breaks) or table() with numeric factors. Currenlty I use a custom function for that, but thought maybe there is a more direct way in R. table works with numerics: table(c(1,1,3,4,12,123,12,2,21,2,2,2)) 1 2 3 4 12 21 123 2 4 1 1 2 1 1 Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error while calculating AOV
apsawant apsawant at yahoo.com writes: I am trying to run a simple example script to calculate AOV. Below is the script file (aov.R) I am trying to execute: aov.R -- aov(rt - shape * color + Error(subj/(shape * color)), data=Hays.df) summary(aov(rt - shape * color + Error(subj/(shape * color)), data=Hays.df)) The - in the formula is wrong, it should be ~ Dieter #--- data1-c(49,47,46,47,48,47,41,46,43,47,46,45,48,46,47,45,49,44,44,45,42,45,45,40 ,49,46,47,45,49,45,41,43,44,46,45,40,45,43,44,45,48,46,40,45,40,45,47,40) Hays.df-data.frame(rt = data1, subj=factor(rep(paste(subj, 1:12, sep=), 4)), shape=factor(rep(rep(c(shape1,shape2), c(12, 12)), 2)), color=factor(rep(c(color1,color2), c(24, 24 aov(rt ~ shape * color + Error(subj/(shape * color)), data=Hays.df) summary(aov(rt ~ shape * color + Error(subj/(shape * color)), data=Hays.df)) __ 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] negative binomial lmer
If lmer() does not do it, you can try: http://otter-rsch.com/admbre/examples/glmmadmb/glmmADMB.html It handles negative binomial responce (but you may have to remove data entries involving NA manually). Regards, hans Hi I am running an lmer which works fine with family=poisson mixed.model -lmer(nobees~spray+dist+flwabund+flwdiv+round+(1|field),family=poisson,method=ML, na.action=na.omit) But it is overdispersed. I tried using family=quasipoisson but get no P values. This didnt worry me too much as i think my data is closer to negative binomial but i cant find any examples of negative binomial lmer. I tried using the family=negative.binomial(theta=x,link=log) but got an error message from R saying the function famiily=negative.binomial wasnt recognised. Can anyone suggest how to go about setting up the lmer with negative binomial distribution? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] read complicated file
Dear R experts, I have been given data files in the following configuration and have been puzzling about how to read them in. First I will give a snippet of the beginning of file: Data File: W Para File: GABOR_0.gor v 10.6, Date : 29/10/2007 Time : 13:33 3.00 5.000 Noise SD(deg): 15.000 1 -5.321 -5.321 2 -5.321 -3.991 3 -5.321 -2.661 4 -5.321 -1.330 5 -5.321 0.000 6 -5.321 1.330 7 -5.321 2.661 8 -5.321 3.991 9 -5.321 5.321 10 -3.991 -5.321 11 -3.991 -3.991 12 -3.991 -2.661 13 -3.991 -1.330 14 -3.991 0.000 15 -3.991 1.330 16 -3.991 2.661 17 -3.991 3.991 18 -3.991 5.321 19 -2.661 -5.321 20 -2.661 -3.991 21 -2.661 -2.661 22 -2.661 -1.330 23 -2.661 0.000 24 -2.661 1.330 25 -2.661 2.661 26 -2.661 3.991 27 -2.661 5.321 28 -1.330 -5.321 29 -1.330 -3.991 30 -1.330 -2.661 31 -1.330 -1.330 32 -1.330 0.000 33 -1.330 1.330 34 -1.330 2.661 35 -1.330 3.991 36 -1.330 5.321 37 0.000 -5.321 38 0.000 -3.991 39 0.000 -2.661 40 0.000 -1.330 41 0.000 0.000 42 0.000 1.330 43 0.000 2.661 44 0.000 3.991 45 0.000 5.321 46 1.330 -5.321 47 1.330 -3.991 48 1.330 -2.661 49 1.330 -1.330 50 1.330 0.000 51 1.330 1.330 52 1.330 2.661 53 1.330 3.991 54 1.330 5.321 55 2.661 -5.321 56 2.661 -3.991 57 2.661 -2.661 58 2.661 -1.330 59 2.661 0.000 60 2.661 1.330 61 2.661 2.661 62 2.661 3.991 63 2.661 5.321 64 3.991 -5.321 65 3.991 -3.991 66 3.991 -2.661 67 3.991 -1.330 68 3.991 0.000 69 3.991 1.330 70 3.991 2.661 71 3.991 3.991 72 3.991 5.321 73 5.321 -5.321 74 5.321 -3.991 75 5.321 -2.661 76 5.321 -1.330 77 5.321 0.000 78 5.321 1.330 79 5.321 2.661 80 5.321 3.991 81 5.321 5.321 END 1 5.000 15.000 118 -101-84 56 72 157 -15877 21 -238 -171-257-34 78 -228-122328 144 23 -168 159 106 -60 330 -13933 -22 215 95 -89 -201199 364 -70 352 -25 -108-10023 105 -42 106 164 123 289 77 50 16 -13251 140 105 229 135 -17175 83 -165133 -131 -8 -132149 165 60 31 -305336 -16 73 -10 212 65 12 193 180 -82 137 7 -146 249 59 -180-73 -278-124-22 107 164 73 160 -136-37 119 -10 100 -4 0 182 152 35 256 70 148 -9 -4 0 49 128 -44 21 36 143 -114-59 -1107 -40 -80 -70 99 27 -27 184 293 257 -83 44 101 65 -68 -167158 94 -39 130 59 -34934 47 -108 70 141 55 138 -20 -83 81 -15 74 -107 140 -280107 -32583 125 -64 200 -122123 -280 22 2 5.000 15.000 93 313 312 -113230 160 -13 -42 145 -31 184 -287-92 5 48 -62 5 110 -58 215 73 -171-15 219 -20 94 -37 -13 -198175 -17912 -47 27 186 -18030 0 -25 -91 164 117 -155188 149 -28 24 5 20 -31 52 -78 45 -133-63 -77 75 -183130 -119 -47 -8 -40 64 209 166 48 -65 -244111 110 -106-248-21 -1732 -38 111 30 -174 257 59 -180-73 -278-124-22 107 164 73 160 -136-37 119 -10 100 -4 0 182 152 35 256 70 148 -9 -4 0 49 128 -44 21 36 143 -114-59 -1107 -40 -80 -70 99 27 -27 184 293 257 -83 44 101 65 -68 -167158 94 -39 130 59 -34934 47 -108 70 141 55 138 -20 -83 81 -15 74 -107 140 -280107 -32583 125 -64 200 -122123 -280 21 ... The first bit up to END can be skipped. That's the first 90 lines. Then I need to do something like this: while data still exist in the file { skip 3 lines scan 81 values into temp scan 82nd value, which is 11, 12, 21,
Re: [R] histogram plot as step function
On Thu, 15 Nov 2007, Hakim Tafer wrote: Hi I want to plot a histogram (not cumulative!) as a step-function. Any idea how achieve this? Thank you Well if I understand you correctly you can do this. x-rnorm(100) par(mfrow=c(2,1)) hist(x) histRes - hist(x,plot=FALSE) xvals - histRes$breaks yvals - histRes$counts length(xvals) length(yvals) xvals - c(xvals,xvals[length(xvals)]) yvals - c(0,yvals,0) plot(xvals,yvals,type=S) David Scott _ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: [EMAIL PROTECTED] Graduate Officer, Department of Statistics 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] convex optimization package for R, specifically semidefinite programming
Hi there, I do assume you are talking about the CVXOPT (and CVXMOD) Python package(s). Please note that CVXOPT only contains _interfaces_ to the solvers in MOSEK, because these are commercial products (as Roger Koenker already has mentioned). There appear to be some Python/Scipy-based solvers available in CVXOPT, but for larger applications one would still have to utilize the original CVX modules. CVX itself is a free Matlab software for disciplined convex optimization. As you can read on their Web page http://www.stanford.edu/~boyd/cvx/, future plans are to port it to other frameworks such as *R*, Octave, or Mathematica. Perhaps the R community could accelerate such an R port by contacting the developers and by offering support and provision (I can't, I'm no programmer, I am only modeling and trying to solve optimization problems). -- Hans Werner Galkowski, Jan jgalkows at akamai.com writes: Recently, a package for convex optimization was announced for Python, based upon the LP solver GLPK, the SDP solver in DSDP5, and the LP and QP solvers in MOSEK. I'm aware GLPK is available for R, but wondered if anyone had good packages for convex optimization along these lines for R. TIA. __ R-help at 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] Package to make stepwise model selection using F or Chisq test
Hi, I looking for a method that use F or Chisq test instead of AIC in a stepwise modelo selection. I try the grasp package using the grasp.step.anova, but It dont work. library(grasp) Carregando pacotes exigidos: gam Carregando pacotes exigidos: splines Carregando pacotes exigidos: mda Carregando pacotes exigidos: class data(anorexia,package=MASS) m1 - glm(Postwt ~ Prewt * Treat,data=anorexia) m1.grasp - grasp.step.anova(m1,scope=list(upper=~ Prewt * Treat,lower=~1),trace=1,direction=both) # # FUNCTION: grasp.step.anova # (by Splus, adapted by A. Lehmann from step.gam) # grasp.step.anova is a modified version of step.gam of Splus using ANOVA based on Chi or F tests instead # of AIC criteria # Erro em grasp.step.anova(m.pres, scope = list(upper = ~(ProfSer + NgalhoSer + : objeto OPTIONS não encontrado Looking for OPTIONS in the code I found that this need a P.limit in an OPTIONS object. I make it. OPTIONS - NULL OPTIONS$P.limit - 0.05 m.pres.step - grasp.step.anova(m.pres,scope=list(upper=~(ProfSer+NgalhoSer+CTOTAL+DensRamos+Htotal+CAP)^3,lower=~1),trace=1,direction=both) # # FUNCTION: grasp.step.anova # (by Splus, adapted by A. Lehmann from step.gam) # grasp.step.anova is a modified version of step.gam of Splus using ANOVA based on Chi or F tests instead # of AIC criteria # Erro em untangle.scope(object$terms, scope) : The elements of a regimen 1 appear more than once in the initial model Dont work and grasp manual is incomplete. Anybody know other package to make this? Thanks Ronaldo -- Prof. Ronaldo Reis Júnior | .''`. UNIMONTES/Depto. Biologia Geral/Lab. de Biologia Computacional | : :' : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia | `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil | `- Fone: (38) 3229-8187 | [EMAIL PROTECTED] | [EMAIL PROTECTED] | http://www.ppgcb.unimontes.br/ | ICQ#: 5692561 | LinuxUser#: 205366 __ 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] problem with png()
Hi Ingo Your code worked for me and I did not lose the title. Not much help I know but my session details are below to compare. Windows XP ... Regards JS sessionInfo() R version 2.6.0 (2007-10-03) i386-pc-mingw32 locale: LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] lattice_0.17-1 RWinEdt_1.7-8 loaded via a namespace (and not attached): [1] grid_2.6.0 --- John Seers Institute of Food Research Norwich Research Park Colney Norwich NR4 7UA tel +44 (0)1603 251497 fax +44 (0)1603 507723 e-mail [EMAIL PROTECTED] e-disclaimer at http://www.ifr.ac.uk/edisclaimer/ Web sites: www.ifr.ac.uk www.foodandhealthnetwork.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ingo Holz Sent: 15 November 2007 11:34 To: r-help@r-project.org Subject: Re: [R] problem with png() Dear Brian, sorry, library(lattice) is loaded, when I start R, so I forgot to add this. I get Ingo's title if I plot directly to the screen. However, I do not get it if I use png() or I lose it if I save from the plot (screen). Ingo On 15 Nov 2007 at 10:30, Prof Brian Ripley wrote: Works for me when I add the library(lattice) you omitted Since effectively all png() is doing is copying the screen, the problem is unlikely to be in png(). Most such problems are when there is not enough space to include labels, and you need to adjust margins or pointsize. On Thu, 15 Nov 2007, Ingo Holz wrote: Hi, I am runing R2.6.0 (2007-10-03) on WindowsXP. If I use png() to save a plot I lose the main title. An example: ## outfile - outfile.png p11 - histogram( ~ height | voice.part, data = singer, xlab=Height, main=Ingo's title) p2 - histogram( ~ height, data = singer, xlab = Height) png(outfile, width=800, height=800) print(p11, split=c(1,1,1,2), more=TRUE) print(p2, split=c(1,2,1,2)) dev.off() In my outfile.png I do not see Ingo's title. I know that it is not possible to reproduce this error on LINUX. It seems not possible on Windows, either. Thank you for your help. Ingo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] negative binomial lmer
lmer will work with negative binomial models, provided you specify an explicit, scalar value for theta. Rather than family = negative.binomial(theta = x) try something like family=negative.binomial(theta = 2.5) (or whatever you wish specify as theta). Bill Venables. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of H. Skaug Sent: Thursday, 15 November 2007 8:16 PM To: r-help@r-project.org Subject: [R] negative binomial lmer If lmer() does not do it, you can try: http://otter-rsch.com/admbre/examples/glmmadmb/glmmADMB.html It handles negative binomial responce (but you may have to remove data entries involving NA manually). Regards, hans Hi I am running an lmer which works fine with family=poisson mixed.model -lmer(nobees~spray+dist+flwabund+flwdiv+round+(1|field),family=poisson ,method=ML, na.action=na.omit) But it is overdispersed. I tried using family=quasipoisson but get no P values. This didnt worry me too much as i think my data is closer to negative binomial but i cant find any examples of negative binomial lmer. I tried using the family=negative.binomial(theta=x,link=log) but got an error message from R saying the function famiily=negative.binomial wasnt recognised. Can anyone suggest how to go about setting up the lmer with negative binomial distribution? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a repetition of simulation
Hello, In addition to my question a few days ago, Now I have a matrix of the coefficients, how can I see all the P.Values (Pr(|z|)) of the covariates from the 1000 iterations? I tried names(log_v) and couldn'n find it. Thank you, Sigalit. On 11/13/07, Julian Burgos [EMAIL PROTECTED] wrote: Well, the obvious (but perhaps not the most elegant) solution is put everything in a loop and run it 600 times. coefficients=matrix(NA,ncol=3,nrow=600) for (loop in 1:600){ [all your code here] coefficients[loop,]=coef(log_v) } That will give you a matrix with the coefficients of each model run in each row. Julian sigalit mangut-leiba wrote: I want to repeat the simulation 600 times and to get a vector of 600 coefficients for every covariate: aps and tiss. Sigalit. On 11/13/07, Julian Burgos [EMAIL PROTECTED] wrote: And what is your question? Julian sigalit mangut-leiba wrote: Hello, I have a simple (?) simulation problem. I'm doing a simulation with logistic model and I want to reapet it 600 times. The simulation looks like this: z - 0 x - 0 y - 0 aps - 0 tiss - 0 for (i in 1:500){ z[i] - rbinom(1, 1, .6) x[i] - rbinom(1, 1, .95) y[i] - z[i]*x[i] if (y[i]==1) aps[i] - rnorm(1,mean=13.4, sd=7.09) else aps[i] - rnorm(1,mean=12.67, sd=6.82) if (y[i]==1) tiss[i] - rnorm(1,mean=20.731,sd=9.751) else tiss[i] - rnorm(1,mean=18.531,sd=9.499) } v - data.frame(y, aps, tiss) log_v - glm(y~., family=binomial, data=v) summary(log_v) I want to do a repetition of this 600 times (I want to have 600 logistic models), and see all the coefficients of the covariates aps tiss. Thanks in advance, Sigalit. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Unable to save plot as .pdf , ps , eps
http://tolstoy.newcastle.edu.au/R/e2/help/07/10/27155.html b On Nov 15, 2007, at 8:11 AM, Luis Ridao Cruz wrote: R-help, Whenever I try to save a plot with extension .pdf , ps or eps I get the following error/warning message: plot(rnorm(10)) savePlot(test,type=pdf) Error in savePlot(test, type = pdf) : Invalid font type In addition: Warning messages: 1: In savePlot(test, type = pdf) : font family not found in PostScript font database 2: In savePlot(test, type = pdf) : font family not found in PostScript font database Can anyone let me know wht it is going on Thanks in advance version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 6.0 year 2007 month 10 day03 svn rev43063 language R version.string R version 2.6.0 (2007-10-03) __ 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] Unable to save plot as .pdf , ps , eps
R-help, Whenever I try to save a plot with extension .pdf , ps or eps I get the following error/warning message: plot(rnorm(10)) savePlot(test,type=pdf) Error in savePlot(test, type = pdf) : Invalid font type In addition: Warning messages: 1: In savePlot(test, type = pdf) : font family not found in PostScript font database 2: In savePlot(test, type = pdf) : font family not found in PostScript font database Can anyone let me know wht it is going on Thanks in advance version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 6.0 year 2007 month 10 day03 svn rev43063 language R version.string R version 2.6.0 (2007-10-03) __ 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] Romoving elements from a vector. Looking for the opposite of c(), New user
On Nov 15, 2007, at 9:15 AM, Thomas Frööjd wrote: Hi I have three vectors say x, y, z. One of them, x contains observations on a variable. To x I want to append all observations from y and remove all from z. For appending c() is easily used x - c(x,y) But how do I remove all observations in z from x? You can say I am looking for the opposite of c(). If you are looking for the opposite of c, provided you want to remove the first part of things, then perhaps this would work: z-c(x,y) z[-(1:length(x))] However, if you wanted to remove all appearances of elements of x from c(x,y), regardless of whether those elements appear in the x part of in the y part, I think you would want: z[!z %in% x] Probably there are other ways. Welcome to R! Best regards Haris Skiadas Department of Mathematics and Computer Science Hanover College __ 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] generate combination set
I must be missing something. What's wrong with: combn(set, 2) or if we must t(combn(set,2)), optionally with a function argument in the combn call if something is to be done with the pairs? So if you really wanted the outputs to be AB,AC etc, you would do: combn(set,2, paste, collapse=) Haris Skiadas Department of Mathematics and Computer Science Hanover College On Nov 15, 2007, at 8:54 AM, Adrian Dusa wrote: Using your set, wouldn't it be simpler like this? t(apply(combn(7,2), 2, function(x) set[x])) Hth, Adrian On Thursday 15 November 2007, [EMAIL PROTECTED] wrote: There are a number of packages that do this, but here is a simple function for choosing subsets: subsets - function(n, r) { if(is.numeric(n) length(n) == 1) v - 1:n else { v - n n - length(v) } subs - function(n, r, v) if(r = 0) NULL else if(r = n) matrix(v[1:n], nrow = 1) else rbind(cbind(v[1], subs(n - 1, r - 1, v[-1])), subs(n - 1, r, v[-1])) subs(n, r, v) } Here is an example of how to use it: set - LETTERS[1:7] subsets(set, 2) [,1] [,2] [1,] A B [2,] A C [3,] A D [4,] A E [5,] A F [6,] A G [7,] B C [8,] B D [9,] B E [10,] B F [11,] B G [12,] C D [13,] C E [14,] C F [15,] C G [16,] D E [17,] D F [18,] D G [19,] E F [20,] E G [21,] F G Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] project.org] On Behalf Of [EMAIL PROTECTED] Sent: Thursday, 15 November 2007 2:51 PM To: r-help@r-project.org Subject: [R] generate combination set I have a set data={A,B,C,D,E,F,G} I want to choose 2 letter from 8 letters, i.e. generate the combination set for choose 2 letters from 8 letters. I want to get the liking: combination set={AB,AC,AD,} Does anyone konw how to do in R. thanks, Aimin __ 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. -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd 050025 Bucharest sector 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ 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] Re : Unable to save plot as .pdf , ps , eps
I simply use pdf(test.pdf) plot(rnorm(10)) dev.off() postscript(test.ps) plot(rnorm(10)) dev.off() Justin BEM BP 1917 Yaoundé Tél (237) 99597295 (237) 22040246 - Message d'origine De : Luis Ridao Cruz [EMAIL PROTECTED] à : [EMAIL PROTECTED] Envoyé le : Jeudi, 15 Novembre 2007, 14h11mn 28s Objet : [R] Unable to save plot as .pdf , ps , eps R-help, Whenever I try to save a plot with extension .pdf , ps or eps I get the following error/warning message: plot(rnorm(10)) savePlot(test,type=pdf) Error in savePlot(test, type = pdf) : Invalid font type In addition: Warning messages: 1: In savePlot(test, type = pdf) : font family not found in PostScript font database 2: In savePlot(test, type = pdf) : font family not found in PostScript font database Can anyone let me know wht it is going on Thanks in advance version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 6.0 year 2007 month 10 day03 svn rev43063 language R version.string R version 2.6.0 (2007-10-03) __ 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. _ l [[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] no applicable method for names
Actually names(z) works for me. More seriously I don't seem to have a problem with XP and 2.6.0. It may be a slightly wonky installation. You might want to try a re-install and see what happens. --- Schiller Judith 1541 EB [EMAIL PROTECTED] wrote: hi, after installing R-2.6.0 the function names doesn't work anymore on my windows xp machine. for example for a simple vector i get z - 1:3 names(x) Error in UseMethod(name): no applicable method for names ... instead of NULL. the same is true for lists and dataframes. attr(z, names) is a workaround, but i don't want to change all my functions. is this a know bug? thanks for any comments, judith schiller __ 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] counting strings of identical values in a matrix
Hello I have this problem. I have a large matrix of this sort: prova [,1] [,2] [,3] [,4] [1,]3333 [2,]3331 [3,]1333 [4,]1113 [5,]3113 [6,]3113 [7,]1313 [8,]1333 What I want to do is to count the number of sequences of ones and stack the results in a vector, which I will subsequently use to build an istogram (or a density) I mean: in the matrix prova I have two sequences of length two in column 1, one sequence of length three in column 2, one sequence of length four in column 3 and one sequence of length one in column 4. (I know I can actually turn the matrix into a vector by using rep(prova)) I would like to get to a vector such as : xx = [1,2,1,1] Can anyone help? Thanks! Mario === Andrea Mario Lavezzi Dipartimento di Studi su Politica Diritto e Società Piazza Bologni 8 90134 Palermo tel. ++39 091 6625600 fax ++39 091 6112023 skype: lavezzimario email: [EMAIL PROTECTED] web: http://www.unipa.it/~lavezzi === __ 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] map - mapproj : problem of states localisation
I haven't seen the original code, but the problem with Ray's code is that the two projections are not synchronized. Specifically, they are using different (default) values for the orientation. To synchronize the projections, either specify the orientation parameter for both, or the second one should use proj=, as follows: map(france, proj=lambert, pa=c(30, 60)) map(world, proj=, lwd=1, col=red, add=TRUE) # reuse previous projection Tom -Original Message- From: Ray Brownrigg [mailto:[EMAIL PROTECTED] Sent: 14 November 2007 21:03 To: Amandine Chevalier Cc: r-help@r-project.org; [EMAIL PROTECTED] Subject: Re: [R] map - mapproj : problem of states localisation On Wed, 14 Nov 2007, Amandine Chevalier wrote: Thank you very much for your help, I work about my code so as to give you the example (attached file) : In the first case (azequalarea projection), france from the france map and from the world map are well superimposed, whereas in the second case (lambert projection), it is not. However, due to projections I used to produce my data, it would be better to use the lambert projection...That is not only a problem of boundaries that do not line up...it is like the map of France (it would be the same with the Italy's map) was centered on the figure without taking into account the lat-long...Can I also trust the location of the world map ? Do you have any idea of the problem? Thank you veru much for your help, Regards, Amandine It seems to me the problem doesn't need 200 lines of code and data to describe, it is merely: library(mapproj) map(france, proj=lambert, pa=c(30, 60)) map(world, proj=lambert, pa=c(30, 60), lwd=1, col=red, add=TRUE) So I've punted it to the maintainer of mapproj, who isn't me. Ray __ 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] font formating
you can do this with expression() as in plot(1:2,1:2,main=expression(x[k[j]])) see ?plotmath for some more possibilities of formating mathematical expressions. hth. José Alberto Monteiro schrieb: I am tryindo to do a very simple thing but cannont find how to do it anywhere. I need to formap part of my title as subscript ans superscript. How can I do it? Thanks a lot in advance José __ 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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790 __ 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] Ancova doesn't return test statistics
Dear all, I'm quite sure that this is a stupid question, but I'll ask anyway. I want to perform an ANCOVA with two continuous factors and three categorical factors. Plant population growth rate (GR) = dependent variable Seed reduction due to herbivory (SR) = continuous explanatory variable Herbivore species (HS, 2 levels) = categorical explanatory variable Population (Pop, 24 levels) = categorical explanatory variable Population size (Popsize) = continuous explanatory variable Year (Year, 16 levels) = categorical explanatory variable My model is technically simple: model-aov(GR~SR*HS*Pop*Popsize*Year) However, R is not returning any F and P values – only Df, Sum Sq and Mean Sq. I have to remove either Year or Pop in order to get the test statistics. Why is this? Thank you in advance! Johan A. Stenberg, Umea University, Sweden __ 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] font formating
you may read, as suggested, ?plotmath and look at the examples example(plotmath) José Alberto Monteiro schrieb: Thanks a lot! Can I use it inside text( )? Like text(expression=()) -- MSc José Alberto F. Monteiro Botanisches Institut Universität Basel -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problems working with large data
Hi, I'm working with a numeric matrix with 55columns and 581012 rows and I'm having problems in allocation of memory using some of the functions in R: for example lda, rda (library MASS), princomp(package mva) and mvnorm.etest (energy package). I've read tips to use less memory in help(read.table) and managed to use some of this functions, but haven't been able to work with mvnorm.etest. I would like to know the better way to solve this problem, as well as doing it faster. Best regards, Pedro Marques __ 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] combine two dataframe
Well, I admit I did not make it very clear. it was actually not sqldf that failed to be installed, that fact is that when I install sqdf, R did not find RSQLite(I have to check ) package which sqldf depends on on my linux box. I am using R-2.5/linux. Not sure if upgrading to 2.6 may help or not. and, sqldf is quite convenient when I can still remember some basic SQL syntax. :) Gabor Grothendieck [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Nov 14, 2007 4:59 AM, sun [EMAIL PROTECTED] wrote: Thanks all for the answers. Both Merge and sqldf works perfectly for me. Well, I feel sqldf run a littile bit slower. And I failed to install this package (sqldf ) on my linux box. Have never heard of anyone not being able to install sqldf on Linux before. sqldf is written in 100% R so it should run on all platforms R runs on and for which its dependencies work, mainly RSQLite (or RMySQL). As mentioned on the home page, http://sqldf.googlecode.com, sqldf is optimized for convenience, not speed, so I would not think it would be the fastest. Denver, your approach also works, but in my case, data frame A has much more rows then B, so B has to be duplicated many many times. kind regards, Sun - Original Message - From: Gabor Grothendieck [EMAIL PROTECTED] To: sun [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, November 13, 2007 6:07 PM Subject: Re: [R] combine two dataframe Try this: A - data.frame(a1 = c(1, 2, 1), a2 = c(2, 3, 3), a3 = c(3, 1, 2)) B - data.frame(b1 = 1:2, b2 = 2:1) library(sqldf) sqldf(select * from A, B) a1 a2 a3 b1 b2 1 1 2 3 1 2 2 1 2 3 2 1 3 2 3 1 1 2 4 2 3 1 2 1 5 1 3 2 1 2 6 1 3 2 2 1 On Nov 13, 2007 6:49 AM, sun [EMAIL PROTECTED] wrote: I have two data frame A and B adn want to cross them. A has format as: a1 a2 a3 1 23 2 31 1 32 ... B: b1 b2 1 2 2 1 ... the combine result shall be something like a1 a2 a3 b1 b2 1 2 3 1 2 1 2 3 2 1 2 3 1 1 2 2 3 1 2 1 1 3 2 1 2 1 3 2 2 1 is there a function able of doing this instead of loops? Thanks, Sun __ 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. __ 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] counting strings of identical values in a matrix
On Thu, 2007-11-15 at 15:51 +0100, A M Lavezzi wrote: Hello I have this problem. I have a large matrix of this sort: prova [,1] [,2] [,3] [,4] [1,]3333 [2,]3331 [3,]1333 [4,]1113 [5,]3113 [6,]3113 [7,]1313 [8,]1333 What I want to do is to count the number of sequences of ones and stack the results in a vector, which I will subsequently use to build an istogram (or a density) I mean: in the matrix prova I have two sequences of length two in column 1, one sequence of length three in column 2, one sequence of length four in column 3 and one sequence of length one in column 4. (I know I can actually turn the matrix into a vector by using rep(prova)) I would like to get to a vector such as : xx = [1,2,1,1] I presume a typo above and that it should be: xx = [2,1,1,1] ? If so: unlist(lapply(apply(prova, 2, rle), function(x) length(x$lengths[x$values == 1]))) [1] 2 1 1 1 See ?rle to get the basics of identifying runs of values. HTH, Marc Schwartz __ 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] Ancova doesn't return test statistics
On Thu, 2007-11-15 at 16:36 +0100, Johan A. Stenberg wrote: Dear all, I'm quite sure that this is a stupid question, but I'll ask anyway. I want to perform an ANCOVA with two continuous factors and three categorical factors. Plant population growth rate (GR) = dependent variable Seed reduction due to herbivory (SR) = continuous explanatory variable Herbivore species (HS, 2 levels) = categorical explanatory variable Population (Pop, 24 levels) = categorical explanatory variable Population size (Popsize) = continuous explanatory variable Year (Year, 16 levels) = categorical explanatory variable My model is technically simple: model-aov(GR~SR*HS*Pop*Popsize*Year) However, R is not returning any F and P values – only Df, Sum Sq and Mean Sq. I have to remove either Year or Pop in order to get the test statistics. Why is this? Thank you in advance! Johan A. Stenberg, Umea University, Sweden See ?summary.aov which is referenced in the See Also section of ?aov and is used in the examples therein. HTH, Marc Schwartz __ 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] Romoving elements from a vector. Looking for the opposite of c(), New user
Not sure i explained it good enough. Ill try with an example say x=[3,3,4,4,4,4,5,5,6,8] z=[3,4,4,5,5] what i want to get after removing z from x is something like x=[3,4,4,6,8] On Nov 15, 2007 3:29 PM, Charilaos Skiadas [EMAIL PROTECTED] wrote: On Nov 15, 2007, at 9:15 AM, Thomas Frööjd wrote: Hi I have three vectors say x, y, z. One of them, x contains observations on a variable. To x I want to append all observations from y and remove all from z. For appending c() is easily used x - c(x,y) But how do I remove all observations in z from x? You can say I am looking for the opposite of c(). If you are looking for the opposite of c, provided you want to remove the first part of things, then perhaps this would work: z-c(x,y) z[-(1:length(x))] However, if you wanted to remove all appearances of elements of x from c(x,y), regardless of whether those elements appear in the x part of in the y part, I think you would want: z[!z %in% x] Probably there are other ways. Welcome to R! Best regards Haris Skiadas Department of Mathematics and Computer Science Hanover College __ 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] quadratic solver, constrained problem
Dear all, I am locking for a quadratic solver in R beeing able to solve the following sort of problem: minimize || y - Xmatrix u ||^2 subject to: Amatrix u = Bbound and u = lowbound While the functions pcls{mgcv} and solve.QP{quadprog} can handle the first part of the constraint it seems that they are not designed to deal with the second part (or I do not see how to specify this second constraint). Is there an existing function for this sort of problem in R? Regards, Sven Sven Lautenbach UFZ Centre for Environmental Research in the Helmholtz Association Department for Computational Landscape Ecology Permosterstr. 15 D-04318 Leipzig Germany [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] counting strings of identical values in a matrix
Dear Marc thank you so much! One thing: writing xx=[1,2,1,1] is not a typo: I read it as the count of runs of different length starting from 1. In prova I have 1 run of length one, 2 runs of length two, 1 run of length three and 1 run of length four. Can I abuse of your time and ask how to do this? Thanks again Mario At 16.48 15/11/2007, you wrote: On Thu, 2007-11-15 at 15:51 +0100, A M Lavezzi wrote: Hello I have this problem. I have a large matrix of this sort: prova [,1] [,2] [,3] [,4] [1,]3333 [2,]3331 [3,]1333 [4,]1113 [5,]3113 [6,]3113 [7,]1313 [8,]1333 What I want to do is to count the number of sequences of ones and stack the results in a vector, which I will subsequently use to build an istogram (or a density) I mean: in the matrix prova I have two sequences of length two in column 1, one sequence of length three in column 2, one sequence of length four in column 3 and one sequence of length one in column 4. (I know I can actually turn the matrix into a vector by using rep(prova)) I would like to get to a vector such as : xx = [1,2,1,1] I presume a typo above and that it should be: xx = [2,1,1,1] ? If so: unlist(lapply(apply(prova, 2, rle), function(x) length(x$lengths[x$values == 1]))) [1] 2 1 1 1 See ?rle to get the basics of identifying runs of values. HTH, Marc Schwartz === Andrea Mario Lavezzi Dipartimento di Studi su Politica Diritto e Società Piazza Bologni 8 90134 Palermo tel. ++39 091 6625600 fax ++39 091 6112023 skype: lavezzimario email: [EMAIL PROTECTED] web: http://www.unipa.it/~lavezzi === __ 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] Plot problem
Dear list, I have a question about using plot(). I tried the code: pdf(mel_chr_all_13cancer_cghFLasso_all.pdf, height=6, width=11);plot( Disease.FL, index=1:4, type=All);dev.off(); and it went through well which outputed 4 plots for 4 samples in one page. But if I increase the numbers of plots(samples) which I want, saying to 11, pdf(mel_chr_all_13cancer_cghFLasso_all.pdf, height=6, width=11);plot( Disease.FL, index=1:11, type=All);dev.off(); then I got an error message as: Error in segments((1:n)[y 0], jp, (1:n)[y 0], jp + y[y 0], col = downcol) :invalid first argument I suspect that it has sth to do with the maxium plots which can be outputed on one page, which means less or equal to 4 will be fine but beyond that there will be a problem. I have tried the number 5 yet. Is there a way that I could specify that the plots can be put on multiple pages with 4 plots per one. Thank you very much for your help! Best, Allen [[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] Romoving elements from a vector. Looking for the opposite of c(), New user
Thomas Frööjd wrote: Not sure i explained it good enough. Ill try with an example say x=[3,3,4,4,4,4,5,5,6,8] z=[3,4,4,5,5] what i want to get after removing z from x is something like x=[3,4,4,6,8] On Nov 15, 2007 3:29 PM, Charilaos Skiadas [EMAIL PROTECTED] wrote: On Nov 15, 2007, at 9:15 AM, Thomas Frööjd wrote: Hi I have three vectors say x, y, z. One of them, x contains observations on a variable. To x I want to append all observations from y and remove all from z. For appending c() is easily used x - c(x,y) But how do I remove all observations in z from x? You can say I am looking for the opposite of c(). If you are looking for the opposite of c, provided you want to remove the first part of things, then perhaps this would work: z-c(x,y) z[-(1:length(x))] However, if you wanted to remove all appearances of elements of x from c(x,y), regardless of whether those elements appear in the x part of in the y part, I think you would want: z[!z %in% x] Probably there are other ways. Welcome to R! Best regards Haris Skiadas Department of Mathematics and Computer Science Hanover College __ 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. Hi, you may try this : x=[3,3,4,4,4,4,5,5,6,8] z=c(3,4,4,5,5) f1 - function(vec,toremove){ + + for(elem in toremove){ + temp - grep(elem,vec)[1] + if(!is.na(temp)) vec - vec[-temp] + } + + return(vec) + } f1(x,z) [1] 3 4 4 6 8 Regards, Thibaut. -- ## Thibaut JOMBART CNRS UMR 5558 - Laboratoire de Biométrie et Biologie Evolutive Universite Lyon 1 43 bd du 11 novembre 1918 69622 Villeurbanne Cedex Tél. : 04.72.43.29.35 Fax : 04.72.43.13.88 [EMAIL PROTECTED] http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en http://pbil.univ-lyon1.fr/software/adegenet/ __ 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] ESRI Shapefile for EU-25
Here are some sites that I found with maps of europe (or more, but eourope is included). I don't know how up to date these are, so check them out for yourself: http://www.vdstech.com/map_data.htm http://openmap.bbn.com/data/shape/timezone/ http://arcdata.esri.com/data_downloader/DataDownloader?part=10200stack= back Hope this helps, -- 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 Albrecht Kauffmann Sent: Tuesday, November 13, 2007 5:30 AM To: r-help@r-project.org Subject: [R] ESRI Shapefile for EU-25 Hi all, who knows how to get an ESRI Shapefile for the NUTS-2 Regions of the enlarged European Union? Particularly I want to draw maps of Germany, Poland, Czech Republik, Hungary and Austria. I've found Shapefiles for the US, Russia and other countries elsewhere in the web, but for Europe it seems really difficult. With many thanks for any hint Albrecht __ 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] font formating
I am tryindo to do a very simple thing but cannont find how to do it anywhere. I need to formap part of my title as subscript ans superscript. How can I do it? Thanks a lot in advance José -- MSc José Alberto F. Monteiro Botanisches Institut Universität Basel [[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] combine two dataframe
Here is another approach: tmp - expand.grid( 1:nrow(B), 1:nrow(A) ) out - cbind( A[tmp[,2],], B[tmp[,1],] ) Hope this helps, -- 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 sun Sent: Tuesday, November 13, 2007 4:50 AM To: [EMAIL PROTECTED] Subject: [R] combine two dataframe I have two data frame A and B adn want to cross them. A has format as: a1 a2 a3 1 23 2 31 1 32 ... B: b1 b2 1 2 2 1 ... the combine result shall be something like a1 a2 a3 b1 b2 1 2 3 1 2 1 2 3 2 1 2 3 1 1 2 2 3 1 2 1 1 3 2 1 2 1 3 2 2 1 is there a function able of doing this instead of loops? Thanks, Sun __ 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] Error with read.delim read.csv
Hi - I'm reading in a tab delimited file that is causing issues with read.delim. Specifically, for a specific set of lines, the last entry of the line is misread and considered to be the first entry of a new row (which is then padded with 'NA's' ). Specifically: tmp - read.delim( trouble.txt, header=F ) produces a data.frame, tmp where if I call tmp[,1], I get output like: [76] F45H7.4#2 C47C12.5#2F40H7.4#2 ZK353.2 0.59 [81] Y116A8C.340.23 Y116F11A.MM 0.04 F26D12.A I initially assumed it was a formatting issue with the file. However, I've tried looking at the file in octal viewer, and the lines in question seem fine. Additionally, using scan and then strsplit can split the lines correctly (code below the sig). Since I can't attach the file to a group posting, I can't give a sample of the lines causing the issue, however, I can send a small sample to anyone who's interested. Note, I've tried this on several architectures and versions of R and get the same behavior. Specifically, v.2.5.1 on an x86_64, as well as v.2.6.0 on an x686 architecture. I also get similar behavior when I convert the file into a comma-separated file and use read.csv. As a quick workaround I can use scan strsplit, but thought someone might want to take a look at this problem. Thanks, Peter Waltman p.s. the combination of scan strsplit I describe above was as follows: my.lines - scan( trouble.txt, sep=\n, what='character' ) split.lines - strsplit( my.lines, \t ) num.entries - sapply( split.lines, length ) after which num.lines will contain a equal number of entries as my.lines, all containing 509 (the number of elt's per line). __ 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] kalman filter estimation
[EMAIL PROTECTED] wrote: Hi, Following convention below: y(t) = Ax(t)+Bu(t)+eps(t) # observation eq x(t) = Cx(t-1)+Du(t)+eta(t) # state eq I modified the following routine (which I copied from: http://www.stat.pitt.edu/stoffer/tsa2/Rcode/Kall.R) to accommodate u(t), an exogenous input to the system. for (i in 2:N){ xp[[i]]=C%*%xf[[i-1]] Pp[[i]]=C%*%Pf[[i-1]]%*%t(C)+Q siginv=A[[i]]%*%Pp[[i]]%*%t(A[[i]])+R sig[[i]]=(t(siginv)+siginv)/2 # make sure sig is symmetric siginv=solve(sig[[i]]) # now siginv is sig[[i]]^{-1} K=Pp[[i]]%*%t(A[[i]])%*%siginv innov[[i]]=as.matrix(yobs[i,])-A[[i]]%*%xp[[i]] xf[[i]]=xp[[i]]+K%*%innov[[i]] Pf[[i]]=Pp[[i]]-K%*%A[[i]]%*%Pp[[i]] like= like + log(det(sig[[i]])) + t(innov[[i]])%*%siginv%*%innov[[i]] } like=0.5*like list(xp=xp,Pp=Pp,xf=xf,Pf=Pf,like=like,innov=innov,sig=sig,Kn=K) } I tried to fit my problem and observe that I got positive log likelihood mainly because the log of determinant of my variance matrix is largely negative. That's not good because they should be positive. Have anyone experience this kind of instability? The determinant should not be negative (the line # make sure sig is symmetric should look after that) but the log can be negative. Also, I realize that I have about 800 sample points. The above routine when being plugged to optim becomes very slow. Could anyone share a faster way to compute kalman filter? The KF recursion you show is not time varying, but the code you show looks like it may allow for time varying models. (I'm just guessing, I'm not familiar with the code.) If you do not need the time varying aspect then this is probably a slow way to implement. Package dse1 in the dse bundle implements the recursion the way you show, with an exogenous input u(t), so you don't even have to modify the code. It is implemented in R for demonstration, but also in fortran for speed. See the dse Users Guide for more details, and also ?SS and ?l.SS. One caveat is that the way the likelihood is cumulated over i in your code above allows for time varying sig, which in theory can be important for a diffuse prior. In dse the likelihood is calculated using the residual to get a sample estimate of sig, which is faster. I have not found cases where this makes much difference (but would be interested to know of one). And my last problem is, optim with my defined feasible space does not converge. I have about 20 variables that I need to identify using MLE method. Is there any other way that I can try out? I tried most of the methods available in optim already. They do not converge at all.. Thank you. This used to be a well known problem for multivariate state space models, but seems to be largely forgotten. It does not seriously affect univariate models. For a review of the old literature see section 5 of Gilbert 1993, available at http://www.bank-banque-canada.ca/pgilbert/research.php#MiscResearch. The bottom line is that you are in trouble trying to use hill climbing methods and state-space models unless you have a very good starting point, or are luck. This is a feature of the parameter space, not a reflection on the optimization routine. One solution is to start by estimating a VAR or ARMA model and then convert it to a state space model, which was one of the original purposes of dse. (See ?bft for example.) Paul Gilbert - adschai __ 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. La version française suit le texte anglais. This email may contain privileged and/or confidential information, and the Bank of Canada does not waive any related rights. Any distribution, use, or copying of this email or the information it contains by other than the intended recipient is unauthorized. If you received this email in error please delete it immediately from your system and notify the sender promptly by email that you have done so. Le présent courriel peut contenir de l'information privilégiée ou confidentielle. La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute diffusion, utilisation ou copie de ce courriel ou des renseignements qu'il contient par une personne autre que le ou les destinataires désignés est interdite. Si vous recevez ce courriel par erreur, veuillez le supprimer immédiatement et envoyer sans délai à l'expéditeur un message électronique pour l'aviser que vous avez éliminé de votre ordinateur toute copie du courriel reçu.
[R] Multiply each column of array by vector component
Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij * v_j This seems so basic but I can't figure out how to do it without a loop. Any suggestions? Michal. __ 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] kalman filter estimation
Giovanni Petris wrote: Kalman filter for general state space models, especially in its naive version, is known for its numerical instability. This is the reason why people developed square root filters, based on Cholesky decomposition of variance matrices. In package dlm the implementation of Kalman filter is based on the singular value decomposition (SVD) of the relevant variance matrices, providing for a more robust algorithm than the standard square root filter. The lack of convergence of optimization algorithms in finding MLEs of unknown parameters is not surprising to me, especially if you have many parameters. When using state space models it is easy to end up with a fairly flat, or multimodal likelihood function. These are two signs of poor identifiability of the model. Lack of identification makes things worse, but these problems can occur even when the model is identified. The problem is actually worse then what you indicate. There can be large regions of parameter space where the likelihood increases as parameters diverge to infinity. This was the basis of the literature on chart switching procedures. Also, it is not so much the number of parameters that cause the problem as it is the dimension of the output (though they tend to be related). A univariate model with a large state is usually not too bad if it is identified and there is enough data. However, multiple series can cause problems even with relatively few parameters. You can live with it, but be aware that it is there. My suggestion is to start the optimization from several different initial values and compare maximized values of the likelihood. Simulated annealing may be used to better explore the parameter space. Yes. Are you aware of any work on this in R? Paul HTH, Giovanni Date: Thu, 15 Nov 2007 04:41:26 + (GMT) From: [EMAIL PROTECTED] Sender: [EMAIL PROTECTED] Priority: normal Precedence: list Hi, Following convention below: y(t) = Ax(t)+Bu(t)+eps(t) # observation eq x(t) = Cx(t-1)+Du(t)+eta(t) # state eq I modified the following routine (which I copied from: http://www.stat.pitt.edu/stoffer/tsa2/Rcode/Kall.R) to accommodate u(t), an exogenous input to the system. for (i in 2:N){ xp[[i]]=C%*%xf[[i-1]] Pp[[i]]=C%*%Pf[[i-1]]%*%t(C)+Q siginv=A[[i]]%*%Pp[[i]]%*%t(A[[i]])+R sig[[i]]=(t(siginv)+siginv)/2 # make sure sig is symmetric siginv=solve(sig[[i]]) # now siginv is sig[[i]]^{-1} K=Pp[[i]]%*%t(A[[i]])%*%siginv innov[[i]]=as.matrix(yobs[i,])-A[[i]]%*%xp[[i]] xf[[i]]=xp[[i]]+K%*%innov[[i]] Pf[[i]]=Pp[[i]]-K%*%A[[i]]%*%Pp[[i]] like= like + log(det(sig[[i]])) + t(innov[[i]])%*%siginv%*%innov[[i]] } like=0.5*like list(xp=xp,Pp=Pp,xf=xf,Pf=Pf,like=like,innov=innov,sig=sig,Kn=K) } I tried to fit my problem and observe that I got positive log likelihood mainly because the log of determinant of my variance matrix is largely negative. That's not good because they should be positive. Have anyone experience this kind of instability? Also, I realize that I have about 800 sample points. The above routine when being plugged to optim becomes very slow. Could anyone share a faster way to compute kalman filter? And my last problem is, optim with my defined feasible space does not converge. I have about 20 variables that I need to identify using MLE method. Is there any other way that I can try out? I tried most of the methods available in optim already. They do not converge at all.. Thank you. - adschai __ 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. La version française suit le texte anglais. This email may contain privileged and/or confidential information, and the Bank of Canada does not waive any related rights. Any distribution, use, or copying of this email or the information it contains by other than the intended recipient is unauthorized. If you received this email in error please delete it immediately from your system and notify the sender promptly by email that you have done so. Le présent courriel peut contenir de l'information privilégiée ou confidentielle. La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute diffusion, utilisation ou copie de ce courriel ou des renseignements qu'il contient par une personne autre que le ou les destinataires désignés est interdite. Si vous recevez ce courriel par erreur, veuillez le supprimer immédiatement et envoyer sans délai à l'expéditeur un message électronique pour l'aviser que
[R] sample nth day data in each month
Dear all i have a time series containing trading dates and historical stock prices: Date Price 10-Jan-2007 100 11-Jan-2007 101 13-Jan-2007 99 .. .. .. 10-Nov-2007 200 i want to sample every 21st data of each month: 21-Jan-2007 101 21-Feb-2007 111 21-Mar-2007 131 .. .. .. 21-Oct-2007 140 1) how can i do that? 2) if some of the dates are non-trading day, how can i tell R to use modified following or following data? thanks carles __ 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] Multiply each column of array by vector component
On Nov 15, 2007 12:50 PM, [EMAIL PROTECTED] wrote: Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij * v_j This seems so basic but I can't figure out how to do it without a loop. Any suggestions? Here are 4 ways: A - matrix(1:6, 3) v - 10:11 A %*% diag(v) A * rep(1, nrow(A)) %o% v t(t(A) * v) A * replace(A, TRUE, v[col(A)]) __ 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] Multiply each column of array by vector component
?sweep b On Nov 15, 2007, at 12:50 PM, [EMAIL PROTECTED] wrote: Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij * v_j This seems so basic but I can't figure out how to do it without a loop. Any suggestions? Michal. __ 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] counting strings of identical values in a matrix
Thanks Gabor. Nice solution. Marc On Thu, 2007-11-15 at 12:35 -0500, Gabor Grothendieck wrote: We can append a row of 0's to handle that case: with(rle(as.vector(rbind(prova, 0))), table(lengths[values == 1])) On Nov 15, 2007 11:36 AM, Marc Schwartz [EMAIL PROTECTED] wrote: Ah...OK. I misunderstood then. I thought that you wanted the number of runs of 1's in each column. This is actually easier, _if_ there is not an overlap of 1's from the end of one column to the start of the next column: res - rle(as.vector(prova)) res Run Length Encoding lengths: int [1:11] 2 2 2 2 3 3 5 4 2 1 ... values : int [1:11] 3 1 3 1 3 1 3 1 3 1 ... table(res$lengths[res$values == 1]) 1 2 3 4 1 2 1 1 HTH, Marc snip __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] kalman filter estimation
You can live with it, but be aware that it is there. My suggestion is to start the optimization from several different initial values and compare maximized values of the likelihood. Simulated annealing may be used to better explore the parameter space. Yes. Are you aware of any work on this in R? Paul The function dlmMLE in package dlm calls optim to find maximum likelihood estimates. You can pass additional arguments to optim, including method = SANN for simulated annealing. Giovanni __ 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
Hi everyone, Can someone help me with root bisection algorithm? Nadine - [[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] Rgui Windows command history
With the Mac and R.app, there is a window to the right of the console wherein all commands are display and can be re-chosen by double clicking. Does a similar feature exist with Windows and Rgui? Or have I missed it somewhere? Thank you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multiply each column of array by vector component
If i understand your question, you can do: x - matrix(1:10, 2) y - sample(10,5) apply(x, 1, function(.x)mapply(y, .x, FUN=*)) On 15/11/2007, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij * v_j This seems so basic but I can't figure out how to do it without a loop. Any suggestions? Michal. __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ 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] Romoving elements from a vector. Looking for the opposite of c(), New user
You can also check out the 'set' operations: setdiff, intersect, union. On Nov 15, 2007 12:08 PM, John Kane [EMAIL PROTECTED] wrote: I think you've read Thomas's request in reverse. and what he want is: x[!x %in% z] Thanks for the %in% approach BTW. --- Charilaos Skiadas [EMAIL PROTECTED] wrote: On Nov 15, 2007, at 9:15 AM, Thomas Fr��jd wrote: Hi I have three vectors say x, y, z. One of them, x contains observations on a variable. To x I want to append all observations from y and remove all from z. For appending c() is easily used x - c(x,y) But how do I remove all observations in z from x? You can say I am looking for the opposite of c(). If you are looking for the opposite of c, provided you want to remove the first part of things, then perhaps this would work: z-c(x,y) z[-(1:length(x))] However, if you wanted to remove all appearances of elements of x from c(x,y), regardless of whether those elements appear in the x part of in the y part, I think you would want: z[!z %in% x] Probably there are other ways. Welcome to R! Best regards Haris Skiadas Department of Mathematics and Computer Science Hanover College __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ 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] Rgui Windows command history
On Thu, 15 Nov 2007, Loren Engrav wrote: With the Mac and R.app, there is a window to the right of the console wherein all commands are display and can be re-chosen by double clicking. Does a similar feature exist with Windows and Rgui? Or have I missed it somewhere? You have. history() brings up a pager of past commands, and you can re-submit by the right-click menu (or Ctrl-V). -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] no applicable method for names
I think you have an object x which doensn't allow to give names. If you use names(z) it will work. To see what kind of object x is: class(x) Regards Bart Schiller Judith 1541 EB wrote: hi, after installing R-2.6.0 the function names doesn't work anymore on my windows xp machine. for example for a simple vector i get z - 1:3 names(x) Error in UseMethod(name): no applicable method for names ... instead of NULL. the same is true for lists and dataframes. attr(z, names) is a workaround, but i don't want to change all my functions. is this a know bug? thanks for any comments, judith schiller __ 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. -- View this message in context: http://www.nabble.com/no-applicable-method-for-%22names%22-tf4806311.html#a13764385 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] Romoving elements from a vector. Looking for the opposite of c(), New user
Jim, The one issue with those is that they remove duplicate elements in each vector before applying their logic. Thus, would not likely work here: x - c(3,3,4,4,4,4,5,5,6,8) z - c(3,4,4,5,5) In effect, you end up with: unique(x) [1] 3 4 5 6 8 unique(z) [1] 3 4 5 Thus: setdiff(x, z) [1] 6 8 setdiff(z, x) numeric(0) union(x, z) [1] 3 4 5 6 8 intersect(x, z) [1] 3 4 5 I am also not sure that the two solutions proposed using %in% work as desired, though I may be missing something there. I may have also missed other solutions in this thread, but here is a proposal: x - c(3,3,4,4,4,4,5,5,6,8) z - c(3,4,4,5,5) for (i in seq(length(z))) { Ind - match(z[i], x) x - x[-Ind] } x [1] 3 4 4 6 8 I think that works. HTH, Marc On Thu, 2007-11-15 at 13:28 -0500, jim holtman wrote: You can also check out the 'set' operations: setdiff, intersect, union. On Nov 15, 2007 12:08 PM, John Kane [EMAIL PROTECTED] wrote: I think you've read Thomas's request in reverse. and what he want is: x[!x %in% z] Thanks for the %in% approach BTW. --- Charilaos Skiadas [EMAIL PROTECTED] wrote: On Nov 15, 2007, at 9:15 AM, Thomas Fr��jd wrote: Hi I have three vectors say x, y, z. One of them, x contains observations on a variable. To x I want to append all observations from y and remove all from z. For appending c() is easily used x - c(x,y) But how do I remove all observations in z from x? You can say I am looking for the opposite of c(). If you are looking for the opposite of c, provided you want to remove the first part of things, then perhaps this would work: z-c(x,y) z[-(1:length(x))] However, if you wanted to remove all appearances of elements of x from c(x,y), regardless of whether those elements appear in the x part of in the y part, I think you would want: z[!z %in% x] Probably there are other ways. Welcome to R! __ 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] Using plotmath expressions in lattice key text
Folks: delta - 1:5 I would like to put 5 separate lines of text of the form 10 %+-% delta[i] into a lattice key legend, where %+-% is the plotmath plus/minus symbol and delta[i] is the ith value of delta. The construct: lapply(delta,function(d)bquote(10%+-%.(d))) appears to produce a list of expressions of the correct form, and, indeed, if I assign the above to (a list!) test, plot(0:1,0:1) text(.5,.5,test[[1]]) produces the correctly formatted plotmath expression. However, note that I have to use test[[1]] to extract the expression; test[1] doesn't work (it is a list containing an expression, not an expression) -- and therein may lie the problem. For if I try to use the above expression as the lab component of the text component in key, e.g. by xyplot(, key = list( text = list(lab = lapply(delta,function(d)bquote(10%+-%.(d))),...),...) I get an error: Error in fun(key = list(text = list(lab = list(10 %+-% 1, 10 %+-% 2 : first component of text has to be vector of labels So how should I do this?? I suspect it's simple, but I just can't figure it out. Note: I'd be happy to supply reproducible code if needed. Just complain and I'll do so. Thanks. Bert Gunter Genentech Nonclinical 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.
[R] Normalizing data
Hello, I have a data set of about 300.000 measurements made by an STM which should apporximately fix a normal (Gaussian) distribution. I have imported the data in R and used plot(density()) to get a nice plot of the distribution which in fact looks like a real Gaussian. However, the integral over the surface is not equal to one (I know since some of the plots extend to numbers greater then 1). Is there a way to normalize the data so the density function will actualy yield the probability of x (a height in my case)? This is my code so far: #Input path path - G:\\C\\Data txt\\1au300.txt #Dataverwerking data - read.table(path, header=TRUE) rows - length(data$height) height - data$height[1:rows] dens -density(height) mean - mean(height) sd - sd(height) min - min(hnorm) max - max(hnorm) #Plot par(new=FALSE) curve(dnorm(x,m=mean,sd=sd),from=min,to=max, xlab=, ylab=, col=white, lwd=2) points(dens, type=h, col=grey ) par(new=TRUE) curve(dnorm(x,m=mean,sd=sd),from=min,to=max, xlab=Height (nm), ylab=Density, lwd=2, col=darkred) Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] generate combination set
Actually, (now that I know about combn), a better way is t(matrix(set[combn(7,2)], nrow = 2)) Bill V. -Original Message- From: Adrian Dusa [mailto:[EMAIL PROTECTED] Sent: Thursday, 15 November 2007 11:55 PM To: Venables, Bill (CMIS, Cleveland) Cc: [EMAIL PROTECTED]; r-help@r-project.org Subject: Re: [R] generate combination set Using your set, wouldn't it be simpler like this? t(apply(combn(7,2), 2, function(x) set[x])) Hth, Adrian On Thursday 15 November 2007, [EMAIL PROTECTED] wrote: There are a number of packages that do this, but here is a simple function for choosing subsets: subsets - function(n, r) { if(is.numeric(n) length(n) == 1) v - 1:n else { v - n n - length(v) } subs - function(n, r, v) if(r = 0) NULL else if(r = n) matrix(v[1:n], nrow = 1) else rbind(cbind(v[1], subs(n - 1, r - 1, v[-1])), subs(n - 1, r, v[-1])) subs(n, r, v) } Here is an example of how to use it: set - LETTERS[1:7] subsets(set, 2) [,1] [,2] [1,] A B [2,] A C [3,] A D [4,] A E [5,] A F [6,] A G [7,] B C [8,] B D [9,] B E [10,] B F [11,] B G [12,] C D [13,] C E [14,] C F [15,] C G [16,] D E [17,] D F [18,] D G [19,] E F [20,] E G [21,] F G Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Thursday, 15 November 2007 2:51 PM To: r-help@r-project.org Subject: [R] generate combination set I have a set data={A,B,C,D,E,F,G} I want to choose 2 letter from 8 letters, i.e. generate the combination set for choose 2 letters from 8 letters. I want to get the liking: combination set={AB,AC,AD,} Does anyone konw how to do in R. thanks, Aimin __ 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. -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd 050025 Bucharest sector 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ 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] not R question : alternative to logistic regression
MARK LEEDS-3 wrote: I was just curious if anyone knew of an alternative model to logistic regression where the probabilities seems pretty linear to the predictor rather than having that S shape that probit and logit assume. Well, the logistic curve is very close to linear over the middle range of probabilities -- are your probabilities all in the middle, or do they seem to hit 0 and 1 fairly sharply? Using the formula interface to mle in the bbmle package (blatant plug), you could do something like mle2(surv~dbinom(prob=pmin(pmax(a+b*x,0.001),0.999),size=1),start=...) the pmin/pmax cut the probabilities off before they get to 1 or 0. I'm not sure this is a good idea, but it is possible. cheers Ben Bolker -- View this message in context: http://www.nabble.com/not-R-question-%3A-alternative-to-logistic-regression-tf4816865.html#a13781110 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] RMySQL installation problem
Hi List, I'm running R2.5.1 on WinXP. Downloaded RMySQL_0.6-0.zip from http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.6/ and the installation seemed fine. However, when I tried to load the package, the error occured: utils:::menuInstallLocal() package 'RMySQL' successfully unpacked and MD5 sums checked updating HTML package descriptions library(RMySQL) Loading required package: DBI Error in dyn.load(x, as.logical(local), as.logical(now)) : unable to load shared library 'C:/PROGRA~1/R/R-25~1.1/library/RMySQL/libs/RMySQL.dll': LoadLibrary failure: The specified module could not be found. Error: package/namespace load failed for 'RMySQL' ## However, I can see the .dll file is there from window's explorer!! There was also a pop windows says: R Console: Rgui.exe-Unable To Locate Component This application has failed to start because LIBMYSQL.dll was not found. Re-installing the application may fix the problem. I tried the re-installation. It didn't work. The DBI package I have is version 0.2-4, just in case. thanks, ...Tao _ Climb to the top of the charts! Play Star Shuffle: the word scramble challenge with star power. t __ 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] update matrix with subset of it where only row names match
jim holtman wrote: Lets take a look at your solution: mat1 - matrix(0, nrow=10, ncol=3) dimnames(mat1) - list(paste('row', 1:10, sep=''), LETTERS[1:3]) mat2 - matrix(1:3, ncol=1, dimnames=list(c('row3', 'row7', 'row5'), B)) mat2 B row3 1 row7 2 row5 3 mat1[rownames(mat2)%in%rownames(mat1),B]=mat2[,B] Error in mat1[rownames(mat2) %in% rownames(mat1), B] = mat2[, B] : number of items to replace is not a multiple of replacement length rownames(mat2)%in%rownames(mat1) [1] TRUE TRUE TRUE mat2[,B] row3 row7 row5 123 I got an error statement using your statement with %in%. This is because it produces a vector a 3 TRUE values are you can see above. With recycling to will the matrix, you get the error message. What you want to provide is the index value of the rows to replace in. What you would need in this case is the following statement: mat1[match(rownames(mat2), rownames(mat1)),B]=mat2[,B] Now your solution would have to be changed everytime you wanted a different column replaced. My solution determined which of the column names matched in the objects. In R, there are a number of ways of doing things. As to which is 'better', it all depends. In most cases it is probably a matter of 'style' or what a person is used to. Better does come into play when you are taking about performance and there might be a factor of 10X, 100X or 1000X depending on how you used some statements. I happen to like to try to break things down into some simple steps so if I have to go back later, I think I might be able to understand it again. If you are coming from a C/Java background, then one of hard things to get your mind around it to think in terms of 'vectorized' operations and also the difference in some of the ways that you create/manipulate data structures in R vs. some other languages. HTH Thankyou for you explanation and time - very helpful. Best wishes, Martin __ 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] Equal confidence interval arrowhead lengths across multiple-paneled lattice plots with free y-scales
Hi. I've got a lattice plot with multiple panels and two groups superimposed on each panel. Each panel has an independently scaled y-axis (scales = list(relation = free)). I've successfully put up 95%CI error bars using panel.arrows (and some help from the mailing list). My question is whether I can unscale the arrowheads so that they appear to have the same length across all panels. I recognize from the help-file that the length argument in panel.arrows is in terms of grid units (which I assume are specific to the particular panel). Can anybody think of a way to set the length so that it appears uniform across all panels? Example code: summTable-data.frame(X = seq(1,12), Y = c(1,8,3,6,6,5,7,3,8,1,10,-2), Location = rep(c(Site1, Site2), times = c(6,6)), Species = rep(c(A, B), 6) ) #change scale for Site 1 summTable[1:6,2]-100*summTable[1:6,2] #arbitrary confidence intervals summTable-cbind(summTable, ly = (summTable$Y*(.98)), uy = (summTable$Y*1.02) ) #panel plotting panel.func-function(x,y,ly,uy,subscripts,...){ ly-as.numeric(ly)[subscripts] uy-as.numeric(uy)[subscripts] panel.arrows(x,ly,x,uy, unit = native, angle = 90, length = .25, code = 3, ) panel.xyplot(x,y,...) } xyplot(Y ~ X | Location, groups = Species, type = l, data = summTable, scales = list(relation = free), ly = summTable$ly, uy = summTable$uy, auto.key = T, panel = panel.superpose, panel.groups = panel.func ) Thank you. --Bob Farmer (using R 2.6.0 and lattice 0.16-5) __ 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] Rgui Windows command history
On 11/15/2007 12:55 PM, Loren Engrav wrote: With the Mac and R.app, there is a window to the right of the console wherein all commands are display and can be re-chosen by double clicking. Does a similar feature exist with Windows and Rgui? Or have I missed it somewhere? history() will display a list; commands can be copied to the clipboard, or resubmitted directly to the console. See the local menu on the right mouse button. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with K-means Clustering
Hello, I'm new using R. I'm trying to develop a K-means Clustering with R for some data I have, however each time I use that instruction with the same data my cluster means, clustering vector and within cluster sum of square change and I don't understand why because I use the same parameters and the same data. Can anybody explain me why does it happen? Thank you Act. Calef Alejandro Rodríguez Cuevas Analista de mercado Laboratorios Farmasa S.A. de C.V. Schwabe Mexico, S.A. de C.V. Bufalo Nr. 27 Col. del Valle 03100 Mexico, D.F. Mexico Tel. 52 00 26 80 email: [EMAIL PROTECTED] www.schwabe.com.mx www.umckaloabo.com.mx __ 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 extract the elements of a list of vectors in a fixed position?
Hi, How is it possible to extract athe elements of a list of vectors in a fixed position? suppose that I have a list of 2-element vectors, how can I extract the 2nd element of all vectors in the list? Can it be done with indexing and not by element name? Thanks carol So in this example, I want to extract 2 and 4 v = list (c(1,2), c(3, 4)) v [[1]] [1] 1 2 [[2]] [1] 3 4 - Never miss a thing. Make Yahoo your homepage. [[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] not R question : alternative to logistic regression
I was just curious if anyone knew of an alternative model to logistic regression where the probabilities seems pretty linear to the predictor rather than having that S shape that probit and logit assume. Maybe there is there some kind of other GLM that could accomplish that. Any textbook references or suggestions are appreciated. I have most of the texts but if someone knows of a text that talks about this, it would be helpful because I don't even know of the name for such a model ( if it exists ) so I don't know where to look. Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] not R question : alternative to logistic regression
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Thursday, November 15, 2007 12:04 PM To: r-help@r-project.org Cc: [EMAIL PROTECTED] Subject: [R] not R question : alternative to logistic regression I was just curious if anyone knew of an alternative model to logistic regression where the probabilities seems pretty linear to the predictor rather than having that S shape that probit and logit assume. Maybe there is there some kind of other GLM that could accomplish that. Any textbook references or suggestions are appreciated. I have most of the texts but if someone knows of a text that talks about this, it would be helpful because I don't even know of the name for such a model ( if it exists ) so I don't know where to look. Thanks Google linear probablity model and you will find a lot of information. Hope this is helpful, Dan Daniel J. Nordlund Research and Data Analysis Washington State Department of Social and Health Services Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a repetition of simulation
Excuse me, but I think your code deserves some comments. Unfortunately, the history of postings is in reverse order, so I'll address your first question first: The simulation looks like this: z - 0 x - 0 y - 0 aps - 0 tiss - 0 for (i in 1:500){ z[i] - rbinom(1, 1, .6) x[i] - rbinom(1, 1, .95) y[i] - z[i]*x[i] If I'm getting this correctly, you don't need z and x later on? Then y - rbinom(500, 1, .6*.95) should do the trick. if (y[i]==1) aps[i] - rnorm(1,mean=13.4, sd=7.09) else aps[i] - rnorm(1,mean=12.67, sd=6.82) if (y[i]==1) tiss[i] - rnorm(1,mean=20.731,sd=9.751) else tiss[i] - rnorm(1,mean=18.531,sd=9.499) tiss - ifelse(y, rnorm(500, mean=20.731, sd=9.751), rnorm(500, mean=18.531, sd=9.499)) Likewise for aps. } v - data.frame(y, aps, tiss) log_v - glm(y~., family=binomial, data=v) summary(log_v) Makes me wonder what you need aps and tiss for. Let's assume for a moment that they are the coefficients. I do not see the necessity to put everything into a data frame, so log_v - glm(y ~ aps+tiss, family=binomial) should be sufficient and summary(log_v)$coefficients[,Pr(|z|)] extracts the p value. how can I see all the P.Values (Pr(|z|)) of the covariates from the 1000 iterations? I tried names(log_v) and couldn'n find it. Try str(summary(log_v)) and you see the whole structure. -- Johannes H�sing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:[EMAIL PROTECTED] from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, Life on the Mississippi) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a repetition of simulation
summary(log_v) Julian sigalit mangut-leiba wrote: Hello, In addition to my question a few days ago, Now I have a matrix of the coefficients, how can I see all the P.Values (Pr(|z|)) of the covariates from the 1000 iterations? I tried names(log_v) and couldn'n find it. Thank you, Sigalit. On 11/13/07, Julian Burgos [EMAIL PROTECTED] wrote: Well, the obvious (but perhaps not the most elegant) solution is put everything in a loop and run it 600 times. coefficients=matrix(NA,ncol=3,nrow=600) for (loop in 1:600){ [all your code here] coefficients[loop,]=coef(log_v) } That will give you a matrix with the coefficients of each model run in each row. Julian sigalit mangut-leiba wrote: I want to repeat the simulation 600 times and to get a vector of 600 coefficients for every covariate: aps and tiss. Sigalit. On 11/13/07, Julian Burgos [EMAIL PROTECTED] wrote: And what is your question? Julian sigalit mangut-leiba wrote: Hello, I have a simple (?) simulation problem. I'm doing a simulation with logistic model and I want to reapet it 600 times. The simulation looks like this: z - 0 x - 0 y - 0 aps - 0 tiss - 0 for (i in 1:500){ z[i] - rbinom(1, 1, .6) x[i] - rbinom(1, 1, .95) y[i] - z[i]*x[i] if (y[i]==1) aps[i] - rnorm(1,mean=13.4, sd=7.09) else aps[i] - rnorm(1,mean=12.67, sd=6.82) if (y[i]==1) tiss[i] - rnorm(1,mean=20.731,sd=9.751) else tiss[i] - rnorm(1,mean=18.531,sd=9.499) } v - data.frame(y, aps, tiss) log_v - glm(y~., family=binomial, data=v) summary(log_v) I want to do a repetition of this 600 times (I want to have 600 logistic models), and see all the coefficients of the covariates aps tiss. Thanks in advance, Sigalit. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to extract the elements of a list of vectors in a fixedposition?
[snip] or (I can't resist) unlist(lapply(v,function(x,i){x[i]},i=2)) # For more flexibility. Well, if we are not resisting the fun ones then try: sapply( v, `[`, i=2) -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 __ 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] Writing a helper function that takes in the dataframe and variable names and then does a subset and plot
Hi, I have a large dataframe than I'm writing functions to explore, and to reduce cut and paste I'm trying to write a function that does a subset and then a plot. Firstly, I can write a wrapper around a plot: plotwithfits - function(formula, data, xylabels=c('','')) { xyplot(formula, data, panel = function(x,y, ...) { panel.xyplot(x,y, ...) panel.abline(lm(y~x),lwd=2, ...) panel.loess(x,y,lwd=2,col.line='red', ...) }, xlab = xylabels[1], ylab= xylabels[2]) } plotwithfits(Latency ~ Stimulus.number | Subject.ID,eye_subsetted_data) # Works However, I can't get it working if I try the same for a subset and plot: explorebysubject - function(xvar,yvar,data,condition=TRUE,xlim=c(-Inf,Inf),ylim=c(-Inf,Inf)) { temp_subset - subset(data, subset=conditionxvarxlim[1]xvarxlim[2]yvarylim[1]yvarylim[2], select=c(Group,Subject.ID,xvar,yvar) ) plotwithfits(xvar~yvar | Subject.ID,temp_subset) } explorebysubject(Latency,Primary.gain,eye,Analysis.type == 'reflexive') # Doesn't work as can't find 'Analysis.type', 'Latency', etc I can see why it doesn't work, however, I've looked at substitute, deparse, etc, without much luck. Is there a something simple I could do to fix this up? Is there any material I should be reading? Using the arguments eye$Latency, eye$Primary.gain, etc would partially solve this problem, however I would prefer to avoid this if possible. One unclean way that does work is constructing strings and then evaluating them. However, as I am planning to write several similar functions I would prefer to avoid this: explorebysubject - function(xvar,yvar,dataset,condition,xlim=c(-Inf,Inf),ylim=c(-Inf,Inf)) { # xvar - variable to plot along x-axis # yvar - variable to plot along y-axis # the dataset to use # condition - used to provide extra conditions on the data selected # xlim, ylim - optional limits of data to select. i.e. xlim=c(0,1) # Generate command to select appropriate data cmd - paste(subset(,dataset,,,condition,,xvar,,xlim[1],,xvar,,xlim[2],,yvar,,ylim[1],,yvar,,ylim[2],,select=c(,xvar,,,yvar,,Group,Subject.ID))) temp_subset - eval(parse(text=cmd)) #generate plot command cmd - paste(plotwithfits(,xvar,~,yvar,|Subject.ID,temp_subset)) eval(parse(text=cmd)) } explorebysubject('Latency','Primary.gain','eye',Analysis.type == 'reflexive',xlim=c(90,500),ylim=c(0.5,1.5)) # Works Thanks. Cheers, Daniel __ 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] problem with png()
Dear Brian, sorry, library(lattice) is loaded, when I start R, so I forgot to add this. I get Ingo's title if I plot directly to the screen. However, I do not get it if I use png() or I lose it if I save from the plot (screen). Ingo On 15 Nov 2007 at 10:30, Prof Brian Ripley wrote: Works for me when I add the library(lattice) you omitted Since effectively all png() is doing is copying the screen, the problem is unlikely to be in png(). Most such problems are when there is not enough space to include labels, and you need to adjust margins or pointsize. On Thu, 15 Nov 2007, Ingo Holz wrote: Hi, I am runing R2.6.0 (2007-10-03) on WindowsXP. If I use png() to save a plot I lose the main title. An example: ## outfile - outfile.png p11 - histogram( ~ height | voice.part, data = singer, xlab=Height, main=Ingo's title) p2 - histogram( ~ height, data = singer, xlab = Height) png(outfile, width=800, height=800) print(p11, split=c(1,1,1,2), more=TRUE) print(p2, split=c(1,2,1,2)) dev.off() In my outfile.png I do not see Ingo's title. I know that it is not possible to reproduce this error on LINUX. It seems not possible on Windows, either. Thank you for your help. Ingo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] HELP: How to subtract a vector out of each row of a matrix or array
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Zhu Sent: Thursday, November 15, 2007 10:45 AM To: r-help@r-project.org Subject: [R] HELP: How to subtract a vector out of each row of a matrix or array Hi All, I am having great trouble doing something pretty simple. Here is what I did: x - read.table(clipboard) dim (x) [1] 126 10 typeof(x) [1] list w - array(x) typeof(w) list Q1: How come after constructing an array out of the list, the type of the array is still list? w - as.array(x) Error in `dimnames-.data.frame`(`*tmp*`, value = list(c(V1, V2, V3, : invalid 'dimnames' given for data frame Q2: How do I covnert a two dimensional list to an array then? y-as.matrix(x) dim(y) [1] 126 10 Finally, this works. m-colMeans(y) m V1 V2 V3 V4 V5 V6 0.098965679 0.075252330 0.046776996 0.021706852 0.005319685 0.003453889 V7 V8 V9 V10 0.037819506 0.021107303 0.039035427 0.002694224 Get the mean of each column. Q3: Now the big question. I want to substract V1 from each element of column 1, V2 from each element of column 2, ... How do I do this? I ended up doing this, which is highly inefficient. z- t(t(y)-m) Geoffrey, How about x - apply(y,1,'-',m) Hope this is helpful, Dan Daniel J. Nordlund Research and Data Analysis Washington State Department of Social and Health Services Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a repetition of simulation
Thank you for all your comments, Sigalit. On 11/15/07, Johannes Hüsing [EMAIL PROTECTED] wrote: Excuse me, but I think your code deserves some comments. Unfortunately, the history of postings is in reverse order, so I'll address your first question first: The simulation looks like this: z - 0 x - 0 y - 0 aps - 0 tiss - 0 for (i in 1:500){ z[i] - rbinom(1, 1, .6) x[i] - rbinom(1, 1, .95) y[i] - z[i]*x[i] If I'm getting this correctly, you don't need z and x later on? Then y - rbinom(500, 1, .6*.95) should do the trick. if (y[i]==1) aps[i] - rnorm(1,mean=13.4, sd=7.09) else aps[i] - rnorm(1,mean=12.67, sd=6.82) if (y[i]==1) tiss[i] - rnorm(1,mean=20.731,sd=9.751) else tiss[i] - rnorm(1,mean=18.531,sd=9.499) tiss - ifelse(y, rnorm(500, mean=20.731, sd=9.751), rnorm(500, mean= 18.531, sd=9.499)) Likewise for aps. } v - data.frame(y, aps, tiss) log_v - glm(y~., family=binomial, data=v) summary(log_v) Makes me wonder what you need aps and tiss for. Let's assume for a moment that they are the coefficients. I do not see the necessity to put everything into a data frame, so log_v - glm(y ~ aps+tiss, family=binomial) should be sufficient and summary(log_v)$coefficients[,Pr(|z|)] extracts the p value. how can I see all the P.Values (Pr(|z|)) of the covariates from the 1000 iterations? I tried names(log_v) and couldn'n find it. Try str(summary(log_v)) and you see the whole structure. -- Johannes Hüsing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:[EMAIL PROTECTED] from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, Life on the Mississippi) [[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] Graphics device storable in a variable
I'm using R embedded in PostgreSQL (via PL/R), and would like to use it to create images. It works fine, except that I have to create every image in a file (owned by and only readable by the PostgreSQL server), and then use PostgreSQL to read from that file and return it to the client. It would be much nicer if I could plot images into an R variable (for instance, a matrix), and return that variable through the PostgreSQL client. Leaving aside the details of returning the data to PostgreSQL (which I realize are beyond the scope of this list), I envision R code along the lines of the following: # Create a png device, a handle to which is stored in myDevice myDevice - png.variable(height = 1280, width = 1024, bg = white) # Plot some data into the current device plot(myX, myY, col=red) # Finalize dev.off() # Print out the contents of myDevice myDevice ...and the data would print out just like any other matrix or class or whatever type myDevice actually is. So my question is does such a thing already exist? I know about piximage, but apparently I have to load image data from somewhere for it to work; I can't use plot(), etc. to create the piximage data. GDD would be a nice way to do it, because GD libraries are widely available for use with other languages I might use with PostgreSQL and PL/R (for instance, Perl would talk to PostgreSQL, call a PL/R function to use R to return an image, which Perl would then process further), but GDD requires temporary files as well, as far as I can see. Thanks for any help anyone can offer. -Josh / eggyknap __ 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] where is library file
Thanks Brian. I installed libf2c for the x86_64 server, and then R and Bioconductor both installed without error, so apparently it was missing the library files. Back in business. Richard Casey, PhD Rocky Mountain Regional Center of Excellence for Biodefense CSU Center for Bioinformatics Colorado State University Ft. Collins, CO 80523 Ph: 970-491-8568 Cell: 970-980-5975 Email: [EMAIL PROTECTED] RMRCE: www.cvmbs.colostate.edu/mip/rmrce CBC: www.bioinformatics.colostate.edu -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Wednesday, November 14, 2007 2:02 PM To: Casey,Richard Cc: r-help@r-project.org Subject: Re: [R] where is library file On Wed, 14 Nov 2007, Casey,Richard wrote: While trying to install R on 64-bit HP Proliant and RedHat Enterprise Linux v.4 using R-2.6.0-3.rh4.x86_64.rpm, it says: Failed dependencies: libg2c.so.0()(64bit) is needed by R Does anyone know where to get libg2c.so or the rpm to install it? libg2c is the runtime library for g77, the fortran compiler for gcc 3.x. Loooking at the R spec file, this is likely to be in gcc-g77 (or a dependency of that), and that is a dependency of the R-devel RPM. Have you tried installing the latter: you will need it to install packages later? Googling got me to http://www.redhat.com/archives/nahant-list/2007-April/msg00049.html which suggests that you need the libf2c RPM on RHEL4. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RMySQL installation problem
On Thu, 15 Nov 2007, Tao Shi wrote: Hi List, I'm running R2.5.1 on WinXP. Downloaded RMySQL_0.6-0.zip from http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.6/ and the installation seemed fine. However, when I tried to load the package, the error occured: utils:::menuInstallLocal() package 'RMySQL' successfully unpacked and MD5 sums checked updating HTML package descriptions library(RMySQL) Loading required package: DBI Error in dyn.load(x, as.logical(local), as.logical(now)) : unable to load shared library 'C:/PROGRA~1/R/R-25~1.1/library/RMySQL/libs/RMySQL.dll': LoadLibrary failure: The specified module could not be found. Error: package/namespace load failed for 'RMySQL' ## However, I can see the .dll file is there from window's explorer!! The 'specified module' was specified in the popup! (Windows' users should be used to the arcaneness of the error messages.) Assuming you actually have MySQL installed, you need to make sure libmysql.dll is on the PATH. It's in the mysql\bin directory, so installing MySQL would normally put it on the PATH. There was also a pop windows says: R Console: Rgui.exe-Unable To Locate Component This application has failed to start because LIBMYSQL.dll was not found. Re-installing the application may fix the problem. I tried the re-installation. It didn't work. The DBI package I have is version 0.2-4, just in case. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems working with large data
A little more information might be useful. If your matrix is numeric, then a single copy will require about 250MB of memory. What type of system are you on and how much memory do you have? When you say you are having problems, what are they? Is it a problem reading the data in? Are you getting allocation errors? Is your system paging? If you have 2GB of memory, you should be fine depending on how many copies of the data you have. On Nov 15, 2007 10:53 AM, [EMAIL PROTECTED] wrote: Hi, I'm working with a numeric matrix with 55columns and 581012 rows and I'm having problems in allocation of memory using some of the functions in R: for example lda, rda (library MASS), princomp(package mva) and mvnorm.etest (energy package). I've read tips to use less memory in help(read.table) and managed to use some of this functions, but haven't been able to work with mvnorm.etest. I would like to know the better way to solve this problem, as well as doing it faster. Best regards, Pedro Marques __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ 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] homogenity inside groups
Dear all I would like to show my audience that some variables are homogenous inside groups but different outside. I can use by with summary for all variables by(iris[,1:4], iris$Species, summary) what can be quite messy in case of more than few variables and about 8 groups or densityplot for one variable densityplot(~Petal.Length | Species, iris) I have two questions: 1. Is there any other plot to show all variables at once? Something like densityplot(~iris[,1:4] | Species, iris) 2. Is it possible to evaluate homogenity of many (20-30) variables inside groups by some other function/table/graph? Thank you Petr Pikal [EMAIL PROTECTED] __ 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] Graphics device storable in a variable
This is possible using the cairoDevice package and RGtk2. Turning an R graphic into a raw vector of bytes: library(cairoDevice) library(RGtk2) # create a pixmap and tell cairoDevice to draw to it pixmap - gdkPixmapNew(w=500, h=500, depth=24) asCairoDevice(pixmap) # make a dummy plot plot(1:10) # convert the pixmap to a pixbuf plot_pixbuf - gdkPixbufGetFromDrawable(NULL, pixmap, pixmap$getColormap(), 0, 0, 0, 0, 500, 500) # save the pixbuf to a raw vector buffer - gdkPixbufSaveToBufferv(plot_pixbuf, jpeg, character(0), character(0))$buffer ### Then you can send buffer to your database, or whatever. Replacing jpeg with png will probably produce png output. Michael On Nov 15, 2007 3:32 PM, Greg Snow [EMAIL PROTECTED] wrote: You might try looking at the tkrplot package, it uses win.metafile and captures the graphics device into a variable (which is then put into a tk lable, but you could probably do something else with it). -- 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 Josh Tolley Sent: Thursday, November 15, 2007 2:08 PM To: r-help@r-project.org Subject: [R] Graphics device storable in a variable I'm using R embedded in PostgreSQL (via PL/R), and would like to use it to create images. It works fine, except that I have to create every image in a file (owned by and only readable by the PostgreSQL server), and then use PostgreSQL to read from that file and return it to the client. It would be much nicer if I could plot images into an R variable (for instance, a matrix), and return that variable through the PostgreSQL client. Leaving aside the details of returning the data to PostgreSQL (which I realize are beyond the scope of this list), I envision R code along the lines of the following: # Create a png device, a handle to which is stored in myDevice myDevice - png.variable(height = 1280, width = 1024, bg = white) # Plot some data into the current device plot(myX, myY, col=red) # Finalize dev.off() # Print out the contents of myDevice myDevice ...and the data would print out just like any other matrix or class or whatever type myDevice actually is. So my question is does such a thing already exist? I know about piximage, but apparently I have to load image data from somewhere for it to work; I can't use plot(), etc. to create the piximage data. GDD would be a nice way to do it, because GD libraries are widely available for use with other languages I might use with PostgreSQL and PL/R (for instance, Perl would talk to PostgreSQL, call a PL/R function to use R to return an image, which Perl would then process further), but GDD requires temporary files as well, as far as I can see. Thanks for any help anyone can offer. -Josh / eggyknap __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to deal with character(0)?
I want to identify whether a variable is character(0), but get lost. For example, if I have dd-character(0) the following doesn't seem to serve as a good identifier: dd==character(0) logical(0) So how to detect character(0)? Thanks, Gang __ 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 deal with character(0)?
is.character(dd) length(dd) == 0 should do it i think. Gabor On Thu, Nov 15, 2007 at 04:54:45PM -0500, Gang Chen wrote: I want to identify whether a variable is character(0), but get lost. For example, if I have dd-character(0) the following doesn't seem to serve as a good identifier: dd==character(0) logical(0) So how to detect character(0)? Thanks, Gang __ 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. -- Csardi Gabor [EMAIL PROTECTED]MTA RMKI, ELTE TTK __ 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] Romoving elements from a vector. Looking for the opposite of c(), New user
Try this. xx and zz are the same as x and z except they have a sequence number appended. We then do a setdiff and remove the sequence numbers. xx - paste(x, seq(x) - match(x, x)) zz - paste(z, seq(z) - match(z, z)) dd - setdiff(xx, zz) as.numeric(sub( .*, , dd)) [1] 3 4 4 6 7 8 8 9 On Nov 15, 2007 11:09 AM, Thomas Frööjd [EMAIL PROTECTED] wrote: Not sure i explained it good enough. Ill try with an example say x=[3,3,4,4,4,4,5,5,6,8] z=[3,4,4,5,5] what i want to get after removing z from x is something like x=[3,4,4,6,8] On Nov 15, 2007 3:29 PM, Charilaos Skiadas [EMAIL PROTECTED] wrote: On Nov 15, 2007, at 9:15 AM, Thomas Frööjd wrote: Hi I have three vectors say x, y, z. One of them, x contains observations on a variable. To x I want to append all observations from y and remove all from z. For appending c() is easily used x - c(x,y) But how do I remove all observations in z from x? You can say I am looking for the opposite of c(). If you are looking for the opposite of c, provided you want to remove the first part of things, then perhaps this would work: z-c(x,y) z[-(1:length(x))] However, if you wanted to remove all appearances of elements of x from c(x,y), regardless of whether those elements appear in the x part of in the y part, I think you would want: z[!z %in% x] Probably there are other ways. Welcome to R! Best regards Haris Skiadas Department of Mathematics and Computer Science Hanover College __ 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] Graphics device storable in a variable
Just an couple of ideas that might or might not work ... Josh Tolley a écrit : I'm using R embedded in PostgreSQL (via PL/R), and would like to use it to create images. It works fine, except that I have to create every image in a file (owned by and only readable by the PostgreSQL server), and then use PostgreSQL to read from that file and return it to the client. It would be much nicer if I could plot images into an R variable (for instance, a matrix), and return that variable through the PostgreSQL client. Leaving aside the details of returning the data to PostgreSQL (which I realize are beyond the scope of this list), I envision R code along the lines of the following: # Create a png device, a handle to which is stored in myDevice myDevice - png.variable(height = 1280, width = 1024, bg = white) # Plot some data into the current device plot(myX, myY, col=red) # Finalize dev.off() # Print out the contents of myDevice myDevice ...and the data would print out just like any other matrix or class or whatever type myDevice actually is. So my question is does such a thing already exist? I know about piximage, but apparently I have to load image data from somewhere for it to work; I can't use plot(), etc. to create the piximage data. GDD would be a nice way to do it, because GD libraries are widely available for use with other languages I might use with PostgreSQL and PL/R (for instance, Perl would talk to PostgreSQL, call a PL/R function to use R to return an image, which Perl would then process further), but GDD requires temporary files as well, as far as I can see. Thanks for any help anyone can offer. The documentation for the png device mentions a filename argument. That might be a temporary file that another process (or a R or plpgsql function, btw) could read and store in the correct Postgres table. The package odfWeave uses something like this to insert graphs in an Open Document file. # What follows might work on unix and unix-alikes, possibly on Mac OS X # (BSD-like). I do not know about Windows... Furthermore, the png device doc cross-references the postcript device for details ; this latter doc mentions that a filename of the form |cmd will effectively pipe device output to cmd, which is a possibility that avoids file creation (but may well be as slow as with temporary file creation, since one would have to go to the filesystem to create a new process for cmd...). Furthermore, you'd have to pass additional arguments to cmd (some reference for the graph, where is it to be stored, and so on...). I do not know if the | cmd syntax would pass additional arguments to cmd... However, I wonder if the png device supports the |cmd syntax. It *should*, but I've never tried that... A third possibility would be to write to a named pipe whose output is consumed by a process storing data in the relevant table . This process should be somehow controlled (passing an identifier, telling it what to store and when, etc...), possibly from *another* named pipe A fourth possibility would be to force the output (of plot and such) to stdout and capture stdout with capture.output (package utils). However, I have no idea on how to do that (from the outside, it seems theoretically possible, but one might need special hooks in the interpreter... Of all those possibilities, the first one seems reasonable, easy to implement, but has the drawback of using temporary files, which might be a resource hog. The second possibility is also a probable resource hog. The third might be much more economical (a daemon might be set up with its input and control pipes once for good), but might be difficult to set up in pl/r (does this implementatin allows I/O from/to external files ?). The fourth is much more problematic... HTH Emmanuel Charpentier __ 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] Romoving elements from a vector. Looking for the opposite of c(), New user
I think you've read Thomas's request in reverse. and what he want is: x[!x %in% z] Thanks for the %in% approach BTW. --- Charilaos Skiadas [EMAIL PROTECTED] wrote: On Nov 15, 2007, at 9:15 AM, Thomas Fr��jd wrote: Hi I have three vectors say x, y, z. One of them, x contains observations on a variable. To x I want to append all observations from y and remove all from z. For appending c() is easily used x - c(x,y) But how do I remove all observations in z from x? You can say I am looking for the opposite of c(). If you are looking for the opposite of c, provided you want to remove the first part of things, then perhaps this would work: z-c(x,y) z[-(1:length(x))] However, if you wanted to remove all appearances of elements of x from c(x,y), regardless of whether those elements appear in the x part of in the y part, I think you would want: z[!z %in% x] Probably there are other ways. Welcome to R! Best regards Haris Skiadas Department of Mathematics and Computer Science Hanover College __ 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] generate combination set
On Thursday 15 November 2007, [EMAIL PROTECTED] wrote: Actually, (now that I know about combn), a better way is t(matrix(set[combn(7,2)], nrow = 2)) Indeed, or to avoid transposing: matrix(set[combn(7,2)], ncol = 2, byrow=T) Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd 050025 Bucharest sector 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ 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] Ancova doesn't return test statistics
Your model is fully saturated. It specifies terms that use up all degrees of freedom. There are no degrees of freedom left over for a Residual term and therefore there is no denominator for the tests. When you drop one term, then those degrees of freedom are left over, that is they form the Residual, and are used as the denominator for the tests. The usual practice is to suppress the high-order interactions, in your example by model - aov(GR ~ SR*HS*Pop*Popsize*Year - SR:HS:Pop:Popsize:Year) Please use spaces around the arrow, tilde, and + and - signs for legibility. Rich __ 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] Normalizing data
Maybe Joren means that the y axis has values greater than 1? If that is the case, that is certainly not evidence of any problem; the density can have values larger than 1 and still integrate to 1. (And, just as a silly example, try dnorm(0, mean = 0, sd = 0.1)). Best, R. On Nov 15, 2007 11:05 PM, jim holtman [EMAIL PROTECTED] wrote: I am not sure what you mean when you say it does not integrate to 1. Here are a couple of cases, and it seems fine to me: x - density(1:30) str(x) List of 7 $ x: num [1:512] -11.0 -10.9 -10.8 -10.7 -10.6 ... $ y: num [1:512] 6.66e-05 7.22e-05 7.84e-05 8.49e-05 9.20e-05 ... $ bw : num 4.01 $ n: int 30 $ call : language density.default(x = 1:30) $ data.name: chr 1:30 $ has.na : logi FALSE - attr(*, class)= chr density plot(x) sum(diff(x$x) * (head(x$y,-1) + tail(x$y,-1))/2) # integrate [1] 1.000823 x - density(rnorm(1000)) sum(diff(x$x) * (head(x$y,-1) + tail(x$y,-1))/2) # integrate [1] 1.000974 On Nov 15, 2007 2:47 PM, Joren Heit [EMAIL PROTECTED] wrote: Hello, I have a data set of about 300.000 measurements made by an STM which should apporximately fix a normal (Gaussian) distribution. I have imported the data in R and used plot(density()) to get a nice plot of the distribution which in fact looks like a real Gaussian. However, the integral over the surface is not equal to one (I know since some of the plots extend to numbers greater then 1). Is there a way to normalize the data so the density function will actualy yield the probability of x (a height in my case)? This is my code so far: #Input path path - G:\\C\\Data txt\\1au300.txt #Dataverwerking data - read.table(path, header=TRUE) rows - length(data$height) height - data$height[1:rows] dens -density(height) mean - mean(height) sd - sd(height) min - min(hnorm) max - max(hnorm) #Plot par(new=FALSE) curve(dnorm(x,m=mean,sd=sd),from=min,to=max, xlab=, ylab=, col=white, lwd=2) points(dens, type=h, col=grey ) par(new=TRUE) curve(dnorm(x,m=mean,sd=sd),from=min,to=max, xlab=Height (nm), ylab=Density, lwd=2, col=darkred) Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ 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. -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz __ 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: How to subtract a vector out of each row of a matrix or array
Hi All, I am having great trouble doing something pretty simple. Here is what I did: x - read.table(clipboard) dim (x) [1] 126 10 typeof(x) [1] list w - array(x) typeof(w) list Q1: How come after constructing an array out of the list, the type of the array is still list? w - as.array(x) Error in `dimnames-.data.frame`(`*tmp*`, value = list(c(V1, V2, V3, : invalid 'dimnames' given for data frame Q2: How do I covnert a two dimensional list to an array then? y-as.matrix(x) dim(y) [1] 126 10 Finally, this works. m-colMeans(y) m V1 V2 V3 V4 V5 V6 0.098965679 0.075252330 0.046776996 0.021706852 0.005319685 0.003453889 V7 V8 V9 V10 0.037819506 0.021107303 0.039035427 0.002694224 Get the mean of each column. Q3: Now the big question. I want to substract V1 from each element of column 1, V2 from each element of column 2, ... How do I do this? I ended up doing this, which is highly inefficient. z- t(t(y)-m) Thanks, Geoffrey __ 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] Ancova doesn't return test statistics
On Nov 15, 2007 4:36 PM, Johan A. Stenberg [EMAIL PROTECTED] wrote: Dear all, I'm quite sure that this is a stupid question, but I'll ask anyway. I want to perform an ANCOVA with two continuous factors and three categorical factors. Plant population growth rate (GR) = dependent variable Seed reduction due to herbivory (SR) = continuous explanatory variable Herbivore species (HS, 2 levels) = categorical explanatory variable Population (Pop, 24 levels) = categorical explanatory variable Population size (Popsize) = continuous explanatory variable Year (Year, 16 levels) = categorical explanatory variable My model is technically simple: model-aov(GR~SR*HS*Pop*Popsize*Year) However, R is not returning any F and P values – only Df, Sum Sq and Mean Sq. I have to remove either Year or Pop in order to get the test statistics. Why is this? Thank you in advance! Johan A. Stenberg, Umea University, Sweden Hi, How much data do you have? a model on the data with all interactions included ,as in your example, requires estimating well over 500 parameters. Even the largest data sets might be strained by this. Supposedly, that's why the aov doesn't give p-values. (though since you don't give a reproducible example, I can't be certain) I'd suggest reducing the number of interactions. I'm fairly certain that you don't want 4- or 5-way interactions for example-they tend to be hard to interpret. /Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik __ 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] R Help
Ya, I was wondering if anyone knows how to use R and can do some computing with it. I have a problem that involves implementing the EM Algorithm for censored normal data. So I was wondering if anyone knows how to code a problem involving the EM Algorithm in R, and then estimate the parameters, mean, standard deviation, and estimated variance covariance matrix for certain data given. If you do and can help me, please email me back and let me know and I can email you the entire problem with the data. Thanks so much, this would really help me out if you can help. Bryan Email: [EMAIL PROTECTED] - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to deal with character(0)?
On 11/15/2007 4:54 PM, Gang Chen wrote: I want to identify whether a variable is character(0), but get lost. For example, if I have dd-character(0) the following doesn't seem to serve as a good identifier: dd==character(0) logical(0) So how to detect character(0)? (length(dd) == 0) (typeof(dd) == character) or if you really want to be specific (and rule out things that just act like character(0) in most respects) identical(dd, character(0)) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sample nth day data in each month
On Nov 15, 2007 12:54 PM, Carles Fan [EMAIL PROTECTED] wrote: Dear all i have a time series containing trading dates and historical stock prices: Date Price 10-Jan-2007 100 11-Jan-2007 101 13-Jan-2007 99 .. .. .. 10-Nov-2007 200 i want to sample every 21st data of each month: 21-Jan-2007 101 21-Feb-2007 111 21-Mar-2007 131 .. .. .. 21-Oct-2007 140 1) how can i do that? 2) if some of the dates are non-trading day, how can i tell R to use modified following or following data? Using zoo, z is some test data. zz is only those points whose day of the month is 21 or more. In the last line we keep only the first point in each month in zz. library(zoo) z - zoo(101:200, as.Date(2000-01-01) + seq(0, len = 100, by = 2)) zz - z[as.numeric(format(time(z), %d)) = 21] zz[!duplicated(as.yearmon(time(zz)))] __ 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] syntax for a 3-level nlme model
I am writing to verify the syntax that I am using to test a 3-level model with a random intercept at the second level (participant in my model) versus a model with a random slope and intercept at this level. Specifically, I am testing a 3 level model in which time (WEEK) is nested in participants (PARTICIP) and participants are nested in dyads (DYADID). The goal is to examine how an interpersonal style (CORUMTO) one week predicts changes in depression the following week (BDIAFTER) controlling for levels of depression (BDI) from the previous week. I want to verify that the following syntax would be appropriate for modeling a random intercept and fixed slope at the participant level and a random slope and intercept at the participant level both-lme(BDIAFTER~BDI+WEEK+CORUMTO, random=list(DYADID=~1, PARTICIP=~CORUMTO), data=weeklydata) Also, when modeling a random slope and intercept at the participant level, I receive output, and I also receive the following error message Warning message Fewer observations than random effects in all level 2 groups I was wondering what this error message means and if it may be suggesting that the results after the summary statement are incorrect. I also want to verify that the following syntax is appropriate for modeling just a random intercept (and a fixed slope) at the dyad and participant levels intercept-lme(BDIAFTER~BDI+WEEK+CORUMTO, random=list(DYADID=~1, PARTICIP=~1), data=weeklydata) Any advice you can give would be much appreciated. Thank you for your time. Sincerely, Christine Calmes Christine Calmes, M.A. Doctoral Candidate, Clinical Psychology University at Buffalo: The State University at New York Department of Psychology; Park Hall North Campus Buffalo NY, 14260 __ 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] sample nth day data in each month
Carles Fan a écrit : Dear all i have a time series containing trading dates and historical stock prices: Date Price 10-Jan-2007 100 11-Jan-2007 101 13-Jan-2007 99 .. .. .. 10-Nov-2007 200 i want to sample every 21st data of each month: 21-Jan-2007 101 21-Feb-2007 111 21-Mar-2007 131 .. .. .. 21-Oct-2007 140 1) how can i do that? YourDataFrame[strptime(YourDataFrame$Date,%Y-%b-%d)$mday==21,] # beware your locale ! 2) if some of the dates are non-trading day, how can i tell R to use modified following or following data? Dunno : what is anon-trading day ? HTH Emmanuel Charpentier __ 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] map - mapproj : problem of states localisation
On Fri, 16 Nov 2007, Tom Minka wrote: I haven't seen the original code, but the problem with Ray's code is that the two projections are not synchronized. Specifically, they are using different (default) values for the orientation. To synchronize the projections, either specify the orientation parameter for both, or the second one should use proj=, as follows: map(france, proj=lambert, pa=c(30, 60)) map(world, proj=, lwd=1, col=red, add=TRUE) # reuse previous projection Tom Thanks for that, Tom. That does 'fix' the original code. So basically the response is RTFM :-). I had forgotten about that aspect of projections, since I don't use them myself. Regards, Ray __ 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] Multiply each column of array by vector component
On Thu, 2007-11-15 at 17:50 +, [EMAIL PROTECTED] wrote: Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij * v_j This seems so basic but I can't figure out how to do it without a loop. Any suggestions? Michal. If I understand you correctly: t(t(A) * v) set.seed(1) A - matrix(sample(20), ncol = 2) v - c(5, 2) A [,1] [,2] [1,]63 [2,]82 [3,] 11 20 [4,] 16 10 [5,]45 [6,] 147 [7,] 15 12 [8,]9 17 [9,] 19 18 [10,]1 13 t(t(A) * v) [,1] [,2] [1,] 306 [2,] 404 [3,] 55 40 [4,] 80 20 [5,] 20 10 [6,] 70 14 [7,] 75 24 [8,] 45 34 [9,] 95 36 [10,]5 26 HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help
On Wed, 14 Nov 2007, Nadine Mugusa wrote: Hi everyone, Can someone help me with root bisection algorithm? Nadine Well you really should read the posting guide because this is not a very informative enquiry. However if what you really want to do is find the root of an equation you should use the uniroot function which is far more efficient than bisection. See ?uniroot David Scott _ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: [EMAIL PROTECTED] Graduate Officer, Department of Statistics 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] Romoving elements from a vector. Looking for the oppositeof c(), New user
Thomas Not sure i explained it good enough. Ill try with an example say x=[3,3,4,4,4,4,5,5,6,8] z=[3,4,4,5,5] what i want to get after removing z from x is something like x=[3,4,4,6,8] This will work, but I imagine there are better ways (assuming z is always a subset of x): z - c(3,4,4,5,5) x - c(3,3,4,4,4,4,5,5,6,8) tempTab - merge(table(x), table(z), by='row.names', all=T) tempTab[is.na(tempTab[,5]),5] - 0 rep(as.numeric(tempTab[,1]), tempTab[,3]-tempTab[,5]) Peter Alspach __ 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 these matrices going backwards
Sorry, I wasn't sure what you meant. This way will return more than one answer, right? N-c(1,2,1,3) R-c(1.75,3.5,1.75,1.3125) ## get all 126 combinations of five 0's and four 1's for matrix cbn-as.matrix(expand.grid( rep( list(0:1), 9))) cbn- cbn[rowSums(cbn)==4,] ans-list() ctr-0 ## loop through each combination for (i in 1:126){ x-cbn[i,] ## replace 1's with N x[which(x==1)]-N ## create matrix dim(x)-c(3,3) ## calculate y and new R y -sum(x) * x / (rowSums(x)%o%colSums(x)) R1-y[y[1:3,]0] # check if equal to original R if(identical(R, R1)) ans[[ctr-ctr+1]]-x } ans [[1]] [,1] [,2] [,3] [1,]001 [2,]103 [3,]020 [[2]] [,1] [,2] [,3] [1,]001 [2,]020 [3,]103 [[3]] [,1] [,2] [,3] [1,]020 [2,]001 [3,]103 Chris francogrex wrote: Hi, thanks but the way you are doing it is to assign the values of N in the x matrix, knowing from the example I have given where they are supposed to be. While the assumption is, you ONLY have values of N and R and do NOT know where they would be placed in the x and y matrix a-priori, but their position has to be derived from only the (N and R) dataframe you have. -- View this message in context: http://www.nabble.com/Generating-these-matrices-going-backwards-tf4807447.html#a13782676 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] counting strings of identical values in a matrix
On Thu, 2007-11-15 at 17:53 +0100, A M Lavezzi wrote: thank you. I did not think about the case of overlapping of 1's from the end of one column to the start of the next, this would actually be a problem In the simulations I am running each column corresponds to the path followed by an agent across states of a stochastic process, so I would like to avoid mixing up two different paths (I made a mistake when I mentioned the possibility of turning my matrix into a vector, sorry about that). can I kindly ask again your help on this? please excuse me. Mario snip Not a problem. After sending my follow up, I suspected that you might need a more general approach. This sort of ends up being a combination of the first two, in order to keep each column sequence intact: res - do.call(cbind, apply(prova, 2, function(x) do.call(rbind, rle(x res [3,] [5,] [7,] [4,] [7,] [4,] [8,] [2,] [3,] lengths222 233 234 111 6 values 313 131 331 331 3 table(res[lengths, res[values, ] == 1]) 1 2 3 4 1 2 1 1 I think that should do it, but you might want to test it on a known set of data. HTH, Marc __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to extract the elements of a list of vectors in a fixedposition?
On 16/11/2007, at 9:44 AM, Greg Snow wrote: [snip] or (I can't resist) unlist(lapply(v,function(x,i){x[i]},i=2)) # For more flexibility. Well, if we are not resisting the fun ones then try: sapply( v, `[`, i=2) Admittedly *much* cooler than my somewhat kludgy effort. cheers, Rolf ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot problem
Hi Allen, Its difficult to know what is the problem without knowing what type of object is 'Disease.FL'. plot() is a generic function and it will act differently depending on the type of object you are passing to it. As always, you should provide 'provide commented, minimal, self-contained, reproducible code' so we can find the problem. As a general comment, you can do any number of plots on a device (a window or a pdf file). The limit is only given by the number and size of the plots and the size of the device. Julian affy snp wrote: Dear list, I have a question about using plot(). I tried the code: pdf(mel_chr_all_13cancer_cghFLasso_all.pdf, height=6, width=11);plot( Disease.FL, index=1:4, type=All);dev.off(); and it went through well which outputed 4 plots for 4 samples in one page. But if I increase the numbers of plots(samples) which I want, saying to 11, pdf(mel_chr_all_13cancer_cghFLasso_all.pdf, height=6, width=11);plot( Disease.FL, index=1:11, type=All);dev.off(); then I got an error message as: Error in segments((1:n)[y 0], jp, (1:n)[y 0], jp + y[y 0], col = downcol) :invalid first argument I suspect that it has sth to do with the maxium plots which can be outputed on one page, which means less or equal to 4 will be fine but beyond that there will be a problem. I have tried the number 5 yet. Is there a way that I could specify that the plots can be put on multiple pages with 4 plots per one. Thank you very much for your help! Best, Allen [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multiply each column of array by vector component
?sweep -- 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 [EMAIL PROTECTED] Sent: Thursday, November 15, 2007 10:50 AM To: r-help@r-project.org Subject: [R] Multiply each column of array by vector component Hi, I've got an array, say with i,jth entry = A_ij, and a vector, say with jth entry= v_j. I would like to multiply each column of the array by the corresponding vector component, i,e. find the array with i,jth entry A_ij * v_j This seems so basic but I can't figure out how to do it without a loop. Any suggestions? Michal. __ 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.