Re: [R] Problem with package development
On Wed, 1 Jun 2011, Nipesh Bajaj wrote: I have been struggling for last one hour but not yet any through. However again I recreate the package.skeleton and run R CMD check trial3 Here are the errors: warning in dir.create(pkgoutdir, mode = 0755): cannot create dir 'c:\Program files\R\R-2.13.0\bin\trial3.Rcheck', reason . Error in printLog(Log, , text, \n): object 'Log' not found Execution haulted Why I am getting this error? what is that Log. I will really appreciate if somebody please help me to figure out. R CMD check writes a (in your case) trial3.Rcheck directory, and in there in file 00check.log a copy of the log. If it cannot create trial3.Rcheck it cannot write the log. I would be surprised that even on Windows Vista the message was literally reason . but if it was, blame Microsoft for their error messages. But cannot create dir 'c:\Program files\R\R-2.13.0\bin\trial3.Rcheck', is clear enough. You need to run 'R CMD check' in your user area. In case you did this because that is where you though 'R' was, it is not the correct R.exe. You may need to add c:\Program Files\R\R-2.13.0\bin\i386 (assuming 32-bit R) to your path. However, your use of e.g. 'Program files' suggests you are not accurately transmitting the messages you got. Thanks, On Wed, Jun 1, 2011 at 1:20 AM, Nipesh Bajaj bajaj141...@gmail.com wrote: Actually partly I followed. Here is the more details what I have done so far: 1. Edit the help file skeletons in 'man', possibly combining help files for multiple functions. I have modified with following: \name{fn1} \alias{fn1} \title{ A function. } \description{ A function. } \usage{ A function. } \arguments{ A function. } \value{ A function. } \author{ \bold{Me} \cr \email{m...@me.com} } 2. Edit the exports in 'NAMESPACE', and add necessary imports. Actually I really do not know what I would do here. In the corresponding file, only exportPattern(^[[:alpha:]]+) is there. Therefore I put that unaltered. 3. Put any C/C++/Fortran code in 'src'. I do not have any such code 4. If you have compiled code, add a useDynLib() directive to 'NAMESPACE'. Again I do not know what to do, so ingored this step. 5. Run R CMD build to build the package tarball. * Run R CMD check to check the package tarball. I did not follow this step exactly. What I done is, put 'trial3' folder in R/R-2.13.0bin folder (after above modification), from the R-working folder. Then just run R CMD INSTALL trial3. However previously with this job, I could create package effectively. After updating R to the current version my problem starts. Those are not sufficient? Thanks, On Wed, Jun 1, 2011 at 1:09 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 11-05-31 3:36 PM, Nipesh Bajaj wrote: Dear all, I am having a strage problem while I was trying to build a package. Here is my package skeleton: fn1- Vectorize(function(x,y,z) { return(x + y +z) }, vectorize.args = c(x), SIMPLIFY = TRUE) package.skeleton(trial3,namespace = TRUE) Did you follow the instructions that package.skeleton printed? Duncan Murdoch However when I tun R CMD INSTALL trial3 in CMD, the execution stopped with following message: *** installing help indices ** building package indices... ** testing if install package can be loaded Error: unexpected symbol in tools:::test_load_package(.. Execution haulted ERROR: loading failed. I am using R 2.13.0 in Vista with latest Rtools installed. Can somebody guide me where I have done wrong? 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] different results from lme() and lmer()
Hello R-help, I'm studying an example in the R book. The data file is available from the link below.http://www.bio.ic.ac.uk/research/mjcraw/therbook/data/fertilizer.txt Could you explain Why the results from lme() and lmer() are different in the following case? In other examples, I can get the same results using the two functions, but not here... Thank you.Miya library(lme4)library(nlme)# object dat contains the data summary(lme(root~fertilizer,random=~week|plant,data=dat))Linear mixed-effects model fit by REML Data: dat AIC BIC logLik 171.0236 183.3863 -79.51181 Random effects: Formula: ~week | plant Structure: General positive-definite, Log-Cholesky parametrization StdDev Corr (Intercept) 2.8639832 (Intr)week 0.9369412 -0.999Residual 0.4966308 Fixed effects: root ~ fertilizer Value Std.Error DF t-value p-value(Intercept) 2.799710 0.1438367 48 19.464499 0e+00fertilizercontrol -1.039383 0.2034158 10 -5.109645 5e-04 Correlation: (Intr)fertilizercontrol -0.707 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -1.9928118 -0.6586834 -0.1004301 0.6949714 2.0225381 Number of Observations: 60Number of Groups: 12 lmer(root~fertilizer+(week|plant),data=dat)Linear mixed model fit by REML Formula: root ~ fertilizer + (week | plant) Data: dat AIC BIC logLik deviance REMLdev 174.4 187 -81.21 159.7 162.4Random effects: Groups Name Variance Std.Dev. Corr plant (Intercept) 4.1416e-18 2.0351e-09 week 8.7452e-01 9.3516e-01 0.000 Residual 2.2457e-01 4.7389e-01 Number of obs: 60, groups: plant, 12 Fixed effects: Estimate Std. Error t value(Intercept) -0.1847 0.2024 -0.913fertilizercontrol -0.7612 0.2862 -2.660 Correlation of Fixed Effects: (Intr)frtlzrcntrl -0.707 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] In a formula, what is the interaction of the intercept and a factor?
Try it for yourself: model.matrix(y ~ 1:group, data = dat) (Intercept) 11 ... Or to do 'interact 1+x with group' model.matrix(y ~ (1+x):group, data = dat) (Intercept) x:groupA x:groupB 1101 ... Note that you usually want to do '*' when you say 'interact with': model.matrix(y ~ (1+x)*group, data = dat) (Intercept) x groupB x:groupB 11 1 11 ... On Tue, 31 May 2011, Kevin Wright wrote: For a pedagogical purpose, I was trying to show how the formula for a simple regression line (~1+x) could be crossed with a factor (~1:group + x:group) to fit separate regressions by group. For example: set.seed(201108) dat - data.frame(x=1:15, y=1:15+rnorm(15), group = sample(c('A','B'), size=15, replace=TRUE)) m1 - lm(y~ 1 + x, data=dat) m2 - lm(y ~ group + x:group, data=dat) m3 - lm(y ~ 1:group + x:group, data=dat) m4 - lm(y ~ 1 + x:group, data=dat) The simple regression is model m1. The usual way to write the by-group regression is model m2. In model m3 was trying to be explicitly clear and interact 1+x with group. Looking only at the coefficients, it appears that model m3 is simplified to model m4. R coef(m3) (Intercept)groupA:xgroupB:x 0.3775140 0.9213835 0.9879690 R coef(m4) (Intercept)x:groupAx:groupB 0.3775140 0.9213835 0.9879690 I wonder if anyone can shed some light on what R is doing with the 1:group term. Kevin [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Zero-inflated regression models: predicting no 0s
On Tue, 31 May 2011, Jean-Simon Michaud wrote: Hi all, First post for me here, but I have been reading on the forum for almost two years now. Thanks to everyone who contributed btw! I have a dataset of 4000 observations of count of a mammal and I am trying to predict abundance from a inflated-zero model as there is quite a bit of zeros in the response variable. I have tried multiple options, but I might do something wrong as every time I look at the fitted values it do not comprise any 0. Yes, the fitted() method and also the default of the predict() method is to compute fitted _means_. And the mean of a count distribution will always be non-zero. Moreover, even when you round the fitted values to integers, this does _not_ lead to the most likely count. Consider the following simple examples: Probability density for a Poisson distribution with mean 0.8 R dpois(0:5, lambda = 0.8) [1] 0.449329 0.359463 0.143785 0.038343 0.007669 0.001227 i.e., zero is still the most likely outcome with a probability of 45% even though the mean is 0.8. And for negative binomial distributions, this can be even more extreme. The probability density for a geometric distribution (negative binomial with size = 1) and mean 2: R dnbinom(0:5, mu = 2, size = 1) [1] 0.3 0.2 0.14815 0.09877 0.06584 0.04390 i.e., despite the mean of 2, zero is still the most likely outcome. You can get the predicted probabilities for all observations via predict(hurdle1, type = prob) and predict(zip1A, type = prob), respectively. Given the results for your negative binomial hurdle model, I suspect that the zero-inflated Poisson fit will have a nonsatisfactory fit for the zeros, even though the predicted means of the two models are similar. See also the paper accompanying the count regression functions in pscl (not lpsc): http://www.jstatsoft.org/v27/i08/ Finally, a short comment on your model formula: hurdle(TOT ~ LC80 + LC231 + DEM, data = mydata_purge, ...) will be easier to read and less confusing (after all data = food does not appear to be used at all). hth, Z Here is what I tried so far: ## - hurdle from the package (lpsc) - ## hurdle1 = hurdle(formula = mydata_purge2$TOT ~ mydata_purge2$LC80 + mydata_purge2$LC231 + mydata_purge2$DEM, data = food, dist = negbin, zero.dist = binomial) summary(hurdle1) Call: hurdle(formula = mydata_purge2$TOT ~ mydata_purge2$LC80 + mydata_purge2$LC231 + mydata_purge2$DEM, data = food, dist = negbin, zero.dist = binomial) Pearson residuals: Min 1Q Median 3Q Max -1.0833 -0.7448 -0.2801 0.4296 6.7242 Count model coefficients (truncated negbin with log link): Estimate Std. Error z value Pr(|z|) (Intercept) 1.7841678 0.0923781 19.314 2e-16 *** mydata_purge2$LC80 -2.5929984 0.4184956 -6.196 5.79e-10 *** mydata_purge2$LC231 0.2154269 0.1171259 1.839 0.065875 . mydata_purge2$DEM0.0007708 0.0002064 3.735 0.000188 *** Log(theta) 0.3742602 0.0390319 9.589 2e-16 *** Zero hurdle model coefficients (binomial with logit link): Estimate Std. Error z value Pr(|z|) (Intercept) 0.0602347 0.2302370 0.262 0.793614 mydata_purge2$LC80 -3.0590108 0.8360020 -3.659 0.000253 *** mydata_purge2$LC231 1.7754441 0.3226731 5.502 3.75e-08 *** mydata_purge2$DEM0.0031943 0.0005307 6.020 1.75e-09 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Theta: count = 1.4539 Number of iterations in BFGS optimization: 12 Log-likelihood: -1.251e+04 on 9 Df ## - zeroinfl from the package (lpsc) - ## zip1A = zeroinfl(mydata_purge2$TOT ~ mydata_purge2$LC80 + mydata_purge2$LC231 + mydata_purge2$DEM, data = food) summary(zip1A) Call: zeroinfl(formula = mydata_purge2$TOT ~ mydata_purge2$LC80 + mydata_purge2$LC231 + mydata_purge2$DEM, data = food) Pearson residuals: Min 1Q Median 3Q Max -2.2128 -1.2886 -0.5010 0.7594 11.8458 Count model coefficients (poisson with log link): Estimate Std. Error z value Pr(|z|) (Intercept) 1.894e+00 3.547e-02 53.401 2e-16 *** mydata_purge2$LC80 -2.249e+00 1.768e-01 -12.725 2e-16 *** mydata_purge2$LC231 1.799e-01 4.492e-02 4.005 6.21e-05 *** mydata_purge2$DEM6.670e-04 7.687e-05 8.678 2e-16 *** Zero-inflation model coefficients (binomial with logit link): Estimate Std. Error z value Pr(|z|) (Intercept) -0.0593751 0.2308068 -0.257 0.796986 mydata_purge2$LC80 2.9428092 0.8523669 3.453 0.000555 *** mydata_purge2$LC231 -1.7772101 0.3233166 -5.497 3.87e-08 *** mydata_purge2$DEM -0.0031901 0.0005319 -5.997 2.01e-09 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Number of iterations in BFGS optimization: 13 Log-likelihood: -1.727e+04 on 8 Df a1 = predict(zip1A) b1 = mydata_purge2$TOT plot(a1,b1) Please find attached the plot of zip1A (which look quite similar to the hurdle1).
[R] conversion of matrix into list
Dear all, I have a matrix X which consists of 2 columns. I would like to convert this matrix into a list where every entry of the list consists of a single row of the matrix. Does anyone have a suggestions how to manage this? Thank you for your efforts in advance! Best, Martin [[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] Odp: conversion of matrix into list
Hi Dear all, I have a matrix X which consists of 2 columns. I would like to convert this matrix into a list where every entry of the list consists of a single row of the matrix. e.g. split(mat, 1:nrow(mat)) Regards Petr Does anyone have a suggestions how to manage this? Thank you for your efforts in advance! Best, Martin [[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] Metafor: Differences between two categories of a moderator
Hi Wolfgang that's good news. One further small follow-up question: When I conduct multiple comparisons via the relevel-command: should I adjust the p-value? Thanks in advance, Holger -- View this message in context: http://r.789695.n4.nabble.com/Metafor-Differences-between-two-categories-of-a-moderator-tp3562778p3565210.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] different results from lme() and lmer()
Dear Miya, Notice the very strong negative correlation between the random intercept and the random slope in the lme() model. That is usually an indication of problems (in this case overfitting). If you drop the random slope, then both models yield the same parameters. Plotting the data reviels a much better model specification. dat - read.table(file = http://www.bio.ic.ac.uk/research/mjcraw/therbook/data/fertilizer.txt;, header = TRUE) library(ggplot2) ggplot(dat, aes(x = week, y = root, group = plant, colour = fertilizer)) + geom_line() lmer(root~fertilizer + week +(1|plant),data=dat) Best regards, Thierry PS Use R-sig-mixedmodels for questions on mixed models -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Taro Miyagawa Verzonden: woensdag 1 juni 2011 7:58 Aan: r-help@r-project.org Onderwerp: [R] different results from lme() and lmer() Hello R-help, I'm studying an example in the R book. The data file is available from the link below.http://www.bio.ic.ac.uk/research/mjcraw/therbook/data/fertilizer.txt Could you explain Why the results from lme() and lmer() are different in the following case? In other examples, I can get the same results using the two functions, but not here... Thank you.Miya library(lme4)library(nlme)# object dat contains the data summary(lme(root~fertilizer,random=~week|plant,data=dat))Linear mixed- effects model fit by REML Data: dat AIC BIC logLik 171.0236 183.3863 - 79.51181 Random effects: Formula: ~week | plant Structure: General positive-definite, Log-Cholesky parametrization StdDev Corr (Intercept) 2.8639832 (Intr)week 0.9369412 -0.999Residual 0.4966308 Fixed effects: root ~ fertilizer Value Std.Error DF t-value p- value(Intercept) 2.799710 0.1438367 48 19.464499 0e+00fertilizercontrol - 1.039383 0.2034158 10 -5.109645 5e- 04 Correlation: (Intr)fertilizercontrol -0.707 Standardized Within-Group Residuals: Min Q1 Med Q3 Max - 1.9928118 -0.6586834 -0.1004301 0.6949714 2.0225381 Number of Observations: 60Number of Groups: 12 lmer(root~fertilizer+(week|plant),data=dat)Linear mixed model fit by REML Formula: root ~ fertilizer + (week | plant) Data: dat AIC BIC logLik deviance REMLdev 174.4 187 -81.21 159.7 162.4Random effects: Groups Name Variance Std.Dev. Corr plant (Intercept) 4.1416e-18 2.0351e-09 week 8.7452e-01 9.3516e-01 0.000 Residual 2.2457e-01 4.7389e-01 Number of obs: 60, groups: plant, 12 Fixed effects: Estimate Std. Error t value(Intercept) - 0.1847 0.2024 -0.913fertilizercontrol -0.7612 0.2862 -2.660 Correlation of Fixed Effects: (Intr)frtlzrcntrl -0.707 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] problems with converting into dxf file
Hello, I'm using R to calculate MCP home ranges to my master thesis. I have problem with converting shapes of home ranges to .dxf file, which I can use in ArcMap. Problems are showing when I'm opening attribute table, because somehow during converting int dxf file R is deleting all input information like: animal ID, habitat, season for which it has calculated MCP size. Is there any command which can save those informations? My script looks like that: mcp95 - mcp(loc, id=season, percent = 95) area2dxf(mcp95, file = D:/your_own_path/mcp_95,lay = mcparea95) -- View this message in context: http://r.789695.n4.nabble.com/problems-with-converting-into-dxf-file-tp3565145p3565145.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] bayesglm with weights
Dear list, I have troubles with using Bayesian logistic model with count data in bayesglm. If I consider the following artificial data set, with a response y and a covariate x, in a form of row data (a) and count (b) : a-data.frame(y=c(rep(1,10),rep(0,6)),x=c(rep(5,6),rep(4,4),rep(5,1),rep(4,5))) a$un-1 b-aggregate(a$un,list(y=a$y,x=a$x),sum) names(b)[3]-w A binomial model with glm running on a and b give the same results : (M1=glm(y~x,family=binomial,data=a)) (M2=glm(y~x,data=b,family=binomial,weights=w)) However, with the arm and bayesglm function, the equivalent models with non-informative prior, give different results: library(arm) (M3=bayesglm(y~x,data=a,family=binomial,prior.scale=Inf, prior.df=Inf) )#M3=M2=M1 (M4=bayesglm(y~x,data=b,family=binomial,weights=w,prior.scale=Inf, prior.df=Inf))#M4 is different When I try a formulation with y=response rate or y=(response,failure), I get the rights coefs, but lower standard errors. c-data.frame(y=c(4/9,6/7),x=c(4,5),w=c(9,7)) (M5=bayesglm(y~x,data=c,family=binomial,weights=w,prior.scale=Inf, prior.df=Inf)) y-matrix(c(4,6,5,1),ncol=2) x-matrix(c(4,5),ncol=1) (M6=bayesglm(y~x,family=binomial,prior.scale=Inf, prior.df=Inf)) Am I missing something? Thanks, Edouard Chatignoux, Statistician Health oservatory of the Paris Île-de-France region 43 rue Beaubourg- 75003 PARIS Tel. : 01 77 49 78 54 Fax. : 01 77 49 78 61 I'm running R 2.13.0 under windows XP sessionInfo() R version 2.13.0 (2011-04-13) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] splines stats graphics grDevices datasets grid utils [8] methods base other attached packages: [1] foreign_0.8-44 arm_1.4-11 abind_1.3-0R2WinBUGS_2.1-18 [5] coda_0.14-4lme4_0.999375-39 Matrix_0.999375-50 lattice_0.19-26 [9] MASS_7.3-13xtable_1.5-6 mgcv_1.7-6 ggplot2_0.8.9 [13] proto_0.3-9.2 reshape_0.8.4 plyr_1.5.2 loaded via a namespace (and not attached): [1] nlme_3.1-101 stats4_2.13.0 tools_2.13.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Odp: while loop problems
Hi Without reproducible example or some code I wonder if anybody can give you some advice. As a wild guess do you use if function correctly i.e. input is length one logical vector ? And maybe you do not need loop at all Regards Petr [R] while loop problems Hi , i am trying to get this loop in my r program to work but it is not giving me the results that I desire. I am trying to model an insurance contract where there are n securities that have a fixed likelihood of default vector(data[i,2]) and a payout vector(data[i,1]). i need to price the value of stop losses at the security level and at the portfolio level. to do this i created two while loops for the conditional vectors of each level (which will be inputed into the function by the user) one while loop to scan through the various securities and a final one to model the various scenarios(i.e. monte carlo). i tried to Use R's matrix capabilities to help organize the results. the problem with this code is that the if statement behaves oddly, not activating and filtering correctly. this causes the program to be slow and provide bad results. it fills the individual protection column always rather than conditioning it on the likelihood vector(data[i,2]). there is a lot of moving parts but overall it is a simple model. my end result is to have a vector containing the accumulated values of insurance for each type of stop loss(i.e. idiosyncratic and aggregate). Thanks, Alon. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] load seven files (named by date) at a time
Hello, I'm trying to load a weeks worth of files that are each named by the date they were creaded (e.g., 20110601.RData), starting with the day before today so if today is June 1, I would like to load 20110525- 20110531. The script was working until today, and x= 20110593 20110594 20110595 20110596 20110597 20110598 20110599 20110600. time=Sys.time() t1- as.numeric(format.Date(time, %Y%m%d)) #date range of data to load t1=t1-1 t0 -t1-7 x = t0:t1 Any solutions? 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.
[R] Odp: load seven files (named by date) at a time
Hi [R] load seven files (named by date) at a time Hello, I'm trying to load a weeks worth of files that are each named by the date they were creaded (e.g., 20110601.RData), starting with the day before today so if today is June 1, I would like to load 20110525- 20110531. The script was working until today, and x= 20110593 20110594 20110595 20110596 20110597 20110598 20110599 20110600. time=Sys.time() t1- as.numeric(format.Date(time, %Y%m%d)) #date range of data to load t1=t1-1 t0 -t1-7 x = t0:t1 Any solutions? work with dates not numbers seq(as.Date(time)-7, as.Date(time)-1, by=1) Regards Petr 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Odp: load seven files (named by date) at a time
Awesome, thanks a lot! On 6/1/2011 11:22 AM, Petr PIKAL wrote: seq(as.Date(time)-7, as.Date(time)-1, by=1) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Identifying sequences
Hallo Everybody Consider the following vector a=1:10 b=20:30 c=40:50 x=c(a,b,c) I need a function that can tell me that there are three set of continuos sequences and that the first is from 1:10, the second from 20:30 and the third from 40:50. In other words: a,b, and c. regards Christiaan [[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] error in model specification for cfa with lavaan-package
Dear R-List, (I am not sure whether this list is the right place for my question...) I have a dataframe df.cfa df.cfa-data.frame(x1=c(5,4,1,5,5,NA,4,NA,NA,5),x2=c(2,3,3,3,NA,1,2,1,2,1),x3=c(5,3,4,1,5,5,5,5,5,5),x4=c(5,3,4,5,5,5,5,5,5,5),x5=c(5,4,3,3,4,4,4,5,NA,5),x6=c(3,5,2,1,4,NA,NA,5,3,4),x7=c(5,4,3,4,4,3,4,NA,NA,4),x8=c(5,5,3,4,5,4,5,4,5,5),x9=c(5,1,1,1,NA,3,3,2,2,3),x10=c(5,5,2,3,4,3,1,3,2,5),x11=c(5,4,4,5,5,4,5,4,5,5),x12=c(5,4,5,5,5,4,5,5,5,5),x13=c(5,4,4,5,5,5,5,5,5,5),x14=c(5,3,3,NA,5,4,5,3,NA,5),x15=c(4,4,4,3,4,5,2,4,5,5),x16=c(5,4,3,3,4,4,3,3,4,5)) and I want to carry out a confirmatory factor analysis using the cfa function (lavaan). library(lavaan) then I specify my model cfa.model-' f1=~x1+x2+x3+x4+x5 f2=~x6+x7+x8+x9+x10+x11 f3=~x12+x13+x14+x15+x16 ' and run the cfa routine fit-cfa(cfa.model,data=df.cfa,missing=ml) The output is an error message (here partly in german) Error in chol.default(S) : der führende Minor der Ordnung 4 ist nicht positiv definit Fehler in Sample(data = data, group = group, sample.cov = sample.cov, sample.mean = sample.mean, : sample covariance can not be inverted Then I tried to lavaanify my model specification first cfa.model- lavaanify(cfa.model) id lhs op rhs user group free ustart fixed.x label eq.id free.uncon 1 1 f1 =~ x1 1 1 1 NA 0 f1=~x1 0 1 2 2 f1 =~ x2 1 1 2 NA 0 f1=~x2 0 2 3 3 f1 =~ x3 1 1 3 NA 0 f1=~x3 0 3 4 4 f1 =~ x4 1 1 4 NA 0 f1=~x4 0 4 5 5 f1 =~ x5 1 1 5 NA 0 f1=~x5 0 5 6 6 f2 =~ x6 1 1 6 NA 0 f2=~x6 0 6 7 7 f2 =~ x7 1 1 7 NA 0 f2=~x7 0 7 8 8 f2 =~ x8 1 1 8 NA 0 f2=~x8 0 8 9 9 f2 =~ x9 1 1 9 NA 0 f2=~x9 0 9 10 10 f2 =~ x10 1 1 10 NA 0 f2=~x10 0 10 11 11 f2 =~ x11 1 1 11 NA 0 f2=~x11 0 11 12 12 f3 =~ x12 1 1 12 NA 0 f3=~x12 0 12 13 13 f3 =~ x13 1 1 13 NA 0 f3=~x13 0 13 14 14 f3 =~ x14 1 1 14 NA 0 f3=~x14 0 14 15 15 f3 =~ x15 1 1 15 NA 0 f3=~x15 0 15 16 16 f3 =~ x16 1 1 16 NA 0 f3=~x16 0 16 I run cfa again fit-cfa(cfa.model,data=df.cfa,missing=ml) And this time I get another error information Error in start.idx[i]:end.idx[i] : NA/NaN Argument I must admit that I am stuck, can anyone help? Thanks, Alain [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error in model specification for cfa with lavaan-package
Dear Alain, There were 16 variables with 10 cases with missing values. The sample covariance matrix is not positive definite. It has nothing to do with lavaan. You need more cases before you can fit a CFA with 16 variables. Regards, Mike -- - Mike W.L. Cheung Phone: (65) 6516-3702 Department of Psychology Fax: (65) 6773-1843 National University of Singapore http://courses.nus.edu.sg/course/psycwlm/internet/ - On Wed, Jun 1, 2011 at 6:31 PM, D. Alain dialva...@yahoo.de wrote: Dear R-List, (I am not sure whether this list is the right place for my question...) I have a dataframe df.cfa df.cfa-data.frame(x1=c(5,4,1,5,5,NA,4,NA,NA,5),x2=c(2,3,3,3,NA,1,2,1,2,1),x3=c(5,3,4,1,5,5,5,5,5,5),x4=c(5,3,4,5,5,5,5,5,5,5),x5=c(5,4,3,3,4,4,4,5,NA,5),x6=c(3,5,2,1,4,NA,NA,5,3,4),x7=c(5,4,3,4,4,3,4,NA,NA,4),x8=c(5,5,3,4,5,4,5,4,5,5),x9=c(5,1,1,1,NA,3,3,2,2,3),x10=c(5,5,2,3,4,3,1,3,2,5),x11=c(5,4,4,5,5,4,5,4,5,5),x12=c(5,4,5,5,5,4,5,5,5,5),x13=c(5,4,4,5,5,5,5,5,5,5),x14=c(5,3,3,NA,5,4,5,3,NA,5),x15=c(4,4,4,3,4,5,2,4,5,5),x16=c(5,4,3,3,4,4,3,3,4,5)) and I want to carry out a confirmatory factor analysis using the cfa function (lavaan). library(lavaan) then I specify my model cfa.model-' f1=~x1+x2+x3+x4+x5 f2=~x6+x7+x8+x9+x10+x11 f3=~x12+x13+x14+x15+x16 ' and run the cfa routine fit-cfa(cfa.model,data=df.cfa,missing=ml) The output is an error message (here partly in german) Error in chol.default(S) : der führende Minor der Ordnung 4 ist nicht positiv definit Fehler in Sample(data = data, group = group, sample.cov = sample.cov, sample.mean = sample.mean, : sample covariance can not be inverted Then I tried to lavaanify my model specification first cfa.model- lavaanify(cfa.model) id lhs op rhs user group free ustart fixed.x label eq.id free.uncon 1 1 f1 =~ x11 11 NA 0 f1=~x1 0 1 2 2 f1 =~ x21 12 NA 0 f1=~x2 0 2 3 3 f1 =~ x31 13 NA 0 f1=~x3 0 3 4 4 f1 =~ x41 14 NA 0 f1=~x4 0 4 5 5 f1 =~ x51 15 NA 0 f1=~x5 0 5 6 6 f2 =~ x61 16 NA 0 f2=~x6 0 6 7 7 f2 =~ x71 17 NA 0 f2=~x7 0 7 8 8 f2 =~ x81 18 NA 0 f2=~x8 0 8 9 9 f2 =~ x91 19 NA 0 f2=~x9 0 9 10 10 f2 =~ x101 1 10 NA 0 f2=~x10 0 10 11 11 f2 =~ x111 1 11 NA 0 f2=~x11 0 11 12 12 f3 =~ x121 1 12 NA 0 f3=~x12 0 12 13 13 f3 =~ x131 1 13 NA 0 f3=~x13 0 13 14 14 f3 =~ x141 1 14 NA 0 f3=~x14 0 14 15 15 f3 =~ x151 1 15 NA 0 f3=~x15 0 15 16 16 f3 =~ x161 1 16 NA 0 f3=~x16 0 16 I run cfa again fit-cfa(cfa.model,data=df.cfa,missing=ml) And this time I get another error information Error in start.idx[i]:end.idx[i] : NA/NaN Argument I must admit that I am stuck, can anyone help? Thanks, Alain [[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] Forcing a negative slope in linear regression?
In econometrics economic theory often predicts a particular sign for a slope variable. One often gets wrong signs on variables but the coefficients as estimated, in such cases are usually both statistically and economically insignificant. In such cases one generally re-estimates the equation with the variable omitted (imposing a zero sign. Perhaps re-estimating with the variable missing is the simplest solution. Of course, I agree that if the variable is significant and of the wrong sign there is something wrong with the theory or the data. John On 1 June 2011 03:40, Rolf Turner rolf.tur...@xtra.co.nz wrote: (1) You can easily force the slope to take on a *particular* value, positive or negative, by using offset(). However just to constrain the value of the slope to be less than or equal to 0 you'd have to do a constrained optimization of the sum of squares. Not hard to do, but probably (almost surely) unwise. If the data are telling you that the slope is positive, don't argue with them. Also if you constrain slope = 0 and the data want the slope to be greater than 0, then the constrained optimum will probably be at slope == 0. If you want it to be *less* than 0, you'd have to constrain it with slope = - epsilon for some (positive) epsilon. And then I'd guess you'd wind up with a slope of -epsilon. So you might as well fix the slope at -epsilon and use offset(). But the whole idea makes no sense. So: The executive summary is ``Don't do it.'' (2) Your example data don't make any sense either. You present the values of only one variable. For a regression you need to have a y-variable and at least one x-variable. It would appear that you're not thinking very clearly. cheers, Rolf Turner On 01/06/11 11:32, J S wrote: Dear forum members, How can I force a negative slope in a linear regression even though the slope might be positive? I will need it for the purpose of determining the trend due reasons other than biological because the biological (genetic) trend is not positive for these data. Thanks. Julia Example of the data: [1] 1.254 1.235 1.261 0.952 1.202 1.152 0.801 0.424 0.330 0.251 0.229 0.246 [13] 0.414 0.494 0.578 0.628 0.514 0.594 0.827 0.812 0.629 0.928 0.707 0.976 [25] 1.099 1.039 1.272 1.398 1.926 1.987 2.132 1.644 2.174 2.453 2.392 3.002 [37] 3.352 2.410 2.206 2.692 2.653 1.604 2.536 3.070 3.137 4.187 4.803 4.575 [49] 4.580 3.779 4.201 5.685 4.915 5.929 5.474 6.140 5.182 5.524 5.848 5.830 [61] 5.800 7.517 6.422 [[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. -- John C Frain Economics Department Trinity College Dublin Dublin 2 Ireland www.tcd.ie/Economics/staff/frainj/home.html mailto:fra...@tcd.ie mailto:fra...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] retrieving name of a function inside this function
Dear list members, is it possible to retrieve the name of a function or the exact call to that function from the environment created inside this function? I wrote a function for debugging on a cluster that saves all the objects inside the whole stack of function environments and would also like to retrieve the names of the respective functions. Perhaps also a method to simply retrieve the name of a function inside this function could give me hints to the solution. Thanks Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] retrieving name of a function inside this function
On 11-06-01 7:26 AM, Jannis wrote: Dear list members, is it possible to retrieve the name of a function or the exact call to that function from the environment created inside this function? I wrote a function for debugging on a cluster that saves all the objects inside the whole stack of function environments and would also like to retrieve the names of the respective functions. Perhaps also a method to simply retrieve the name of a function inside this function could give me hints to the solution. I'm not sure I understand what you're asking, but I think the answer is no. You can retrieve the name of a function by calling sys.call() (or a related function for more information, see ?sys.call), but that has to be called in the context of the function. The information is not stored in the active environment, you'll need to save more than that. I think sys.calls() will give you the information you need. Duncan Murdoch Thanks Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Missing completely at random
Hello! I would like to sample 5 % of cases and from 1 to 3 variables within selected cases and set them as NA (MCAR-Missing completely at random). I managed to sample cases and variables, but I donât know how to set them as NA. R code: N - 1000      number of cases n - 12           number of variables X - matrix(rnorm(N * n), N, n)   matrix pMiss - 0.05    percent of missing values idMiss - sample(1:N, N * pMiss)   sample cases nMiss - length(idMiss) m - 3   maximum number of missing variables within selected cases howmanyMiss - sapply(idMiss, function(x) sample(1:m, 1)) howmanyMiss lapply(howmanyMiss, function(x) sample(1:n, x))  Any suggestion? Thanks, Blaž [[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] Import/convert PMML to R model
Hi R-helpers, Can you please let me know if it is possible to import a PMML in R? If yes, can you give me the command to do the same? If not, can you tell me the reason why? Many thanks, Raji -- View this message in context: http://r.789695.n4.nabble.com/Import-convert-PMML-to-R-model-tp3332772p3565260.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] treemaps
Hello, I've created a treemap using the treemap package (tmPlot) showing distribution of my data across 3 countries. The boxes created within the country are proportionate to my data; however how do I make the 3 countries proportionate to the total of all 3 as well? Currently the 3 countries are the same size, this implies they all have the same endowment so to speak, which is not the case. Cheers [[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] Problem with as.POSIXct()
Hi, when I type in these words: a=c(2011-06-01 17:21:24.83, 2011-06-01 17:21:24.283) as.POSIXct(a) the real output is: [1] 2011-06-01 17:21:24.830 CST 2011-06-01 17:21:24.283 CST rather than the expected one: [1] 2011-06-01 17:21:24.083 CST 2011-06-01 17:21:24.283 CST How can I deal with such milliseconds less than 100? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-as-POSIXct-tp3565424p3565424.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Identifying sequences
On Jun 1, 2011, at 6:27 AM, christiaan pauw wrote: Hallo Everybody Consider the following vector a=1:10 b=20:30 c=40:50 x=c(a,b,c) I need a function that can tell me that there are three set of continuos sequences and that the first is from 1:10, the second from 20:30 and the third from 40:50. In other words: a,b, and c. You probably want something like which(diff(x) 1) [1] 10 21 Or perhaps what the rle function provides. ?diff ?rle -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Identifying sequences
Something like this? a=1:10 b=20:30 c=40:50 x=c(a,b,c) borders - which(diff(x) != 1) seqs - data.frame(start = c(1, borders + 1), end = c(borders, length(x))) Best regards, Thierry -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens christiaan pauw Verzonden: woensdag 1 juni 2011 12:27 Aan: r-help@r-project.org Onderwerp: [R] Identifying sequences Hallo Everybody Consider the following vector a=1:10 b=20:30 c=40:50 x=c(a,b,c) I need a function that can tell me that there are three set of continuos sequences and that the first is from 1:10, the second from 20:30 and the third from 40:50. In other words: a,b, and c. regards Christiaan [[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] Identifying sequences
I am assuming in this case that you are looking for continuity along integers, so if you expect noninteger values this will not work. You can get the index of where breaks can be found in your example using which(diff(x) 1) On Wed, Jun 1, 2011 at 6:27 AM, christiaan pauw cjp...@gmail.com wrote: Hallo Everybody Consider the following vector a=1:10 b=20:30 c=40:50 x=c(a,b,c) I need a function that can tell me that there are three set of continuos sequences and that the first is from 1:10, the second from 20:30 and the third from 40:50. In other words: a,b, and c. regards Christiaan [[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. -- === Jon Daily Technician === #!/usr/bin/env outside # It's great, trust me. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Retaining MatchIt output as a dataset
Hi! I am running a simulation testing group balance using different propensity score matching techniques. I am using the MatchIt package to match and analyze the data. Since I am running this analysis many, many times with different simulated data sets, I need to make the output from the MatchIt summary and put it into a dataset and then append each successive run to the end of that dataset. How can I do that? Any help would be appreciated. Thanks! Shane [[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] graphical output - customization of x axis
Hello, I do not understand why the following source does not success in customizing the x axis. The wished customization just consists in labelling the x ticks with 0kb,1kb,5kb,10kb,20kb,50kb,100kb,inf. pathFileName - test1.png stats4H - c(0.8623, 0.7142, 0.7211, 0.6753, 0.6290, 0.6157, 0.5919, 0.5218) stats4W - c(0.8724, 0.7889, 0.7253, 0.7235, 0.6860, 0.6630, 0.6424, 0.5228) stats5H - c(0.7610, 0.6832, 0.6310, 0.5527, 0.5231, 0.5600, 0.6147, 0.5131) stats5W - c(0.7740, 0.7641, 0.7099, 0.6918, 0.6483, 0.5769, 0.5539, 0.4934) plotType - b png(file=pathFileName, bg=transparent) xxf - c(0kb,1kb,5kb,10kb,20kb,50kb,100kb,inf) xf - 1:8 par(lab = c(length(xxf), 5, 7)) #c(x, y, len) # ‘lab’ A numerical vector of the form ‘c(x, y, len)’ which modifies # the default way that axes are annotated. The values of ‘x’ # and ‘y’ give the (approximate) number of tickmarks on the x # and y axes and ‘len’ specifies the label length. The default # is ‘c(5, 5, 7)’. Note that this only affects the way the # parameters ‘xaxp’ and ‘yaxp’ are set when the user coordinate # system is set up, and is not consulted when axes are drawn. # ‘len’ _is unimplemented_ in R. plot(stats4H, xlab = half-width of window, ylab=AUC, type=plotType, pch=7, col=blue, cex = 0.5, ylim=c(0.4,1),xlim=c(1,8), xaxt = n) # without x axis #If you are going to create a custom axis, you should suppress the axis automatically generated by your high level plotting function. The option axes=FALSE suppresses both x and y axes. xaxt=n and yaxt=n suppress the x and y axis respectively. positions - 1:8 axis(side = 1, at=positions, labels=xxf , pos=0, lty=1, col.axis=black, las=0) # side: bottom (1) # at: the points at which tick-marks are to be drawn # pos:coordinate of defined axis on the other axis # lty: linetype # col: line and tick marker color # las: labels are parallel (=0) or perpendicular(=2) to axis # tck: length of tick mark as fraction of plotting region (negative number is outside graph, # positive number is inside, 0 suppresses ticks, 1 creates gridlines) default is -0.01 lines(x = xf, y = stats4W, type=plotType, pch=15, col=green, cex = 0.5) lines(x = xf, y = stats5H, type=plotType, pch=16, col=red, cex = 0.5) lines(x = xf, y = stats5W, type=plotType, pch=17, col=magenta,cex = 0.5) legend(bottomright, legend = c(H, statistic S1, W, statistic S1, H, statistic S2, W, statistic S2), col = c(blue, green, red, magenta), pch = c(7,15,16,17), bty = n, cex = 0.8, inset = c(0.1, 0.1)) dev.off() I thank you in advance for any help. Best regards, Christine Sinoquet __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 as.POSIXct()
circe tju_circe at hotmail.com writes: Hi, when I type in these words: a=c(2011-06-01 17:21:24.83, 2011-06-01 17:21:24.283) as.POSIXct(a) the real output is: [1] 2011-06-01 17:21:24.830 CST 2011-06-01 17:21:24.283 CST rather than the expected one: [1] 2011-06-01 17:21:24.083 CST 2011-06-01 17:21:24.283 CST How can I deal with such milliseconds less than 100? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-as-POSIXct-tp3565424p3565424.html Sent from the R help mailing list archive at Nabble.com. Well, to me the R is behaving as expected. I.e. .83 = .830. If Your dates come in a format like You describe, You need to manually add a leading zero to Your milliseconds. A suggestion to work from: for(i in 1:length(a)){ if(nchar(a[i]) == 23){ print(a[i]) }else{ print( paste(substr(a[i],1,20),0,substr(a[i],21,22),sep='') ) } } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] graphical output - customization of x axis
Take out the pos=0 argument in your call to axis. -- David. On Jun 1, 2011, at 8:56 AM, Christine SINOQUET wrote: Hello, I do not understand why the following source does not success in customizing the x axis. The wished customization just consists in labelling the x ticks with 0kb,1kb,5kb,10kb,20kb,50kb,100kb,inf. pathFileName - test1.png stats4H - c(0.8623, 0.7142, 0.7211, 0.6753, 0.6290, 0.6157, 0.5919, 0.5218) stats4W - c(0.8724, 0.7889, 0.7253, 0.7235, 0.6860, 0.6630, 0.6424, 0.5228) stats5H - c(0.7610, 0.6832, 0.6310, 0.5527, 0.5231, 0.5600, 0.6147, 0.5131) stats5W - c(0.7740, 0.7641, 0.7099, 0.6918, 0.6483, 0.5769, 0.5539, 0.4934) plotType - b png(file=pathFileName, bg=transparent) xxf - c(0kb,1kb,5kb,10kb,20kb,50kb,100kb,inf) xf - 1:8 par(lab = c(length(xxf), 5, 7)) #c(x, y, len) # ‘lab’ A numerical vector of the form ‘c(x, y, len)’ which modifies # the default way that axes are annotated. The values of ‘x’ # and ‘y’ give the (approximate) number of tickmarks on the x # and y axes and ‘len’ specifies the label length. The default # is ‘c(5, 5, 7)’. Note that this only affects the way the # parameters ‘xaxp’ and ‘yaxp’ are set when the user coordinate # system is set up, and is not consulted when axes are drawn. # ‘len’ _is unimplemented_ in R. plot(stats4H, xlab = half-width of window, ylab=AUC, type=plotType, pch=7, col=blue, cex = 0.5, ylim=c(0.4,1),xlim=c(1,8), xaxt = n) # without x axis #If you are going to create a custom axis, you should suppress the axis automatically generated by your high level plotting function. The option axes=FALSE suppresses both x and y axes. xaxt=n and yaxt=n suppress the x and y axis respectively. positions - 1:8 axis(side = 1, at=positions, labels=xxf , pos=0, lty=1, col.axis=black, las=0) # side: bottom (1) # at: the points at which tick-marks are to be drawn # pos:coordinate of defined axis on the other axis # lty: linetype # col: line and tick marker color # las: labels are parallel (=0) or perpendicular(=2) to axis # tck: length of tick mark as fraction of plotting region (negative number is outside graph, # positive number is inside, 0 suppresses ticks, 1 creates gridlines) default is -0.01 lines(x = xf, y = stats4W, type=plotType, pch=15, col=green, cex = 0.5) lines(x = xf, y = stats5H, type=plotType, pch=16, col=red, cex = 0.5) lines(x = xf, y = stats5W, type=plotType, pch=17, col=magenta,cex = 0.5) legend(bottomright, legend = c(H, statistic S1, W, statistic S1, H, statistic S2, W, statistic S2), col = c(blue, green, red, magenta), pch = c(7,15,16,17), bty = n, cex = 0.8, inset = c(0.1, 0.1)) dev.off() I thank you in advance for any help. Best regards, Christine Sinoquet __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simulating SVAR Data
Hello, I'd like to simulate data according to an SVAR model in order to demonstrate how other techniques (such as arima) yield biased estimates. I am interested in a 2 variable SVAR with 2 lags (in the notation of the vars vignette, K = 2, P = 2, where B = I_K). I'm using the {vars} package outlined here: http://cran.r-project.org/web/packages/vars/vignettes/vars.pdf I thought that the following would generate the data and demonstrate the accuracy of an SVAR compared to an arima, but the results are not what I expected. I think the problem is the way that I'm generating the data, but I don't understand what I could be doing wrong. Any guidance would be greatly appreciated. Problems: In the code below, the array means should show that SVAR parameters are unbiased estiamtors, so the second column of means should be near 0, and it's not any closer than the first column (the arima results). So my results are no less biased than the arima results. The first pair of plots should show the same: SVAR results are unbiased. But they don't cluster around the red dots (true parameter values), so they aren't. Finally, the second pair of plots should show the parameters are consistent: that MSE decreases as sample size increases. They don't really show that. Perhaps they would if the smallest sample were smaller than 200, but the SVAR tends not to converge with fewer observations. Further, the MSE tends to be at least as high with the SVAR compared to arima, so it's not any more accurate. Program: # Model # # Y(t) = a0 + a1*Y(t-1) + a2*Y(t-2) + a3*X(t-1) + a4*X(t-2) + e(t) # X(t) = b0 + b1*X(t-1) + b2*X(t-2) + b3*Y(t-1) + b4*Y(t-2) + b5*Y(t) + d(t) # e(t) d(t) ~ N(0,s) # So Y has a contemporaneous impact on X # X only has an impact on future Ys # So this is the setup of a SVAR # Choosing parameters # # Currently, all parameters are just random numbers less than 1 so that # it's a stationary series # The standard deviations of the error terms are also random ~ U(0,2) a0 - runif(1,-1,1) a1 - runif(1,-0.9,0.9) a2 - runif(1,-abs(a1),abs(a1)) a3 - runif(1,-0.9,0.9) a4 - runif(1,-abs(a3),abs(a3)) s.e - runif(1,0,2) b0 - runif(1,-1,1) b1 - runif(1,-0.9,0.9) b2 - runif(1,-abs(b1),abs(b1)) b3 - runif(1,-0.9,0.9) b4 - runif(1,-abs(b3),abs(b3)) b5 - runif(1,-0.9,0.9) s.d - runif(1,0,2) ### A Formal Test: Loop # Z - 100 error - array(0,dim=c(Z,2,6)) N - runif(Z,200,1200) # Let the sample size vary so that we can check for consistency # Generating the data # # Start with 2 initial values and then create a dataset with 1200 observations X - rep(0,1202) Y - rep(0,1202) Y[1] - rnorm(1, a0 + a1*a0 + a2*a0 + a3*b0 + a4*b0, s.e) X[1] - rnorm(1, b0 + b1*b0 + b2*b0 + b3*a0 + b4*a0 + b5*Y[1], s.d) Y[2] - rnorm(1, a0 + a1*Y[1] + a2*a0 + a3*X[1] + a4*b0, s.e) X[2] - rnorm(1, b0 + b1*X[1] + b2*b0 + b3*Y[1] + b4*a0 + b5*Y[2], s.d) for(t in 3:1202){ Y[t] - rnorm(1, a0 + a1*Y[t-1] + a2*Y[t-2] + a3*X[t-1] + a4*X[t-2], s.e) X[t] - rnorm(1, b0 + b1*X[t-1] + b2*X[t-2] + b3*Y[t-1] + b4*Y[t-2] + b5*Y[t], s.d) } L1.Y - rep(NA,1202) L2.Y - rep(NA,1202) for(t in 2:1202){ L1.Y[t] - Y[t-1] L2.Y[t] - L1.Y[t-1] } for(z in 1:Z){ n - N[z] x - X[3:(n+2)] y - Y[3:(n+2)] L1.y - c(NA,L1.Y[4:(n+2)]) L2.y - c(NA,NA,L2.Y[5:(n+2)]) # Modeling x with inclusion of y # m2 - arima(x,order=c(2,0,0),xreg=cbind(L1.y,L2.y,y)) error[z,1,1] - m2$coef[3] - b0 error[z,1,2:3] - m2$coef[1:2] - c(b1,b2) error[z,1,4:6] - m2$coef[4:6] - c(b3,b4,b5) # SVAR of x and y # m3 - VAR(cbind(y,x),p=2) A - matrix(c(1,NA,0,1),ncol=2) m4 - SVAR(m3,Amat=A) error[z,2,1] - m4$var$varresult$x$coeff[5] - b0 error[z,2,2] - m4$var$varresult$x$coeff[2] - b1 error[z,2,3] - m4$var$varresult$x$coeff[4] - b2 error[z,2,4] - m4$var$varresult$x$coeff[1] - b3 error[z,2,5] - m4$var$varresult$x$coeff[3] - b4 error[z,2,6] - m4$A[2,1] - b5 } mse - error^2 means - array(0,dim=c(6,2)) for(i in 1:2){ means[,i] - apply(error[,i,],2,mean) } means par(mfrow=c(2,1)) for(i in 1:2){ plot(1+runif(Z,-0.4,0.4),error[,i,1],xlim=c(0.5,6.5), xaxt='n',ylim=c(-1,1),ylab='',xlab='',main=paste(Model ,i)) for(j in 2:6){ points(j+runif(Z,-0.4,0.4),error[,i,j]) } points(seq(1,6,1),c(b0,b1,b2,b3,b4,b5),col=2) } par(mfrow=c(1,1)) par(mfrow=c(2,1)) for(i in 1:2){ plot(N,mse[,i,1],ylim=c(0,max(mse[,i,2:6])),main=paste(Model ,i)) for(j in 2:6){ points(N,mse[,i,j],col=j) }} par(mfrow=c(1,1)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error in model specification for cfa with lavaan-package
Dear Alain, As for the first error (sample covariance can not be inverted): Mike is right: with only 10 observations and 16 variables, the ML estimation of the sample cov produces a covariance matrix that is not positive definite, and hence the inversion (deliberately) fails. The lesson for me is that lavaan should simply check for this situation (p N), and refuse to proceed (with a gentle and more informative error message). As for the second error (Error in start.idx[i]:end.idx[i] : NA/NaN Argument): the first argument of cfa() must be a model syntax, not a lavaanified object. The 'lavaanify' function is useful to learn about lavaan, and to export the model specification to other software packages, but you should not pass a 'lavaanified' object to the cfa/sem/growth functions directly (although this may work in the future). Moreover, to get a 'complete' parameter list, you need to specify a number of additional arguments: model - model - lavaanify(cfa.model, auto.fix.first = TRUE, auto.var = TRUE, auto.cov.lv.x = TRUE) (see the 'Details' section in the man page of cfa() for a complete list). Hope this helps, Yves. On 06/01/2011 12:31 PM, D. Alain wrote: Dear R-List, (I am not sure whether this list is the right place for my question...) I have a dataframe df.cfa df.cfa-data.frame(x1=c(5,4,1,5,5,NA,4,NA,NA,5),x2=c(2,3,3,3,NA,1,2,1,2,1),x3=c(5,3,4,1,5,5,5,5,5,5),x4=c(5,3,4,5,5,5,5,5,5,5),x5=c(5,4,3,3,4,4,4,5,NA,5),x6=c(3,5,2,1,4,NA,NA,5,3,4),x7=c(5,4,3,4,4,3,4,NA,NA,4),x8=c(5,5,3,4,5,4,5,4,5,5),x9=c(5,1,1,1,NA,3,3,2,2,3),x10=c(5,5,2,3,4,3,1,3,2,5),x11=c(5,4,4,5,5,4,5,4,5,5),x12=c(5,4,5,5,5,4,5,5,5,5),x13=c(5,4,4,5,5,5,5,5,5,5),x14=c(5,3,3,NA,5,4,5,3,NA,5),x15=c(4,4,4,3,4,5,2,4,5,5),x16=c(5,4,3,3,4,4,3,3,4,5)) and I want to carry out a confirmatory factor analysis using the cfa function (lavaan). library(lavaan) then I specify my model cfa.model-' f1=~x1+x2+x3+x4+x5 f2=~x6+x7+x8+x9+x10+x11 f3=~x12+x13+x14+x15+x16 ' and run the cfa routine fit-cfa(cfa.model,data=df.cfa,missing=ml) The output is an error message (here partly in german) Error in chol.default(S) : der führende Minor der Ordnung 4 ist nicht positiv definit Fehler in Sample(data = data, group = group, sample.cov = sample.cov, sample.mean = sample.mean, : sample covariance can not be inverted Then I tried to lavaanify my model specification first cfa.model- lavaanify(cfa.model) id lhs op rhs user group free ustart fixed.x label eq.id free.uncon 1 1 f1 =~ x11 11 NA 0 f1=~x1 0 1 2 2 f1 =~ x21 12 NA 0 f1=~x2 0 2 3 3 f1 =~ x31 13 NA 0 f1=~x3 0 3 4 4 f1 =~ x41 14 NA 0 f1=~x4 0 4 5 5 f1 =~ x51 15 NA 0 f1=~x5 0 5 6 6 f2 =~ x61 16 NA 0 f2=~x6 0 6 7 7 f2 =~ x71 17 NA 0 f2=~x7 0 7 8 8 f2 =~ x81 18 NA 0 f2=~x8 0 8 9 9 f2 =~ x91 19 NA 0 f2=~x9 0 9 10 10 f2 =~ x101 1 10 NA 0 f2=~x10 0 10 11 11 f2 =~ x111 1 11 NA 0 f2=~x11 0 11 12 12 f3 =~ x121 1 12 NA 0 f3=~x12 0 12 13 13 f3 =~ x131 1 13 NA 0 f3=~x13 0 13 14 14 f3 =~ x141 1 14 NA 0 f3=~x14 0 14 15 15 f3 =~ x151 1 15 NA 0 f3=~x15 0 15 16 16 f3 =~ x161 1 16 NA 0 f3=~x16 0 16 I run cfa again fit-cfa(cfa.model,data=df.cfa,missing=ml) And this time I get another error information Error in start.idx[i]:end.idx[i] : NA/NaN Argument I must admit that I am stuck, can anyone help? Thanks, Alain [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] interpolation and extremum location of a surface
Hello, I have a x,y,z file.Z is not corresponding to a simple analytical function of x and y (see below). I am trying to find the minimum location of this surface and the z value corresponding to this location by a spline interpolation or from a polynomial fit. I tried with the akima package but as the location of the point I am looking for (the minimum) is outside of the convex hull it's not giving any answer. If someone has any idea or any suggestion? Thank you in advance Pierre xyz 4.1 60 -152.1719593 4.1 75 -171.136801 4.1 90 -170.4604774 4.2 60 -168.7745552 4.2 75 -174.9667333 4.2 90 -172.1853334 4.3 60 -173.7736418 4.3 75 -171.6712745 4.3 90 -167.6662458 4.05 60 -137.8379387 4.15 60 -162.2264066 4.25 60 -172.4453286 4.35 60 -173.2123715 4.05 67.5 -158.8239625 4.1 67.5 -167.314534 4.15 67.5 -172.586182 4.2 67.5 -175.2217594 4.25 67.5 -175.7162683 4.3 67.5 -174.4890566 4.35 67.5 -171.8940061 4.05 75 -165.4388778 4.15 75 -174.1460392 4.25 75 -174.022344 4.35 75 -168.2149168 4.05 82.5 -166.4026077 4.1 82.5 -170.9199652 4.15 82.5 -172.9923449 4.2 82.5 -173.0803255 4.25 82.5 -171.5739101 4.3 82.5 -168.8024715 4.35 82.5 -165.0431276 4.05 90 -166.2592978 4.15 90 -172.2861302 4.25 90 -170.5383652 4.35 90 -163.8389615 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Force Sweave to add figure filename extension
Hi, is there a way to force Sweave to add the extension (say .pdf) to the image names included by \includegraphics. I understand that the objective of not putting the extension is to allow the compilation with both latex or pdflatex. However, when option eps=false, the extension could optionally be forced to .pdf. I am having troubles submitting a paper to a journal, whose latex system does not compile the file properly if the extensions are not explicitly given. Thank you. Renaud ### UNIVERSITY OF CAPE TOWN This e-mail is subject to the UCT ICT policies and e-mai...{{dropped: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] Force Sweave to add figure filename extension
On 01/06/2011 10:13 AM, Renaud Gaujoux wrote: Hi, is there a way to force Sweave to add the extension (say .pdf) to the image names included by \includegraphics. I understand that the objective of not putting the extension is to allow the compilation with both latex or pdflatex. However, when option eps=false, the extension could optionally be forced to .pdf. I am having troubles submitting a paper to a journal, whose latex system does not compile the file properly if the extensions are not explicitly given. Thank you. Name the chunk and use include=false, then put in your own \includegrpahics call. For example figname, fig=true, include=false= plot(1:10) @ \includegraphics{figname.pdf} Duncan Murdoch Renaud ### UNIVERSITY OF CAPE TOWN This e-mail is subject to the UCT ICT policies and e-mai...{{dropped: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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Force Sweave to add figure filename extension
Hi, thank you Duncan for your prompt response. I was about to post another solution that worked fine for me (and the journal's system). Add in the preamble the command: \DeclareGraphicsExtensions{.pdf} Bests, Renaud On 01/06/2011 16:18, Duncan Murdoch wrote: On 01/06/2011 10:13 AM, Renaud Gaujoux wrote: Hi, is there a way to force Sweave to add the extension (say .pdf) to the image names included by \includegraphics. I understand that the objective of not putting the extension is to allow the compilation with both latex or pdflatex. However, when option eps=false, the extension could optionally be forced to .pdf. I am having troubles submitting a paper to a journal, whose latex system does not compile the file properly if the extensions are not explicitly given. Thank you. Name the chunk and use include=false, then put in your own \includegrpahics call. For example figname, fig=true, include=false= plot(1:10) @ \includegraphics{figname.pdf} Duncan Murdoch Renaud ### UNIVERSITY OF CAPE TOWN This e-mail is subject to the UCT ICT policies and e-mai...{{dropped: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. ### UNIVERSITY OF CAPE TOWN This e-mail is subject to the UCT ICT policies and e-mai...{{dropped: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] In a formula, what is the interaction of the intercept and a factor?
On Wed, Jun 1, 2011 at 1:19 AM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote: [text deleted] Note that you usually want to do '*' when you say 'interact with': model.matrix(y ~ (1+x)*group, data = dat) (Intercept) x groupB x:groupB 11 1 11 ... Thanks for that suggestion. To follow up, R model.matrix(y ~ (1+x)*group, data = dat) (Intercept) x groupB x:groupB 11 1 00 21 2 12 ... but if I delete 'x', R model.matrix(y ~ (1)*group, data = dat) (Intercept) 11 21 ... Why is group simply vanishing in the second model? I tried to dig into this until I hit .Internal(model.matrix Kevin On Tue, 31 May 2011, Kevin Wright wrote: For a pedagogical purpose, I was trying to show how the formula for a simple regression line (~1+x) could be crossed with a factor (~1:group + x:group) to fit separate regressions by group. For example: set.seed(201108) dat - data.frame(x=1:15, y=1:15+rnorm(15), group = sample(c('A','B'), size=15, replace=TRUE)) m1 - lm(y~ 1 + x, data=dat) m2 - lm(y ~ group + x:group, data=dat) m3 - lm(y ~ 1:group + x:group, data=dat) m4 - lm(y ~ 1 + x:group, data=dat) The simple regression is model m1. The usual way to write the by-group regression is model m2. In model m3 was trying to be explicitly clear and interact 1+x with group. Looking only at the coefficients, it appears that model m3 is simplified to model m4. R coef(m3) (Intercept)groupA:xgroupB:x 0.3775140 0.9213835 0.9879690 R coef(m4) (Intercept)x:groupAx:groupB 0.3775140 0.9213835 0.9879690 I wonder if anyone can shed some light on what R is doing with the 1:group term. Kevin [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[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] In a formula, what is the interaction of the intercept and a factor?
Perhaps of interest...in S-Plus 7.0 model.matrix(y ~ (1+x)*group, data = dat) (Intercept) x group x:group 1 1 1 1 1 2 1 2 1 2 ... model.matrix(y ~ (1)*group, data = dat) (Intercept) group 1 1 1 2 1 1 ... Kevin On Wed, Jun 1, 2011 at 9:44 AM, Kevin Wright kw.s...@gmail.com wrote: On Wed, Jun 1, 2011 at 1:19 AM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote: [text deleted] Note that you usually want to do '*' when you say 'interact with': model.matrix(y ~ (1+x)*group, data = dat) (Intercept) x groupB x:groupB 11 1 11 ... Thanks for that suggestion. To follow up, R model.matrix(y ~ (1+x)*group, data = dat) (Intercept) x groupB x:groupB 11 1 00 21 2 12 ... but if I delete 'x', R model.matrix(y ~ (1)*group, data = dat) (Intercept) 11 21 ... Why is group simply vanishing in the second model? I tried to dig into this until I hit .Internal(model.matrix Kevin On Tue, 31 May 2011, Kevin Wright wrote: For a pedagogical purpose, I was trying to show how the formula for a simple regression line (~1+x) could be crossed with a factor (~1:group + x:group) to fit separate regressions by group. For example: set.seed(201108) dat - data.frame(x=1:15, y=1:15+rnorm(15), group = sample(c('A','B'), size=15, replace=TRUE)) m1 - lm(y~ 1 + x, data=dat) m2 - lm(y ~ group + x:group, data=dat) m3 - lm(y ~ 1:group + x:group, data=dat) m4 - lm(y ~ 1 + x:group, data=dat) The simple regression is model m1. The usual way to write the by-group regression is model m2. In model m3 was trying to be explicitly clear and interact 1+x with group. Looking only at the coefficients, it appears that model m3 is simplified to model m4. R coef(m3) (Intercept)groupA:xgroupB:x 0.3775140 0.9213835 0.9879690 R coef(m4) (Intercept)x:groupAx:groupB 0.3775140 0.9213835 0.9879690 I wonder if anyone can shed some light on what R is doing with the 1:group term. Kevin [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 [[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] Identifying sequences
Thanks to David, Thierry and Jonathan for your help. I have been able to put this function together a=1:10 b=20:30 c=40:50 x=c(a,b,c) seq.matrix - function(x){ lower- x[which(diff(x) != 1)] upper - x[which(diff(x) != 1)+1] extremities - c(1,lower, upper,x[length(x)]) m - data.frame(matrix(extremities[order(extremities)],ncol=2,byrow=TRUE,dimnames=list(rows=paste(group,1:(length(lower)+1),sep=),cols=c(lower,upper m$length=m$upper-m$lower+1 m } s.m=seq.matrix(x) s.m lower upper length group1 110 10 group22030 11 group34050 11 One can then make a test to see if a certain value (say 9) falls within one of the groups and use that to find the group name or lower or upper border s.m.test=function(s.m,i){which(s.m[,1] i i s.m[,2])} s.m.test(s.m,i=9) [1] 1 e.g. row.names(s.m)[s.m.test(s.m,i=9)] [1] group1 Cheers Christiaan On 1 June 2011 14:31, Jonathan Daily biomathjda...@gmail.com wrote: I am assuming in this case that you are looking for continuity along integers, so if you expect noninteger values this will not work. You can get the index of where breaks can be found in your example using which(diff(x) 1) On Wed, Jun 1, 2011 at 6:27 AM, christiaan pauw cjp...@gmail.com wrote: Hallo Everybody Consider the following vector a=1:10 b=20:30 c=40:50 x=c(a,b,c) I need a function that can tell me that there are three set of continuos sequences and that the first is from 1:10, the second from 20:30 and the third from 40:50. In other words: a,b, and c. regards Christiaan [[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. -- === Jon Daily Technician === #!/usr/bin/env outside # It's great, trust me. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Create Matrix with Float32 values
Dear R_Help: The following gives me a matrix with integer values. z= matrix(rep(10:1, each= 10), ncol= 10, byrow=TRUE) str(z) int [1:10, 1:10] 10 9 8 7 6 5 4 3 2 1 ... How do I specify that I want Float32 values instead. Thanks,Chris __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RES: conversion of matrix into list
---BeginMessage--- Hi Martin, I believe this can do the trick. Let me know otherwise. Cheers testing - matrix(rnorm(10),50,2) testing_list - lapply(1:nrow(testing), function(j) testing[j,]) -Mensagem original- De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Em nome de Martin Spindler Enviada em: quarta-feira, 1 de junho de 2011 04:46 Para: R-help@r-project.org Assunto: [R] conversion of matrix into list Dear all, I have a matrix X which consists of 2 columns. I would like to convert this matrix into a list where every entry of the list consists of a single row of the matrix. Does anyone have a suggestions how to manage this? Thank you for your efforts in advance! Best, Martin [[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. ---End Message--- This message and its attachments may contain confidential and/or privileged information. If you are not the addressee, please, advise the sender immediately by replying to the e-mail and delete this message. Este mensaje y sus anexos pueden contener información confidencial o privilegiada. Si ha recibido este e-mail por error por favor bórrelo y envíe un mensaje al remitente. Esta mensagem e seus anexos podem conter informação confidencial ou privilegiada. Caso não seja o destinatário, solicitamos a imediata notificação ao remetente e exclusão da mensagem.__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Overlaying two matrices to create a heatmap
Hi, I'm trying to construct a heatmap using two matrices rather than one (Is this possible?) For example, matrix1: (color range black--- blue) acr DPA1-0103 DPA1-0104 DPA1-0201 DPA1-0202 DPA1-0301 DPA1-0103 17 0 2 1 0 DPA1-0104 0 0 0 0 DPA1-0201 1 0 0 DPA1-0202 0 0 DPA1-0301 0 matrix 2: (color range black--- magenta) noacr DPA1-0103 DPA1-0104 DPA1-0201 DPA1-0202 DPA1-0301 DPA1-0103 14 1 5 0 1 DPA1-0104 0 0 0 0 DPA1-0201 1 0 0 DPA1-0202 0 0 DPA1-0301 0 I'd like to create a separate color range for each and then overlay the two using some kind of additive color scheme so that if there are equally high numbers in a certain field the heatmap would display whatever color blue and magenta is (yellow I think). __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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-write plot function for ggplot
Hi, I have the following function that i use to plot graphs. plot_mi_time = function(mdata, miname) { mdata2 = mdata[row.names(mir_test3) == miname, ] # print(mdata2) xcoords - c(1,1,2,2,3,3) plot(xcoords, mdata2, xaxt=n, ylab=Expression, xlab=Time(h), , main=miname) axis(1, at=xcoords, labels=c(a,a,b,b,c,c)) } I want to edit this function so that i can plot it using ggplot. Any suggestions on how to re-write it? -- View this message in context: http://r.789695.n4.nabble.com/re-write-plot-function-for-ggplot-tp3565868p3565868.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] re-write plot function for ggplot
You should post it on the ggplot2 mailing list. For the long run I would suggest getting the book as it's extremely helpful. -- View this message in context: http://r.789695.n4.nabble.com/re-write-plot-function-for-ggplot-tp3565868p3565950.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plot a network with edges of specified length
Hello, I would like to plot a network with given edge lengths by using the plot function of the network package. Assume my network has the following adjacency matrix: a b c a 0 0 0 b 1 0 0 c 1 0 0 so that b and c are linked to a. I would like to specify that the length of the edge from b to a is 10 times longer than the one from c to a. So I set the following edge attribute: edgesLength=matrix(0,nrow=3,ncol=3) edgesLength[2,1]=10 edgesLength[3,1]=1 set.edge.attribute(network,edgesLength,1,e=1:length(network$mel)) set.edge.value(network,edgesLength,edgesLength,e=1:length(network$mel)) and then use the plot command: plot.network(network,attrname=edgesLength) but this does not take into account the fact that one edge should be 10 times longer than the other one. In fact, both edges have approximately the same length. Is this possible with the network package? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Plot-a-network-with-edges-of-specified-length-tp3565986p3565986.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Identifying sequences
Date: Wed, 1 Jun 2011 17:12:29 +0200 From: cjp...@gmail.com To: r-help@r-project.org Subject: Re: [R] Identifying sequences Thanks to David, Thierry and Jonathan for your help. I have been able to put this function together a=1:10 b=20:30 c=40:50 x=c(a,b,c) seq.matrix - function(x){ lower- x[which(diff(x) != 1)] upper - x[which(diff(x) != 1)+1] extremities - c(1,lower, upper,x[length(x)]) m - data.frame(matrix(extremities[order(extremities)],ncol=2,byrow=TRUE,dimnames=list(rows=paste(group,1:(length(lower)+1),sep=),cols=c(lower,upper m$length=m$upper-m$lower+1 m } s.m=seq.matrix(x) s.m lower upper length group1 1 10 10 group2 20 30 11 group3 40 50 11 One can then make a test to see if a certain value (say 9) falls within one of the groups and use that to find the group name or lower or upper border As I understand, you are looking for large derivatives or approx discontinuity against smooth signal. This seems like a natural application for wavelets, try the haar wavelet and use package wavelets, library(wavelets) f=wt.filter(c(-1,1),modwt=T) z-modwt(X=as.numeric(x),filter=f,n.levels=1) z@W $W1 [,1] [1,] 49 [2,] -1 [3,] -1 [4,] -1 [5,] -1 [6,] -1 [7,] -1 [8,] -1 [9,] -1 [10,] -1 [11,] -10 [12,] -1 [13,] -1 [14,] -1 [15,] -1 [16,] -1 [17,] -1 [18,] -1 [19,] -1 [20,] -1 [21,] -1 [22,] -10 [23,] -1 [24,] -1 [25,] -1 [26,] -1 [27,] -1 [28,] -1 [29,] -1 [30,] -1 [31,] -1 [32,] -1 s.m.test=function(s.m,i){which(s.m[,1] s.m.test(s.m,i=9) [1] 1 e.g. row.names(s.m)[s.m.test(s.m,i=9)] [1] group1 Cheers Christiaan On 1 June 2011 14:31, Jonathan Daily wrote: I am assuming in this case that you are looking for continuity along integers, so if you expect noninteger values this will not work. You can get the index of where breaks can be found in your example using which(diff(x) 1) On Wed, Jun 1, 2011 at 6:27 AM, christiaan pauw wrote: Hallo Everybody Consider the following vector a=1:10 b=20:30 c=40:50 x=c(a,b,c) I need a function that can tell me that there are three set of continuos sequences and that the first is from 1:10, the second from 20:30 and the third from 40:50. In other words: a,b, and c. regards Christiaan [[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. -- === Jon Daily Technician === #!/usr/bin/env outside # It's great, trust me. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] interpolation and extremum location of a surface
Clement LAUZIN lauzin at hotmail.com writes: Hello, Hello, I have a x,y,z file.Z is not corresponding to a simple analytical function of x and y (see below). I am trying to find the minimum location of this surface and the z value corresponding to this location by a spline interpolation or from a polynomial fit. I tried with the akima package but as the location of the point I am looking for (the minimum) is outside of the convex hull it's not giving any answer. If someone has any idea or any suggestion? Thank you in advance Pierre According to a 2-dimensional barycentric Lagrange interpolation that I am implementing right now in R, the minimum appears to be at x0 = (4.230490, 68.52776); fval = -175.7959 I certainly would be interested to hear from other reasonable locations of a minimum, as this may be a good test case. -- Hans Werner xyz 4.1 60 -152.1719593 [ ... ] 4.35 90 -163.8389615 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Anyone have experience with kinship pedigree plot?
Hello, I am using the Kinship package to draw a pedigree plot. I am trying to control the spacing between individuals in the pedigree. Currently, it is drawing a pedigree with too little space, so the text is overlapping. I'd like to increase the distance between individuals. According to the documentation, I would expect the following to be relevant: http://rss.acs.unt.edu/Rdoc/library/kinship/html/plot.pedigree.html symbolsize controls symbolsize. Default=1. width default=8. For a packed pedigree, the minimum width allowed in the realignment of pedigrees. density defines density used in the symbols. Takes up to 4 different values. mar no comment(s) my pedigree command is similar to: plot(ptemp, width=5, symbolsize=1); however, 'width', doesnt seem to actually do anything as far as I can see (ie. the plot looks the same no matter what value I use). the example command in the kinship doc uses: plot(x, id=x$id, sex=x$sex, status=x$status, affected=x$affected, cex=1, col=rep(1, length(x$id)), symbolsize=1, branch=0.6, packed=T, align=packed, width=8, density=c(-1, 50,70,90), mar=c(4.1,1,4.1,1), angle=c(90, 70, 50, 0), keep.par=F, ...) when I try density params similar to their example, it also does not obviously do anything. I could not find documentation on exactly what those do either. does anyone have any experience with pedigree plots, other suggestions or tips on where else I should be looking? thanks for the help. -ben __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] interpolation and extremum location of a surface
On Jun 1, 2011, at 9:24 AM, Clement LAUZIN wrote: Hello, I have a x,y,z file.Z is not corresponding to a simple analytical function of x and y (see below). I am trying to find the minimum location of this surface and the z value corresponding to this location by a spline interpolation or from a polynomial fit. I tried with the akima package but as the location of the point I am looking for (the minimum) is outside of the convex hull it's not giving any answer. I do not think that is the reason akima::interp is failing. (For one thing the minimum is not outside the convex hull of x and y.) Note that the help page says that x and y cannot be collinear but yours appear to be so. table(ZZ$x) 4.05 4.1 4.15 4.2 4.25 4.3 4.35 5555555 table(ZZ$y) 60 67.5 75 82.5 90 77777 I took a shot at jittering the x and y and reapplying interpp ... and ended up with what appeared to be useless junk. If you look at the data with contourplot you can see it would place the minimum at around z=-175 at x=4.24, y=67. However, the contourplot and associated help pages say there is no documentation for the algorithm used. contourplot(z ~ x + y, data=ZZ, at=seq(-140, -180 , by= -0.5), interp=TRUE) If someone has any idea or any suggestion? Thank you in advance Pierre xyz 4.1 60 -152.1719593 4.1 75 -171.136801 4.1 90 -170.4604774 4.2 60 -168.7745552 4.2 75 -174.9667333 4.2 90 -172.1853334 4.3 60 -173.7736418 4.3 75 -171.6712745 4.3 90 -167.6662458 4.05 60 -137.8379387 4.15 60 -162.2264066 4.25 60 -172.4453286 4.35 60 -173.2123715 4.05 67.5 -158.8239625 4.1 67.5 -167.314534 4.15 67.5 -172.586182 4.2 67.5 -175.2217594 4.25 67.5 -175.7162683 4.3 67.5 -174.4890566 4.35 67.5 -171.8940061 4.05 75 -165.4388778 4.15 75 -174.1460392 4.25 75 -174.022344 4.35 75 -168.2149168 4.05 82.5 -166.4026077 4.1 82.5 -170.9199652 4.15 82.5 -172.9923449 4.2 82.5 -173.0803255 4.25 82.5 -171.5739101 4.3 82.5 -168.8024715 4.35 82.5 -165.0431276 4.05 90 -166.2592978 4.15 90 -172.2861302 4.25 90 -170.5383652 4.35 90 -163.8389615 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Memory management
I am trying to run a very large Bradley-Terry model using the BradleyTerry2 package. (There are 288 players in the BT model). My problem is that I ran the model below successfully. WLMat is a win-loss matrix that is 288 by 288 WLdf-countsToBinomial(WLMat) mod1-BTm(cbind(win1,win2),player1,player2,~player,id=player,data=WLdf) Then I needed to run the same model with a subset of the observations that went into the win-loss matrix. So I created my new win-loss matrix and tried to run a new model. Now I get: Error: cannot allocate vector of size 90.5 Mb I found this particularly puzzling because the actual input data is the same size as the original model, just different values. I tried increasing memory size, I tried running it in a clean workspace and the error message is always the same (sometimes the vector it is trying to allocate is 181.0MB (twice as large)) but it is always one of those two numbers no matter what I have done to the available memory. To further complicate this...I cannot get the system to re-run my first model either . Same errors. traceback indicates that the error occurs when the program is trying to do a qr decomposition. R 2.13.0 Windows XP Any suggestions? W. Michael Conklin Chief Methodologist Google Voice: (612) 56STATS MarketTools, Inc. | www.markettools.comhttp://www.markettools.com 6465 Wayzata Blvd | Suite 170 | St. Louis Park, MN 55426. PHONE: 952.417.4719 | CELL: 612.201.8978 This email and attachment(s) may contain confidential and/or proprietary information and is intended only for the intended addressee(s) or its authorized agent(s). Any disclosure, printing, copying or use of such information is strictly prohibited. If this email and/or attachment(s) were received in error, please immediately notify the sender and delete all copies [[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] MAP datafile
Hi, I have a MAP datafile with SNP data and would like to open it and run say fisher's exact test and save the p-values. Anyone has any idea how this can be done? -- Thanks, Jim. [[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] Recode numbers
Lisa wrote: Dear all, I have two sets of numbers that look like a - c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3, 4) b - c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, 19) I just want to use “b” to encode “a” so that “a” looks like a1- c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13, 13, 17, 18, 2, 4, 15, 19) Does anyone have a suggestion how to deal with this? Thank you in advance. Lisa is a1 = b[a] what you are looking for? HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Recode-numbers-tp3566395p3566505.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Recode numbers
Dear all, I have two sets of numbers that look like a - c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3, 4) b - c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, 19) I just want to use “b” to encode “a” so that “a” looks like a1- c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13, 13, 17, 18, 2, 4, 15, 19) Does anyone have a suggestion how to deal with this? Thank you in advance. Lisa -- View this message in context: http://r.789695.n4.nabble.com/Recode-numbers-tp3566395p3566395.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] lattice panel fine control
Hello R experts, what follows is my reproducible example: mydata-structure(list(ped.avg = c(335.9, 110.8, 645.7, 638.9, 1468.1, 126.4, 4811.1, 88.5, 868.5, 656.6, 723.6, 654, 2.8, 15, 14.2, 17.5, 15.4, 112.1, 424.7, 18.3, 19.9, 28.6, 25.6, 23.5, 15.4, 27, 62.1, 15.6, 74.6), ped.erst = c(96, 53.2, 615.2, 616.5, 512.9, 56.2, 1851.8, 57.1, 579.5, 613.2, 601.1, 613.6, 1.3, 6.3, 6.5, 6.1, 6.3, 42, 166.4, 6.5, 6.5, 7.6, 8, 7, 6.3, 8.8, 24.6, 6.3, 35.6), tv.avg = c(670.4, 320, 282.4, 266.6, 2077.3, 383.1, 7116, 335.1, 642.9, 291, 405.1, 280.8, 5, 18.5, 16.5, 28.6, 24.8, 150.2, 366, 40.3, 38.4, 51.9, 52.9, 48.1, 27.8, 73.8, 168.3, 32.8, 151.2 ), tv.erst = c(233.8, 243.4, 245.9, 246.4, 389.9, 240.4, 1530.7, 242.8, 232.4, 245.1, 239.7, 245.7, 2.2, 6.9, 6, 11.5, 9.5, 69.5, 139.5, 17.9, 16.7, 22.9, 27.3, 24.5, 12.7, 46.3, 102.2, 15.7, 71.2), family = structure(c(1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L), .Label = c(non-orto PCB, non-orto PCB, non-orto PCB, non-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, PCDD, PCDD, PCDD, PCDD, PCDD, PCDD, PCDD, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF), class = factor), name = structure(c(28L, 29L, 22L, 26L, 18L, 19L, 20L, 21L, 23L, 24L, 25L, 27L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L), .Label = c(D4, D5, D6a, D6b, D6c, D7, D8, F4, F5a, F5b, F6a, F6b, F6c, F6d, F7a, F7b, F8, P105, P114, P118, P123, P126, P156, P157, P167, P169, P189, P77, P81), class = factor), ped.lower = c(239.9, 57.6, 30.5, 22.400, 955.2, 70.2, 2959.3, 31.4, 289, 43.4, 122.5, 40.4, 1.5, 8.7, 7.7, 11.4, 9.1, 70.1, 258.3, 11.8, 13.4, 21, 17.6, 16.5, 9.1, 18.2, 37.5, 9.3, 39), ped.upper = c(431.9, 164, 1260.9, 1255.4, 1981, 182.6, 6662.9, 145.6, 1448, 1269.8, 1324.7, 1267.6, 4.1, 21.3, 20.7, 23.6, 21.7, 154.1, 591.1, 24.8, 26.4, 36.2, 33.6, 30.5, 21.7, 35.8, 86.7, 21.9, 110.2 ), tv.lower = c(436.6, 76.6, 36.5, 20.2, 1687.4, 142.7, 5585.3, 92.3, 410.5, 45.9, 165.4, 35.1, 2.8, 11.6, 10.5, 17.1, 15.3, 80.7, 226.5, 22.4, 21.7, 29, 25.6, 23.6, 15.1, 27.5, 66.1, 17.1, 80), tv.upper = c(904.2, 563.4, 528.3, 513, 2467.2, 623.5, 8646.7, 577.9, 875.3, 536.1, 644.8, 526.5, 7.2, 25.4, 22.5, 40.1, 34.3, 219.7, 505.5, 58.2, 55.1, 74.8, 80.2, 72.6, 40.5, 120.1, 270.5, 48.5, 222.4)), .Names = c(ped.avg, ped.erst, tv.avg, tv.erst, family, name, ped.lower, ped.upper, tv.lower, tv.upper), row.names = c(NA, -29L), class = data.frame) and this is the code I worked so far (in order to clear out what is the final result I would like to get) mydata$family - factor(mydata$family, levels=as.character(mydata$family)) library(lattice) myplot-xyplot(ped.avg ~ tv.avg | family, data=mydata, strip=strip.custom(bg='white'), col.line=1, main=title, xlab=tv [fg/m3], ylab=ped [fg/m3], scales= list(x=list(relation=free, log=TRUE), y=list(relation=free, log=TRUE)), ) update(myplot, xlim=list(c(1.9,3),c(2,3.8),c(0.5,2.7),c(1.2,2.4)), ylim=list(c(1.9,3),c(2,3.8),c(0.5,2.7),c(1.2,2.4)), cex=0.6, aspect=iso, panel=function(...){ panel.abline(a=0, b=1, lty=1, col=1) } ) obviously there is something wrong in the resulting chart and therefore these are my questions: 1- how to draw a diagonal lines in each of the panels without “deleting” points? (in my example the use of panel.abline is somehow getting rid of the points) 2- how to label points with the “name”? (no clue for this) 3- how to draw error bar points referring of both x and y axes? (no clue for this) 4- how to format axes tickmark labels with a scientific notation? (no clue for this) 5- how to list all these commands inside xyplot() without the need to use update()? (for some reasons I do not fully understand I can not ‘move’ all commands inside the main plotting– xyplot() - without loosing some relevant features of the chart) any help much appreciated sorry for such trivial question but I’m using R since a very short time: please keep your replies as much simple and self explanatory as possible thank you maxbre -- View this message in context: http://r.789695.n4.nabble.com/lattice-panel-fine-control-tp3566347p3566347.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Qs on vector of lists, etc.
I'm pretty new to R, so please forgive the cluelessness of these questions. Is it true that it is not possible to have a vector or lists in R? Is a list of lists the closest one can get to a vector of lists? Is it possible to have a matrix of lists in R? Or an array of lists? Thanks! Roy [[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] xtable with conditional formatting using \textcolor
Hello list, I'm doing a table with scores and I want include colors to represent status of an individual. I'm using sweave results=tex= and xtable but I can't get a result I want. My attemps are #- # code R da - data.frame(id=letters[1:5], score=1:5*2) col - function(x){ ifelse(x7, paste(\textcolor{blue}{, formatC(x, dig=2, format=f), }), paste(\textcolor{red}{, formatC(x, dig=2, format=f), })) } da$score.string - col(da$score) require(xtable) xtable(da[,c(id,score.string)]) #- actual result #- \begin{tabular}{rll} \hline id score.string \\ \hline 1 a extcolor\{red\}\{ 2.00 \} \\ 2 b extcolor\{red\}\{ 4.00 \} \\ 3 c extcolor\{red\}\{ 6.00 \} \\ 4 d extcolor\{blue\}\{ 8.00 \} \\ 5 e extcolor\{blue\}\{ 10.00 \} \\ \hline \end{tabular} #- desired result (lines omited to save space) #- 1 a \textcolor{red}{ 2.00 } \\ 2 b \textcolor{red}{ 4.00} \\ #- Any contribution will be useful. Thanks. Walmes. == Walmes Marques Zeviani LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W) Departamento de Estatística - Universidade Federal do Paraná fone: (+55) 41 3361 3573 VoIP: (3361 3600) 1053 1173 e-mail: wal...@ufpr.br twitter: @walmeszeviani homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 == [[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] Recode numbers
Thank you for your help, Pete. I tried b[a], but it is not a1. -- View this message in context: http://r.789695.n4.nabble.com/Recode-numbers-tp3566395p3566534.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Replacing variables in one dataset with those from another
Hoping someone out there can help me...this seems like an easy task but I can't figure it out... I want to replace variables in one dataset (Dataset1) with a variable from another dataset (Dataset2). All the values for variables x1 and x2 in Dataset1 have a unique match to the variable uniquenum in Dataset2. For example, in Dataset1 grpnum A has a value of 343 for variable x1. In Dataset2, 343 will only be found once for variable uniquenum. I would like to create a new dataset where the variable x1 from Dataset1 will be replaced by uniqueid from Dataset2. So variable x1 for grpnum A now would equal GHU82RK02HD7D6 rather than 343. Below is an abbreviated example from my datasets to show what I’m trying to do rather than explain in words because I’m not sure my question is coming across very clearly. I have about 100 columns in Dataset1 (x1, x2, etc.) and the variable uniquenum in Dataset2 has about 4,000 values. Dataset1 grpnum x1 x2 A 343 334 B 313 898 C 40764077 D 275 276 Dataset2 unique num uniqueid 343 GHU82RK02HD7D6 4076GHU82RK02IXPC7 4077GHU82RK02HICZ2 261 GHU82RK02FLOFU 4100GHU82RK02IDO7K 4101GHU82RK02HQYQL 4102GHU82RK02GADV1 4103GHU82RK02G7RQH 4104GHU82RK02HQD2E NewDataset grpnum x1 x2 a GHU82RK02HD7D6Na b Na Na c GHU82RK02IXPC7 GHU82RK02HICZ2 d Na Na Thanks for your time and thoughts. I hope someone can help! -- View this message in context: http://r.789695.n4.nabble.com/Replacing-variables-in-one-dataset-with-those-from-another-tp3566552p3566552.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lattice panel fine control
It is perhaps not entirely clear from ?update, but update replaces your original lattice call with your new call and re-drawsthe plot. This means that the panel function used for the update() plot is the one in update(), which only draws the line. That's why you see no points. Obviously, then, you need to include both points and abline in your panel call to get both. However, if you would like to follow the strategy that you have indicated, you can do so by using the layer() functionality in the lattceExtra package, in which you would do something similar to what you have shown. library(latticeExtra) ## after you have installed it from CRAN, possibly ?layer for further info. Your numerous other questions can be answered by close reading of the ?xyplot Help file and/or adding additional functionality to your panel call. For example, text can be added via the panel.text() function. ?lattice will get you info on this and other low level graphics functionality, as well as references to consult. I would also suggest Deepayan Sarkar's book, if you intend to use lattice seriously. Cheers, Bert On Wed, Jun 1, 2011 at 10:00 AM, maxbre mbres...@arpa.veneto.it wrote: Hello R experts, what follows is my reproducible example: mydata-structure(list(ped.avg = c(335.9, 110.8, 645.7, 638.9, 1468.1, 126.4, 4811.1, 88.5, 868.5, 656.6, 723.6, 654, 2.8, 15, 14.2, 17.5, 15.4, 112.1, 424.7, 18.3, 19.9, 28.6, 25.6, 23.5, 15.4, 27, 62.1, 15.6, 74.6), ped.erst = c(96, 53.2, 615.2, 616.5, 512.9, 56.2, 1851.8, 57.1, 579.5, 613.2, 601.1, 613.6, 1.3, 6.3, 6.5, 6.1, 6.3, 42, 166.4, 6.5, 6.5, 7.6, 8, 7, 6.3, 8.8, 24.6, 6.3, 35.6), tv.avg = c(670.4, 320, 282.4, 266.6, 2077.3, 383.1, 7116, 335.1, 642.9, 291, 405.1, 280.8, 5, 18.5, 16.5, 28.6, 24.8, 150.2, 366, 40.3, 38.4, 51.9, 52.9, 48.1, 27.8, 73.8, 168.3, 32.8, 151.2 ), tv.erst = c(233.8, 243.4, 245.9, 246.4, 389.9, 240.4, 1530.7, 242.8, 232.4, 245.1, 239.7, 245.7, 2.2, 6.9, 6, 11.5, 9.5, 69.5, 139.5, 17.9, 16.7, 22.9, 27.3, 24.5, 12.7, 46.3, 102.2, 15.7, 71.2), family = structure(c(1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L), .Label = c(non-orto PCB, non-orto PCB, non-orto PCB, non-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, mono-orto PCB, PCDD, PCDD, PCDD, PCDD, PCDD, PCDD, PCDD, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF, PCDF), class = factor), name = structure(c(28L, 29L, 22L, 26L, 18L, 19L, 20L, 21L, 23L, 24L, 25L, 27L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L), .Label = c(D4, D5, D6a, D6b, D6c, D7, D8, F4, F5a, F5b, F6a, F6b, F6c, F6d, F7a, F7b, F8, P105, P114, P118, P123, P126, P156, P157, P167, P169, P189, P77, P81), class = factor), ped.lower = c(239.9, 57.6, 30.5, 22.400, 955.2, 70.2, 2959.3, 31.4, 289, 43.4, 122.5, 40.4, 1.5, 8.7, 7.7, 11.4, 9.1, 70.1, 258.3, 11.8, 13.4, 21, 17.6, 16.5, 9.1, 18.2, 37.5, 9.3, 39), ped.upper = c(431.9, 164, 1260.9, 1255.4, 1981, 182.6, 6662.9, 145.6, 1448, 1269.8, 1324.7, 1267.6, 4.1, 21.3, 20.7, 23.6, 21.7, 154.1, 591.1, 24.8, 26.4, 36.2, 33.6, 30.5, 21.7, 35.8, 86.7, 21.9, 110.2 ), tv.lower = c(436.6, 76.6, 36.5, 20.2, 1687.4, 142.7, 5585.3, 92.3, 410.5, 45.9, 165.4, 35.1, 2.8, 11.6, 10.5, 17.1, 15.3, 80.7, 226.5, 22.4, 21.7, 29, 25.6, 23.6, 15.1, 27.5, 66.1, 17.1, 80), tv.upper = c(904.2, 563.4, 528.3, 513, 2467.2, 623.5, 8646.7, 577.9, 875.3, 536.1, 644.8, 526.5, 7.2, 25.4, 22.5, 40.1, 34.3, 219.7, 505.5, 58.2, 55.1, 74.8, 80.2, 72.6, 40.5, 120.1, 270.5, 48.5, 222.4)), .Names = c(ped.avg, ped.erst, tv.avg, tv.erst, family, name, ped.lower, ped.upper, tv.lower, tv.upper), row.names = c(NA, -29L), class = data.frame) and this is the code I worked so far (in order to clear out what is the final result I would like to get) mydata$family - factor(mydata$family, levels=as.character(mydata$family)) library(lattice) myplot-xyplot(ped.avg ~ tv.avg | family, data=mydata, strip=strip.custom(bg='white'), col.line=1, main=title, xlab=tv [fg/m3], ylab=ped [fg/m3], scales= list(x=list(relation=free, log=TRUE), y=list(relation=free, log=TRUE)), ) update(myplot, xlim=list(c(1.9,3),c(2,3.8),c(0.5,2.7),c(1.2,2.4)), ylim=list(c(1.9,3),c(2,3.8),c(0.5,2.7),c(1.2,2.4)), cex=0.6, aspect=iso, panel=function(...){ panel.abline(a=0, b=1, lty=1, col=1) } ) obviously there is something wrong in the resulting chart and therefore these are my questions: 1- how to draw a diagonal lines in each of the panels without “deleting” points? (in my example the use of panel.abline is somehow getting rid of the points)
Re: [R] xtable with conditional formatting using \textcolor
On Jun 1, 2011, at 1:33 PM, Walmes Zeviani wrote: Hello list, I'm doing a table with scores and I want include colors to represent status of an individual. I'm using sweave results=tex= and xtable but I can't get a result I want. My attemps are #- # code R da - data.frame(id=letters[1:5], score=1:5*2) col - function(x){ ifelse(x7, paste(\textcolor{blue}{, formatC(x, dig=2, format=f), }), paste(\textcolor{red}{, formatC(x, dig=2, format=f), })) } da$score.string - col(da$score) require(xtable) xtable(da[,c(id,score.string)]) #- actual result #- \begin{tabular}{rll} \hline id score.string \\ \hline 1 a extcolor\{red\}\{ 2.00 \} \\ 2 b extcolor\{red\}\{ 4.00 \} \\ 3 c extcolor\{red\}\{ 6.00 \} \\ 4 d extcolor\{blue\}\{ 8.00 \} \\ 5 e extcolor\{blue\}\{ 10.00 \} \\ \hline \end{tabular} #- desired result (lines omited to save space) #- 1 a \textcolor{red}{ 2.00 } \\ 2 b \textcolor{red}{ 4.00} \\ #- Any contribution will be useful. Thanks. Walmes. When the '\t' is being cat()'d to the TeX file (or console) by print.xtable(), it is being interpreted as a tab character. You need to escape it with additional backslashes and then adjust the sanitize.text.function in print.xtable() so that it does not touch the backslashes: da - data.frame(id=letters[1:5], score=1:5*2) col - function(x){ ifelse(x7, paste(\\textcolor{blue}{, formatC(x, dig=2, format=f), }), paste(\\textcolor{red}{, formatC(x, dig=2, format=f), })) } da$score.string - col(da$score) da id score score.string 1 a 2 \\textcolor{red}{ 2.00 } 2 b 4 \\textcolor{red}{ 4.00 } 3 c 6 \\textcolor{red}{ 6.00 } 4 d 8 \\textcolor{blue}{ 8.00 } 5 e10 \\textcolor{blue}{ 10.00 } require(xtable) print(xtable(da[,c(id,score.string)]), sanitize.text.function = function(x){x}) That will give you: % latex table generated in R 2.13.0 by xtable 1.5-6 package % Wed Jun 1 13:44:54 2011 \begin{table}[ht] \begin{center} \begin{tabular}{rll} \hline id score.string \\ \hline 1 a \textcolor{red}{ 2.00 } \\ 2 b \textcolor{red}{ 4.00 } \\ 3 c \textcolor{red}{ 6.00 } \\ 4 d \textcolor{blue}{ 8.00 } \\ 5 e \textcolor{blue}{ 10.00 } \\ \hline \end{tabular} \end{center} \end{table} 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] Recode numbers
(The attributions are a little messed up here:) I have two sets of numbers that look like a- c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3, 4) b- c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, 19) I just want to use “b” to encode “a” so that “a” looks like a1- c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13, 13, 17, 18, 2, 4, 15, 19) Does anyone have a suggestion how to deal with this? Thank you in advance. is a1 = b[a] what you are looking for? HTH Pete Thank you for your help, Pete. I tried b[a], but it is not a1. I think you'll need to explain the rule used for a1[9], a1[10], etc. 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] xtable with conditional formatting using \textcolor
Marc, Thank you very much. You gave exactly what I wanted. Bests. Walmes. == Walmes Marques Zeviani LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W) Departamento de Estatística - Universidade Federal do Paraná fone: (+55) 41 3361 3573 VoIP: (3361 3600) 1053 1173 e-mail: wal...@ufpr.br twitter: @walmeszeviani homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 == [[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] BiodiversityR GUI on macosx
Dear List! I installed R and quite a few packages I use. When I try to start BiodiversityR the library loads without any problems but GUI do not start. Rcmdr loads without any problems. I am using R 2.13.0 64 bit. Downgrade to R 2.12.2 works. Thanks, Janos __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Qs on vector of lists, etc.
On 01.06.2011 18:59, Roy Shimizu wrote: I'm pretty new to R, so please forgive the cluelessness of these questions. Is it true that it is not possible to have a vector or lists in R? Is a list of lists the closest one can get to a vector of lists? Actually a list is a vector of mode list. Hence if you have a list of lists, it *is* a vector of lists and behaves consistantly (e.g. when subsetiing with [] rather than [[]]). L - list(list(a=1, b=2), list(c=3, d=4)) L[1] # L can be considered a vector of mode list. Is it possible to have a matrix of lists in R? Or an array of lists? Yes: X - matrix(L, nrow=2) X[1,1] X[2,1] or even: dim(X) - c(1,2,1) mode(X) # list class(X) # array Uwe Ligges Thanks! Roy [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] weird error from MASS::eqcsplot with postscript driver
[Env: R 2.12.2, Win XP] I'm creating figures using MASS::eqcsplot to provide equal scaling of the axes. My figures work OK when I plot to the screen, but when I try to do the same plot as a postscript file, I get an unexplicable error, figframe() Error in if (yuin xuin * ratio) yuin - xuin * ratio else xuin - yuin/ratio : missing value where TRUE/FALSE needed traceback() 2: eqscplot(x = 0, y = 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab, type = n) 1: figframe() Here is a minimal source script exhibiting the problem: library(MASS) eps - function(file=Rplot.eps, horizontal=FALSE, paper=special, ...) { postscript(file=file, onefile=FALSE, horizontal=horizontal, paper=paper, ...) } # Figure frame figframe - function( xlim = c(-3,3), ylim = c(-3,3), xlab = '', ylab = '') { eqscplot( x=0,y=0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab, type = 'n') abline( v=0, col=gray) abline( h=0, col=gray) } # screen: OK op - par(mar=c(3, 3, 1, 1) + 0.4) figframe() par(op) # eps: fails eps(file=test1.eps) op - par(mar=c(3, 3, 1, 1) + 0.4) figframe() par(op) dev.off() I know this worked under an earlier version, probably ~ R 2.9.x -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] as.character limits length of result for formula
If you want a character representation of a long formula (or a formula with long names), you can use: as.character(my.formula) However restriction on length of an as.character result returns only the beginning of a long formula, and without comment. In most cases, the following expression provides the complete result: paste(my.formula[[2]], ~ , paste(attr(terms(my.formula), term.labels),collapse= + ),sep=) It would be better to make as.character handle any size formula. [[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] Force the for loop to stop
Hi, I am looking for a command in R that would force the for loop to stop after it finds what it is looking for. As an example for(i in 1:5){ for(j in 3:6){ if(i==j) # do something... break; } } And i don't want the loop to execute once i = 3 and stop. Is there a way to do this? best, salih [[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] Force the for loop to stop
Hi, you could set a dummy variable to FALSE outside the outermost loop. If the break condition is met in the inner loop, set the dummy variable to TRUE before breaking and test its truth status in the outer loop. HTH Stephan Am 01.06.2011 21:25, schrieb Salih Tuna: Hi, I am looking for a command in R that would force the for loop to stop after it finds what it is looking for. As an example for(i in 1:5){ for(j in 3:6){ if(i==j) # do something... break; } } And i don't want the loop to execute once i = 3 and stop. Is there a way to do this? best, salih [[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] as.character limits length of result for formula
as.character() doesn't give a faithful character representation of its input for lots of language- related inputs. E.g., f - reformulate(paste(sep=,X,1:500), quote(log(Y))) cat(strwrap(as.character(f), 60), sep=\n) ~ log(Y) X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + X11 + X12 + X13 + X14 + X15 + X16 + X17 + X18 + X19 + X20 + X21 + X22 + X23 + X24 + X25 + X26 + X27 + X28 + X29 + X30 + X31 + X32 + X33 + X34 + X35 + X36 + X37 + X38 + X39 + X40 + X41 + X42 + X43 + X44 + X45 + X46 + X47 + X48 + X49 + X50 + X51 + X52 + X53 + X54 + X55 + X56 + X57 + X58 + X59 + X60 + X61 + X62 + X63 + X64 + X65 + X66 + X67 + X68 + X69 + X70 + X71 + X72 + X73 + X74 + X75 + X76 + X77 + X78 + X79 + X80 + X81 + X82 + X83 + X84 + X85 + (Yes, there is nothing after the X85 +.) deparse() works better for such objects. You may want to use paste(collapse=\n) on its output to make a single string. deparse(f) [1] log(Y) ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + X11 + [2] X12 + X13 + X14 + X15 + X16 + X17 + X18 + X19 + X20 + X21 + ... lots of text omitted ... [53] X480 + X481 + X482 + X483 + X484 + X485 + X486 + X487 + X488 + [54] X489 + X490 + X491 + X492 + X493 + X494 + X495 + X496 + X497 + [55] X498 + X499 + X500 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Terrence Ireland Sent: Wednesday, June 01, 2011 12:19 PM To: r-help@r-project.org Subject: [R] as.character limits length of result for formula If you want a character representation of a long formula (or a formula with long names), you can use: as.character(my.formula) However restriction on length of an as.character result returns only the beginning of a long formula, and without comment. In most cases, the following expression provides the complete result: paste(my.formula[[2]], ~ , paste(attr(terms(my.formula), term.labels),collapse= + ),sep=) It would be better to make as.character handle any size formula. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Contributed Packages - Hmisc survey
Hello List, Could someone tell why I can't install the Himsc and survey packages for R version 2.13.0 (2011-04-13)? What am I doing wrong here? Thanks, Pradip install.packages (Hmisc, dependencies=TRUE) --- Please select a CRAN mirror for use in this session --- Warning: unable to access index for repository http://watson.nci.nih.gov/cran_mirror/bin/windows/contrib/2.13 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package 'Hmisc' is not available (for R version 2.13.0) install.packages (survey, dependencies=TRUE) Warning: unable to access index for repository http://watson.nci.nih.gov/cran_mirror/bin/windows/contrib/2.13 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package 'survey' is not available (for R version 2.13.0) Pradip K. Muhuri, PhD Statistician Substance Abuse Mental Health Services Administration The Center for Behavioral Health Statistics and Quality Division of Population Surveys 1 Choke Cherry Road, Room 7-1023 Rockville, MD 20857 Tel: 240-276-1070 Fax: 240-276-1260 e-mail: pradip.muh...@samhsa.hhs.govmailto:pradip.muh...@samhsa.hhs.gov The Center for Behavioral Health Statistics and Quality your feedback. Please click on the following link to complete a brief customer survey: http://cbhsqsurvey.samhsa.gov [[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] Recode numbers
Thank you, Duncan, Here “a” has the length of 24, and “b” has the length of 20 with numbers from 1 to 20 uniquely. I just want encode “a” from 1 to 20 based on “a” current order using “b”. So, a1[1] = b[1] = 1 a1[2] = b[2] = 5 a1[3] = a1[4] = b[3] = 8 (since third and fourth numbers are the same in “a”) a1[5] = a1[6] = b[4] = 9 a1[7] = b[5] = 14 a1[8] = b[6] = 20 a1[9] = b[7] = 3 a1[10] = a1[11] = b[8] = 10 ... a1[23] = b[19] = 15 a1[24] = b[20] = 19 -- View this message in context: http://r.789695.n4.nabble.com/Recode-numbers-tp3566395p3566681.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problems with copula
Hi, I'd like to know why using the program R I can't add a number of margins 3, I have a problem with the graphics. Post here my script: myCop.norm - ellipCopula(family = normal, dim = 3, param = 0.4) myMvd - mvdc(copula = myCop.norm, margins = c(norm, norm,norm), paramMargins = list(list(mean = 0, sd = 2), list(mean = 0, sd = 1),list(mean=0,sd=2))) persp(myMvd, dmvdc, xlim = c(-4, 4), ylim=c(-4, 4),main=Normal copula) I obtain the following message of error : Error in eval index out of bound Help me thanks http://r.789695.n4.nabble.com/file/n3566629/Cattura.jpg -- View this message in context: http://r.789695.n4.nabble.com/problems-with-copula-tp3566629p3566629.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RES: Recode numbers
---BeginMessage--- I think this is proper. a - c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3, 4) b - c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, 19) ref - 1 for (i in 2:length(a)) { if (a[i]!=a[i-1]) ref - c(ref, ref[length(ref)]+1) if (a[i]==a[i-1]) ref - c(ref, ref[length(ref)]) } a2 -b[ref] a1 - c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13, 13, 17, 18, 2, 4, 15, 19) a1=¢ -Mensagem original- De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Em nome de Duncan Murdoch Enviada em: quarta-feira, 1 de junho de 2011 15:51 Para: Lisa Cc: r-help@r-project.org Assunto: Re: [R] Recode numbers (The attributions are a little messed up here:) I have two sets of numbers that look like a- c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3, 4) b- c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, 19) I just want to use b to encode a so that a looks like a1- c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13, 13, 17, 18, 2, 4, 15, 19) Does anyone have a suggestion how to deal with this? Thank you in advance. is a1 = b[a] what you are looking for? HTH Pete Thank you for your help, Pete. I tried b[a], but it is not a1. I think you'll need to explain the rule used for a1[9], a1[10], etc. 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. ---End Message--- This message and its attachments may contain confidential and/or privileged information. If you are not the addressee, please, advise the sender immediately by replying to the e-mail and delete this message. Este mensaje y sus anexos pueden contener información confidencial o privilegiada. Si ha recibido este e-mail por error por favor bórrelo y envíe un mensaje al remitente. Esta mensagem e seus anexos podem conter informação confidencial ou privilegiada. Caso não seja o destinatário, solicitamos a imediata notificação ao remetente e exclusão da mensagem.__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Function to save plots
Hello, I'm using ROCR to plot ROC Curves and I want to automate the saving of plots into PNG files using a custom function. My data frames are named like test1, test2, test3. Each data frame has three variables: method1, method2, goldstandard. Right now, for each plot I have to run: png('test1_method1.png') plot(performance(prediction(test1$method1, test1$goldstandard), tpr, fpr)) dev.off() Here is the function I tried to create but I failed: roc - function(arg1, arg2){ png(paste(arg1, arg2, png, sep=_)) plot(performance(prediction(arg1$arg2, arg1$goldstandard), tpr, fpr)) dev.off() } I wanted to pass the test name as arg1, and the method name as arg2. Here are my problems: 1) arg1$arg2 causes an error message. How can I use a function argument to address a variable in a dataframe? 2) paste(arg1, arg2, png, sep=.) doesn't output something like 'test1.method1.png'. How should I deal with that? Thanks in advance. [[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] Force the for loop to stop
Hi Stephan, Thanks a lot. But i am not very good at R yet so i dont know how to set the dummy variable to FALSE. Can you please help me with that as well? On Wed, Jun 1, 2011 at 8:34 PM, Stephan Kolassa stephan.kola...@gmx.dewrote: Hi, you could set a dummy variable to FALSE outside the outermost loop. If the break condition is met in the inner loop, set the dummy variable to TRUE before breaking and test its truth status in the outer loop. HTH Stephan Am 01.06.2011 21:25, schrieb Salih Tuna: Hi, I am looking for a command in R that would force the for loop to stop after it finds what it is looking for. As an example for(i in 1:5){ for(j in 3:6){ if(i==j) # do something... break; } } And i don't want the loop to execute once i = 3 and stop. Is there a way to do this? best, salih [[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] Force the for loop to stop
Hi Salih, here you go: dummy - FALSE for ( ii in 1:5 ) { for ( jj in 3:6 ) { cat(ii=,ii,; jj=,jj,\n,sep=) if ( ii == jj ) { dummy - TRUE break } } if ( dummy ) break } ### Note that I am using ii and jj as loop indices, not i and j. This makes it a lot easier to search for the loop counter in more complex scripts - if you just search for i, most of your hits will be something else than the loop counter. HTH, Stephan Am 01.06.2011 22:06, schrieb Salih Tuna: Hi Stephan, Thanks a lot. But i am not very good at R yet so i dont know how to set the dummy variable to FALSE. Can you please help me with that as well? On Wed, Jun 1, 2011 at 8:34 PM, Stephan Kolassastephan.kola...@gmx.dewrote: Hi, you could set a dummy variable to FALSE outside the outermost loop. If the break condition is met in the inner loop, set the dummy variable to TRUE before breaking and test its truth status in the outer loop. HTH Stephan Am 01.06.2011 21:25, schrieb Salih Tuna: Hi, I am looking for a command in R that would force the for loop to stop after it finds what it is looking for. As an example for(i in 1:5){ for(j in 3:6){ if(i==j) # do something... break; } } And i don't want the loop to execute once i = 3 and stop. Is there a way to do this? best, salih [[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] Recode numbers
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Lisa Sent: Wednesday, June 01, 2011 12:28 PM To: r-help@r-project.org Subject: Re: [R] Recode numbers Thank you, Duncan, Here a has the length of 24, and b has the length of 20 with numbers from 1 to 20 uniquely. I just want encode a from 1 to 20 based on a current order using b. So, a1[1] = b[1] = 1 a1[2] = b[2] = 5 a1[3] = a1[4] = b[3] = 8 (since third and fourth numbers are the same in a) a1[5] = a1[6] = b[4] = 9 a1[7] = b[5] = 14 a1[8] = b[6] = 20 a1[9] = b[7] = 3 a1[10] = a1[11] = b[8] = 10 ... a1[23] = b[19] = 15 a1[24] = b[20] = 19 I don't understand the verbal description, but the the following makes your example work: b[cumsum(c(TRUE,a[-1]!=a[-length(a)]))] [1] 1 5 8 8 9 9 14 20 3 10 10 12 6 16 7 11 13 13 [19] 17 18 2 4 15 19 identical(.Last.value, a1) [1] TRUE Is that what you want? The cumsum(...) increments each at each changepoint in a. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -- View this message in context: http://r.789695.n4.nabble.com/Recode-numbers-tp3566395p3566681.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Function to save plots
Hi Merik, I believe this does what you want (and maybe a little more): ## define the function, a1 and a2 correspond to your arguments ## d is the directory to save the file in (by default the working directory) ## ... are additional arguments that can be passed to png() to control things like quality, etc. roc - function(a1, a2, d = getwd(), ...) { ## someone wiser may know a better way, but I put dev.off() into on.exit() because ## otherwise, if the plot fails (say due to an error in prediction() or performance()) ## the device does not get shutdown otherwise, and the image is empty but still used by R on.exit(dev.off()) ## I use get() to deal with the fact that the dataset name is passed as a character dat - get(a1) png(filename = paste(d, /, a1, _, a2, .png, sep = ''), ...) plot(performance(prediction(dat[, a2], dat[, goldstandard]), tpr, fpr)) ## I like titles (if you don't need it, just delte this line) title(main = paste(a2, in dataset:, a1)) } ## Test dataset test1 - data.frame(method1 = rbinom(40, 1, .4), method2 = rbinom(40, 1, .4), goldstandard = rbinom(40, 1, .8)) ## Example Usage roc(a1 = test1, a2 = method1) roc(a1 = test1, a2 = method1, d = DRIVE:/AlternatePath) roc(a1 = test1, a2 = method1, width = 960, height = 960) Hope this helps, Josh On Wed, Jun 1, 2011 at 12:39 PM, Merik Nanish merik.nan...@gmail.com wrote: Hello, I'm using ROCR to plot ROC Curves and I want to automate the saving of plots into PNG files using a custom function. My data frames are named like test1, test2, test3. Each data frame has three variables: method1, method2, goldstandard. Right now, for each plot I have to run: png('test1_method1.png') plot(performance(prediction(test1$method1, test1$goldstandard), tpr, fpr)) dev.off() Here is the function I tried to create but I failed: roc - function(arg1, arg2){ png(paste(arg1, arg2, png, sep=_)) plot(performance(prediction(arg1$arg2, arg1$goldstandard), tpr, fpr)) dev.off() } I wanted to pass the test name as arg1, and the method name as arg2. Here are my problems: 1) arg1$arg2 causes an error message. How can I use a function argument to address a variable in a dataframe? 2) paste(arg1, arg2, png, sep=.) doesn't output something like 'test1.method1.png'. How should I deal with that? Thanks in advance. [[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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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] Force the for loop to stop
That is great Stephan, thanks a lot for your help. best, salih On Wed, Jun 1, 2011 at 9:18 PM, Stephan Kolassa stephan.kola...@gmx.dewrote: Hi Salih, here you go: dummy - FALSE for ( ii in 1:5 ) { for ( jj in 3:6 ) { cat(ii=,ii,; jj=,jj,\n,sep=) if ( ii == jj ) { dummy - TRUE break } } if ( dummy ) break } ### Note that I am using ii and jj as loop indices, not i and j. This makes it a lot easier to search for the loop counter in more complex scripts - if you just search for i, most of your hits will be something else than the loop counter. HTH, Stephan Am 01.06.2011 22:06, schrieb Salih Tuna: Hi Stephan, Thanks a lot. But i am not very good at R yet so i dont know how to set the dummy variable to FALSE. Can you please help me with that as well? On Wed, Jun 1, 2011 at 8:34 PM, Stephan Kolassastephan.kola...@gmx.de wrote: Hi, you could set a dummy variable to FALSE outside the outermost loop. If the break condition is met in the inner loop, set the dummy variable to TRUE before breaking and test its truth status in the outer loop. HTH Stephan Am 01.06.2011 21:25, schrieb Salih Tuna: Hi, I am looking for a command in R that would force the for loop to stop after it finds what it is looking for. As an example for(i in 1:5){ for(j in 3:6){ if(i==j) # do something... break; } } And i don't want the loop to execute once i = 3 and stop. Is there a way to do this? best, salih [[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] Problems Dating....
I'm trying to convert a column in a data frame with dates from a Factor type to a Date Object but I am encountering and error. (I am having trouble plotting an x,y scatter and I suspect it's something with my data format). I have a table with two columns and 8,000 rows. dsort=read.delim(C:\\Documents and Settings\\E066582\\My Documents\\R\\R-2.13.0\\bin\\dsort.txt) dsort#name of data.frame colnames(dsort)[1] #name of column 1 [1] Date colnames(dsort)[2] #name of column 2 [1] Qty class(dsort$Date) #checked data type of column Date and it came back as a factor [1] factor Date2=as.Date(dsort$Date)#attempt at changing the data type from a factor to a date object (see error below). Error in charToDate(x) : character string is not in a standard unambiguous format Dates in my table are listed in 3/4/2007 format. StatBat2 [[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] re-write plot function for ggplot
A useful way to get a feel for ggplot2 is to check out http://yeroon.net/ggplot2/ This site allows for a point-and-click ggplot2 graphs. You will not have all of the options from ggplot2 (e.g. themes), but it's a good place to get started. Also, there are some wonderful video tutorials in the help section. Cheers! -- John A. Ramey, M.S. Ph.D. Candidate Department of Statistics Baylor University http://www.johnramey.net On Wed, Jun 1, 2011 at 6:43 AM, rmje robinmje...@gmail.com wrote: Hi, I have the following function that i use to plot graphs. plot_mi_time = function(mdata, miname) { mdata2 = mdata[row.names(mir_test3) == miname, ] # print(mdata2) xcoords - c(1,1,2,2,3,3) plot(xcoords, mdata2, xaxt=n, ylab=Expression, xlab=Time(h), , main=miname) axis(1, at=xcoords, labels=c(a,a,b,b,c,c)) } I want to edit this function so that i can plot it using ggplot. Any suggestions on how to re-write it? -- View this message in context: http://r.789695.n4.nabble.com/re-write-plot-function-for-ggplot-tp3565868p3565868.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- John A. Ramey, M.S. Ph.D. Candidate Department of Statistics Baylor University http://www.johnramey.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] finding numbers in a range
Hi, Is there a quick way of finding if numbers in a vector falls in between a range defined in another matrix. As an example let x y 0 1 3 2 6 9 2515 18 I want to check one by one whether 0,2 and 25 falls in any of the ranges in y. I am using 2 for loops but it is taking a huge amount of time. is there any other alternative way to do this? best, salih [[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] weird error from MASS::eqcsplot with postscript driver
The problem is the ``paper=special '' specification in your eps() function. This makes par(pin), which eqcsplot() uses in its calculations, undefined. The ``value'' thus produced is: [1] NaN NaN Which makes perfect sense if you think about it. If you're going to use paper=special, you need to specify height and width. cheers, Rolf Turner On 02/06/11 07:17, Michael Friendly wrote: [Env: R 2.12.2, Win XP] I'm creating figures using MASS::eqcsplot to provide equal scaling of the axes. My figures work OK when I plot to the screen, but when I try to do the same plot as a postscript file, I get an unexplicable error, figframe() Error in if (yuin xuin * ratio) yuin - xuin * ratio else xuin - yuin/ratio : missing value where TRUE/FALSE needed traceback() 2: eqscplot(x = 0, y = 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab, type = n) 1: figframe() Here is a minimal source script exhibiting the problem: library(MASS) eps - function(file=Rplot.eps, horizontal=FALSE, paper=special, ...) { postscript(file=file, onefile=FALSE, horizontal=horizontal, paper=paper, ...) } # Figure frame figframe - function( xlim = c(-3,3), ylim = c(-3,3), xlab = '', ylab = '') { eqscplot( x=0,y=0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab, type = 'n') abline( v=0, col=gray) abline( h=0, col=gray) } # screen: OK op - par(mar=c(3, 3, 1, 1) + 0.4) figframe() par(op) # eps: fails eps(file=test1.eps) op - par(mar=c(3, 3, 1, 1) + 0.4) figframe() par(op) dev.off() I know this worked under an earlier version, probably ~ R 2.9.x __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Dating....
Hi Nat, I guess something like as.Date(as.character(3/4/2007),format=%d/%m/%Y) should work - as.character() coerces the factors to characters, which the as.Date() function can work with, given the right format argument. HTH Stephan Am 01.06.2011 22:59, schrieb Struckmeier, Nathanael: I'm trying to convert a column in a data frame with dates from a Factor type to a Date Object but I am encountering and error. (I am having trouble plotting an x,y scatter and I suspect it's something with my data format). I have a table with two columns and 8,000 rows. dsort=read.delim(C:\\Documents and Settings\\E066582\\My Documents\\R\\R-2.13.0\\bin\\dsort.txt) dsort#name of data.frame colnames(dsort)[1] #name of column 1 [1] Date colnames(dsort)[2] #name of column 2 [1] Qty class(dsort$Date) #checked data type of column Date and it came back as a factor [1] factor Date2=as.Date(dsort$Date)#attempt at changing the data type from a factor to a date object (see error below). Error in charToDate(x) : character string is not in a standard unambiguous format Dates in my table are listed in 3/4/2007 format. StatBat2 [[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] Problems Dating....
On Jun 1, 2011, at 3:59 PM, Struckmeier, Nathanael wrote: I'm trying to convert a column in a data frame with dates from a Factor type to a Date Object but I am encountering and error. (I am having trouble plotting an x,y scatter and I suspect it's something with my data format). I have a table with two columns and 8,000 rows. dsort=read.delim(C:\\Documents and Settings\\E066582\\My Documents\\R\\R-2.13.0\\bin\\dsort.txt) dsort#name of data.frame colnames(dsort)[1] #name of column 1 [1] Date colnames(dsort)[2] #name of column 2 [1] Qty class(dsort$Date) #checked data type of column Date and it came back as a factor [1] factor Date2=as.Date(dsort$Date)#attempt at changing the data type from a factor to a date object (see error below). Error in charToDate(x) : character string is not in a standard unambiguous format Dates in my table are listed in 3/4/2007 format. StatBat2 After seeing your subject line and your e-mail address, I was going to suggest a dozen roses and some Moose Munch... ;-) When you convert a character/factor to a Date, you need to specify the format of the object to be converted: as.Date(3/4/2007, format = %m/%d/%Y) [1] 2007-03-04 See ?as.Date and ?strptime for more information and format specifications. 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] Contributed Packages - Hmisc survey
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Muhuri, Pradip (SAMHSA/CBHSQ) Sent: Wednesday, June 01, 2011 1:01 PM To: 'r-help-requ...@r-project.org'; 'R-help@r-project.org' Subject: [R] Contributed Packages - Hmisc survey Hello List, Could someone tell why I can't install the Himsc and survey packages for R version 2.13.0 (2011-04-13)? What am I doing wrong here? Thanks, Pradip install.packages (Hmisc, dependencies=TRUE) --- Please select a CRAN mirror for use in this session --- Warning: unable to access index for repository http://watson.nci.nih.gov/cran_mirror/bin/windows/contrib/2.13 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package 'Hmisc' is not available (for R version 2.13.0) install.packages (survey, dependencies=TRUE) Warning: unable to access index for repository http://watson.nci.nih.gov/cran_mirror/bin/windows/contrib/2.13 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package 'survey' is not available (for R version 2.13.0) I get a 502 Bad Gateway error when I try to go to that mirror. Maybe it is down. Have you tried another mirror? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division 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] Problems Dating....
I'll give this a try and mess with what format to convert it to. Thanks again! -Original Message- From: Stephan Kolassa [mailto:stephan.kola...@gmx.de] Sent: Wednesday, June 01, 2011 2:10 PM To: Struckmeier, Nathanael Cc: R-help@r-project.org Subject: Re: [R] Problems Dating Hi Nat, I guess something like as.Date(as.character(3/4/2007),format=%d/%m/%Y) should work - as.character() coerces the factors to characters, which the as.Date() function can work with, given the right format argument. HTH Stephan Am 01.06.2011 22:59, schrieb Struckmeier, Nathanael: I'm trying to convert a column in a data frame with dates from a Factor type to a Date Object but I am encountering and error. (I am having trouble plotting an x,y scatter and I suspect it's something with my data format). I have a table with two columns and 8,000 rows. dsort=read.delim(C:\\Documents and Settings\\E066582\\My Documents\\R\\R-2.13.0\\bin\\dsort.txt) dsort#name of data.frame colnames(dsort)[1] #name of column 1 [1] Date colnames(dsort)[2] #name of column 2 [1] Qty class(dsort$Date) #checked data type of column Date and it came back as a factor [1] factor Date2=as.Date(dsort$Date)#attempt at changing the data type from a factor to a date object (see error below). Error in charToDate(x) : character string is not in a standard unambiguous format Dates in my table are listed in 3/4/2007 format. StatBat2 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plotting from functions
I can plot to png's fine when i run this directly from the top-level script/console: png('diamonds.png');qplot(carat,price,data=diamonds);dev.off() But for some reason it's not working when that's in a function: (function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})() I suspect this is because the qplot's return value must be returned to the top-level, because this works: (function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off() Any hints on how I can plot from within a function? Thanks in advance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RES: Recode numbers
Thank you so much, Filipe. Your R script is what I am looking for. -- View this message in context: http://r.789695.n4.nabble.com/Recode-numbers-tp3566395p3566818.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting from functions
On Wed, Jun 1, 2011 at 1:04 PM, Yang Zhang yanghates...@gmail.com wrote: I can plot to png's fine when i run this directly from the top-level script/console: png('diamonds.png');qplot(carat,price,data=diamonds);dev.off() But for some reason it's not working when that's in a function: (function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})() I suspect this is because the qplot's return value must be returned to the top-level, because this works: (function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off() Any hints on how I can plot from within a function? Thanks in advance. Actually, just found that things work if I do: print(qplot(...)) Is this just what you need to do to plot from within functions? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RES: Recode numbers
Thank you very much, Bill. Your script works very well. -- View this message in context: http://r.789695.n4.nabble.com/Recode-numbers-tp3566395p3566847.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting from functions
Hi, Within functions, you often do need to wrap the plotting calls in print() (you would see this if you read the FAQ). Cheers, Josh On Wed, Jun 1, 2011 at 1:06 PM, Yang Zhang yanghates...@gmail.com wrote: On Wed, Jun 1, 2011 at 1:04 PM, Yang Zhang yanghates...@gmail.com wrote: I can plot to png's fine when i run this directly from the top-level script/console: png('diamonds.png');qplot(carat,price,data=diamonds);dev.off() But for some reason it's not working when that's in a function: (function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})() I suspect this is because the qplot's return value must be returned to the top-level, because this works: (function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off() Any hints on how I can plot from within a function? Thanks in advance. Actually, just found that things work if I do: print(qplot(...)) Is this just what you need to do to plot from within functions? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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] Missing completely at random
This works, but there might be a better way: misscols-lapply(howmanyMiss, function(x) sample(1:n, x)) for (i in 1:nMiss){ for (j in misscols[[i]]){ X[idMiss[i],j]-NA } } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] finding numbers in a range
On Jun 1, 2011, at 5:07 PM, Salih Tuna wrote: Hi, Is there a quick way of finding if numbers in a vector falls in between a range defined in another matrix. As an example let x y 0 1 3 2 6 9 2515 18 I want to check one by one whether 0,2 and 25 falls in any of the ranges in y. I am using 2 for loops but it is taking a huge amount of time. is there any other alternative way to do this? If this represents the full complexity of the problem then findInterval would work: findInterval(c(0,2,25), c(1,3,6,9,15,18) ) %in% c(1,3,5) [1] FALSE TRUE FALSE On the other hand if the y intervals overlap then a different method may be needed. sapply( c(0, 2, 25) , function(x) {any( y[,1] x x y[,2]) }) [1] FALSE TRUE FALSE -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Create Matrix with Float32 values
On 2011-06-01 09:16, Chris English wrote: Dear R_Help: The following gives me a matrix with integer values. z= matrix(rep(10:1, each= 10), ncol= 10, byrow=TRUE) str(z) int [1:10, 1:10] 10 9 8 7 6 5 4 3 2 1 ... How do I specify that I want Float32 values instead. Thanks,Chris Have you tried adding 0? Or you could use the seq() function. I assume that you have a reason for wanting this. Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Problems Dating....
On Jun 1, 2011, at 5:14 PM, Struckmeier, Nathanael wrote: I'll give this a try and mess with what format to convert it to. Thanks again! You need to decide whether to use %d/%m/%Y or %m/%d/% , since the information you provided so far leaves that undetermined. -- David. Hi Nat, I guess something like as.Date(as.character(3/4/2007),format=%d/%m/%Y) should work - as.character() coerces the factors to characters, which the as.Date() function can work with, given the right format argument. HTH Stephan Am 01.06.2011 22:59, schrieb Struckmeier, Nathanael: I'm trying to convert a column in a data frame with dates from a Factor type to a Date Object but I am encountering and error. (I am having trouble plotting an x,y scatter and I suspect it's something with my data format). I have a table with two columns and 8,000 rows. dsort=read.delim(C:\\Documents and Settings\\E066582\\My Documents\\R\\R-2.13.0\\bin\\dsort.txt) dsort#name of data.frame colnames(dsort)[1] #name of column 1 [1] Date colnames(dsort)[2] #name of column 2 [1] Qty class(dsort$Date) #checked data type of column Date and it came back as a factor [1] factor Date2=as.Date(dsort$Date)#attempt at changing the data type from a factor to a date object (see error below). Error in charToDate(x) : character string is not in a standard unambiguous format Dates in my table are listed in 3/4/2007 format. StatBat2 [[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. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Create Matrix with Float32 values
On 01/06/2011 12:16 PM, Chris English wrote: Dear R_Help: The following gives me a matrix with integer values. z= matrix(rep(10:1, each= 10), ncol= 10, byrow=TRUE) str(z) int [1:10, 1:10] 10 9 8 7 6 5 4 3 2 1 ... How do I specify that I want Float32 values instead. You can't. R doesn't support that type. If you want to pass it to an external function that is expecting C single type, you can use as.single(x). That won't convert it to single precision, but it will cause it to be copied to a single precision array whenever you call .C or .Fortran. 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] Plotting from functions
On 01/06/2011 4:06 PM, Yang Zhang wrote: On Wed, Jun 1, 2011 at 1:04 PM, Yang Zhangyanghates...@gmail.com wrote: I can plot to png's fine when i run this directly from the top-level script/console: png('diamonds.png');qplot(carat,price,data=diamonds);dev.off() But for some reason it's not working when that's in a function: (function(){png('diamonds.png');qplot(carat,price,data=diamonds);dev.off()})() I suspect this is because the qplot's return value must be returned to the top-level, because this works: (function(){png('diamonds.png');qplot(carat,price,data=diamonds)})();dev.off() Any hints on how I can plot from within a function? Thanks in advance. Actually, just found that things work if I do: print(qplot(...)) Is this just what you need to do to plot from within functions? If the plotting function is using grid graphics you do. I don't know where the qplot() function is from, but it looks as though it must be from a package that uses grid. 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] Replacing variables in one dataset with those from another
Hi: Letting d1 and d2 be your two data frames, merge(d1, d2, by.x = 'x1', by.y = 'num', all.x = TRUE)[, c(2, 4, 3)] grpnum uniqueid x2 1 D NA 276 2 B NA 898 3 A GHU82RK02HD7D6 334 4 C GHU82RK02IXPC7 4077 If you want x1 to be the variable name for the new dataset, then dmerge - merge(d1, d2, by.x = 'x1', by.y = 'num', all.x = TRUE)[, c(2, 4, 3)] names(dmerge)[2] - 'x1' HTH, Dennis On Wed, Jun 1, 2011 at 11:30 AM, mcginnis21 mcgin...@montana.edu wrote: Hoping someone out there can help me...this seems like an easy task but I can't figure it out... I want to replace variables in one dataset (Dataset1) with a variable from another dataset (Dataset2). All the values for variables x1 and x2 in Dataset1 have a unique match to the variable uniquenum in Dataset2. For example, in Dataset1 grpnum A has a value of 343 for variable x1. In Dataset2, 343 will only be found once for variable uniquenum. I would like to create a new dataset where the variable x1 from Dataset1 will be replaced by uniqueid from Dataset2. So variable x1 for grpnum A now would equal GHU82RK02HD7D6 rather than 343. Below is an abbreviated example from my datasets to show what I’m trying to do rather than explain in words because I’m not sure my question is coming across very clearly. I have about 100 columns in Dataset1 (x1, x2, etc.) and the variable uniquenum in Dataset2 has about 4,000 values. Dataset1 grpnum x1 x2 A 343 334 B 313 898 C 4076 4077 D 275 276 Dataset2 unique num uniqueid 343 GHU82RK02HD7D6 4076 GHU82RK02IXPC7 4077 GHU82RK02HICZ2 261 GHU82RK02FLOFU 4100 GHU82RK02IDO7K 4101 GHU82RK02HQYQL 4102 GHU82RK02GADV1 4103 GHU82RK02G7RQH 4104 GHU82RK02HQD2E NewDataset grpnum x1 x2 a GHU82RK02HD7D6 Na b Na Na c GHU82RK02IXPC7 GHU82RK02HICZ2 d Na Na Thanks for your time and thoughts. I hope someone can help! -- View this message in context: http://r.789695.n4.nabble.com/Replacing-variables-in-one-dataset-with-those-from-another-tp3566552p3566552.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.