Re: [R] ensembleBMA pit function warnings
Hello Chris, I 've found two other issues with MAE and CRPS, giving warning when running examples. I've the same issue on my data. Hope that you could find some time to take a look here. Thank you Anna library(ensembleBMA) Loading required package: chron example(MAE) MAE data(ensBMAtest) MAE ensMemNames - c(gfs,cmcg,eta,gasp,jma,ngps,tcwb,ukmo) MAE obs - paste(T2,obs, sep = .) MAE ens - paste(T2, ensMemNames, sep = .) MAE tempTestData - ensembleData( forecasts = ensBMAtest[,ens], MAE+ dates = ensBMAtest[,vdate], MAE+ observations = ensBMAtest[,obs], MAE+ station = ensBMAtest[,station], MAE+ forecastHour = 48, MAE+ initializationTime = 00) MAE ## Not run: MAE ##D # R check MAE ##D tempTestFit - ensembleBMAnormal( tempTestData, trainingDays = 30) MAE ## End(Not run) MAE MAE MAE( tempTestFit, tempTestData) ensemble BMA 2.322651 2.152652 Warning message: In matchDates(fitDates, ensembleValidDates(ensembleData), dates) : some fit dates dates not represented in data example(CRPS) CRPS data(ensBMAtest) CRPS ensMemNames - c(gfs,cmcg,eta,gasp,jma,ngps,tcwb,ukmo) CRPS obs - paste(T2,obs, sep = .) CRPS ens - paste(T2, ensMemNames, sep = .) CRPS tempTestData - ensembleData( forecasts = ensBMAtest[,ens], CRPS+ dates = ensBMAtest[,vdate], CRPS+ observations = ensBMAtest[,obs], CRPS+ station = ensBMAtest[,station], CRPS+ forecastHour = 48, CRPS+ initializationTime = 00) CRPS ## Not run: CRPS ##D # R check CRPS ##D tempTestFit - ensembleBMAnormal( tempTestData, trainingDays = 30) CRPS ## End(Not run) CRPS crpsValues - crps( tempTestFit, tempTestData) CRPS colMeans(crpsValues) ensemble BMA 1.971644 1.584356 CRPS CRPS( tempTestFit, tempTestData) ensemble BMA 1.971644 1.577258 Warning messages: 1: In matchDates(fitDates, ensembleValidDates(ensembleData), dates) : some fit dates dates not represented in data 2: In matchDates(fitDates, ensembleValidDates(ensembleData), dates) : some fit dates dates not represented in data sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ensembleBMA_5.0.3 chron_2.3-42 loaded via a namespace (and not attached): [1] tools_2.15.1 Anna Freni Sterrantino Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: Chris Fraley fra...@washington.edu Inviato: Giovedì 12 Luglio 2012 17:42 Oggetto: Re: ensembleBMA pit function warnings Dear Anna Freni Sterrantino, I'll get to this as soon as I can. I'm still maintaining ensembleBMA because there is no one else to do it, but my time at the University of Washington has recently been greatly reduced, and the queue of things to do is rather long at the moment. Regards, Chris On Thu, 12 Jul 2012, anna freni sterrantino wrote: Hello! I'm having some problems with pit function in ensembleBMA. When I run on mu data I have the same warnings as below, when I type the example(pit). Any suggestion on how to resolve it? library(ensembleBMA) Loading required package: chron example(pit) pit data(ensBMAtest) pit ensMemNames - c(gfs,cmcg,eta,gasp,jma,ngps,tcwb,ukmo) pit obs - paste(T2,obs, sep = .) pit ens - paste(T2, ensMemNames, sep = .) pit tempTestData - ensembleData( forecasts = ensBMAtest[,ens], pit+ dates = ensBMAtest[,vdate], pit+ observations = ensBMAtest[,obs], pit+ station = ensBMAtest[,station], pit+ forecastHour = 48, pit+ initializationTime = 00) pit ## Not run: pit ##D # R check pit ##D tempTestFit - ensembleBMAnormal( tempTestData, trainingDays = 30) pit ## End(Not run) pit pit tempTestForc - quantileForecast( tempTestFit, tempTestData) pit range(tempTestForc) [1] 277.3138 281.1668 pit tempTestPIT - pit( tempTestFit, tempTestData) Warning messages: 1: In matchDates(fitDates, ensembleValidDates(ensembleData), dates) : some fit dates dates not represented in data 2: In matchDates(fitDates, ensembleValidDates
Re: [R] plotting principal components on geographic map
Hi Marco, a small example will be helpful to get better to the point. But I suggest you either to address this question to R geo mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-geo and eventually take a look to GeoXp library. Cheers Anna Anna Freni Sterrantino Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: marco milella vru...@gmail.com A: r-help@r-project.org Inviato: Domenica 14 Ottobre 2012 12:02 Oggetto: [R] plotting principal components on geographic map Dear all, I have a dataset representing several geographical points (locations), each one having a specific value after performing a PCA. Now I'm trying to understand how to separately represent on a geographic map (of Europe) the pattern of PC1,2, ecc.with colors (e.g.heatmap) I have to add that the dataset includes relatively few points. Therefore, I would also like to interpolate the values for the uncovered geographical areas. Thanks in advance for any feedback, best marco [[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] GAM without intercept
Hi Sergio, based on my understanding ( see Wood Generalized Additive Model) smoothing basis incorporates the intercept already, due to identifiable issues. Therefore the intercept is always specified and you don't need to specify. I guess that your m2 to model is simply not correct. Hope it helps Anna Anna Freni Sterrantino Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: SAEC sergio.es...@uach.cl A: r-help@r-project.org Inviato: Giovedì 11 Ottobre 2012 0:22 Oggetto: [R] GAM without intercept Hi everybody, I am trying to fit a GAM model without intercept using library mgcv. However, the result has nothing to do with the observed data. In fact the predicted points are far from the predicted points obtained from the model with intercept. For example: #First I generate some simulated data: library(mgcv) x-seq(0,10,length=100) y-x^2+rnorm(100) #then I fit a gam model with and without intercept m1-gam(y~s(x,k=10,bs='cs')) m2-gam(y~s(x,k=10,bs='cs')-1) #and now I obtain predicted values for the interval 0-1 x1-seq(0,10,0.1) y1-predict(m1,newdata=list(x=x1)) y2-predict(m2,newdata=list(x=x1)) #plotting predicted values plot(x,y,ylim=c(0,100)) lines(x1,y1,lwd=4,col='red') lines(x1,y2,lwd=4,col='blue') In this example you can see that the red line are the predicted points from the model with intercept which fit pretty good to the data, but the blue line (without intercept) is far from the observed points. Probably I missunderstanding some key elements in gam modelling or using incorrect syntaxis. I don't know what the problem is. Any ideas will be helpful. Sergio -- Sergio A. Estay Inst. Ciencias Ambientales y Evolutivas Universidad Austral de Chile Casilla 567, Valdivia, Chile Phone: 5663-293913 http://www.ciencias.uach.cl/instituto/ciencias_ambientales_evolutivas/academicos/sergio-estay.php -- View this message in context: http://r.789695.n4.nabble.com/GAM-without-intercept-tp4645786.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] interaction testing in GAM
Hello! I'd like to know if it is correct to test with anova two models specified like this: m1=y~x1+s(x2,by=x3),family=poisson m0=y~x1+s(x2),family=poisson anova(m1,m0) Cheers Anna Anna Freni Sterrantino Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. [[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] I: ensembleBMA pit function warnings
Hello! I'm having some problems with pit function in ensembleBMA. When I run on mu data I have the same warnings as below, when I type the example(pit). Any suggestion on how to resolve it? library(ensembleBMA) Loading required package: chron example(pit) pit data(ensBMAtest) pit ensMemNames - c(gfs,cmcg,eta,gasp,jma,ngps,tcwb,ukmo) pit obs - paste(T2,obs, sep = .) pit ens - paste(T2, ensMemNames, sep = .) pit tempTestData - ensembleData( forecasts = ensBMAtest[,ens], pit+ dates = ensBMAtest[,vdate], pit+ observations = ensBMAtest[,obs], pit+ station = ensBMAtest[,station], pit+ forecastHour = 48, pit+ initializationTime = 00) pit ## Not run: pit ##D # R check pit ##D tempTestFit - ensembleBMAnormal( tempTestData, trainingDays = 30) pit ## End(Not run) pit pit tempTestForc - quantileForecast( tempTestFit, tempTestData) pit range(tempTestForc) [1] 277.3138 281.1668 pit tempTestPIT - pit( tempTestFit, tempTestData) Warning messages: 1: In matchDates(fitDates, ensembleValidDates(ensembleData), dates) : some fit dates dates not represented in data 2: In matchDates(fitDates, ensembleValidDates(ensembleData), dates) : some fit dates dates not represented in data sessionInfo() R version 2.15.0 Patched (2012-04-10 r58965) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ensembleBMA_5.0.3 chron_2.3-42 loaded via a namespace (and not attached): [1] tools_2.15.0 Any suggestion? Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. [[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] inverse binomial in R
Hi Duncan and Rlist, I've notice a different behaviour in the invbinomial you suggest me and invbinomial in stata. invbinomial(50,50, 0.4) Error in uniroot(function(x) pbinom(k, n, x) - p, c(0, 1)) : f() values at end points not of opposite sign invbinomial(50,50, 0.6) Error in uniroot(function(x) pbinom(k, n, x) - p, c(0, 1)) : f() values at end points not of opposite sign while stata gen p3=invbinomial(50,50, 0.4) . display p3 0 . gen p4=invbinomial(50,50, 0.6) . display p4 0 Thanks Cheers Anna Da: Duncan Murdoch murdoch.dun...@gmail.com Cc: Rcran help r-help@r-project.org Inviato: Giovedì 31 Maggio 2012 15:32 Oggetto: Re: [R] inverse binomial in R On 12-05-31 9:10 AM, anna freni sterrantino wrote: Hello! I'm having some trouble trying to replicate in R a Stata function invbinomial(n,k,p) Domain n: 1 to 1e+17 Domain k: 0 to n - 1 Domain p: 0 to 1 (exclusive) Range: 0 to 1 Description: returns the inverse of the cumulative binomial; i.e., it returns the probability of success on one trial such that the probability of observing floor(k) or fewer successes in floor(n) trials is p. I've found some hints on the web like http://rwiki.sciviews.org/doku.php?id=guides:tutorials:regression:table I tried to replicate using qbinom the results obtained in invbinomial(10,5, 0.5) .54830584 but with no success. I don't think base R has a function like that, though some contributed package probably does. If you're writing it yourself you'd need to use uniroot or some other solver, e.g invbinomial - function(n, k, p) { uniroot(function(x) pbinom(5, 10, x) - p, c(0, 1)) } [[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] inverse binomial in R[solved]
Hello Peter, Duncan, Dan and RList! How I suspected... I managed to do the homework and forced invbinomal to return zero ( as in Stata) once that k==n. Thank you for all you replies! Cheers Anna Da: peter dalgaard pda...@gmail.com Cc: Duncan Murdoch murdoch.dun...@gmail.com; Rcran help r-help@r-project.org Inviato: Martedì 19 Giugno 2012 16:00 Oggetto: Re: [R] inverse binomial in R On Jun 19, 2012, at 11:39 , anna freni sterrantino wrote: Hi Duncan and Rlist, I've notice a different behaviour in the invbinomial you suggest me and invbinomial in stata. invbinomial(50,50, 0.4) Error in uniroot(function(x) pbinom(k, n, x) - p, c(0, 1)) : f() values at end points not of opposite sign invbinomial(50,50, 0.6) Error in uniroot(function(x) pbinom(k, n, x) - p, c(0, 1)) : f() values at end points not of opposite sign while stata gen p3=invbinomial(50,50, 0.4) . display p3 0 . gen p4=invbinomial(50,50, 0.6) . display p4 0 Notice that as per your own statement, k==n is outside the domain of definition in Stata, so it is only out of kindness that it is returning any value at all ;-). The root(!) cause is of course that pbinom(n,n,whatever) is identically 1, so solving for any other value is pointless. Modifying Duncan's code to return 0 if k = n is left as an exercise for the reader... -Peter D. Thanks Cheers Anna Da: Duncan Murdoch murdoch.dun...@gmail.com Cc: Rcran help r-help@r-project.org Inviato: Giovedì 31 Maggio 2012 15:32 Oggetto: Re: [R] inverse binomial in R On 12-05-31 9:10 AM, anna freni sterrantino wrote: Hello! I'm having some trouble trying to replicate in R a Stata function invbinomial(n,k,p) Domain n: 1 to 1e+17 Domain k: 0 to n - 1 Domain p: 0 to 1 (exclusive) Range: 0 to 1 Description: returns the inverse of the cumulative binomial; i.e., it returns the probability of success on one trial such that the probability of observing floor(k) or fewer successes in floor(n) trials is p. I've found some hints on the web like http://rwiki.sciviews.org/doku.php?id=guides:tutorials:regression:table I tried to replicate using qbinom the results obtained in invbinomial(10,5, 0.5) .54830584 but with no success. I don't think base R has a function like that, though some contributed package probably does. If you're writing it yourself you'd need to use uniroot or some other solver, e.g invbinomial - function(n, k, p) { uniroot(function(x) pbinom(5, 10, x) - p, c(0, 1)) } [[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. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] inverse binomial in R
Hello! I'm having some trouble trying to replicate in R a Stata function invbinomial(n,k,p) Domain n: 1 to 1e+17 Domain k: 0 to n - 1 Domain p: 0 to 1 (exclusive) Range: 0 to 1 Description: returns the inverse of the cumulative binomial; i.e., it returns the probability of success on one trial such that the probability of observing floor(k) or fewer successes in floor(n) trials is p. I've found some hints on the web like http://rwiki.sciviews.org/doku.php?id=guides:tutorials:regression:table I tried to replicate using qbinom the results obtained in invbinomial(10,5, 0.5) .54830584 but with no success. Thank you Cheers Anna Anna Freni Sterrantino Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. [[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 example Glm rms package
Glm(formula = counts ~ outcome + treatment, family = poisson()) Model Likelihood Ratio Test Obs 9LR chi2 5.45 Residual d.f. 4d.f.4 g 0.227Pr( chi2) 0.2440 CoefS.E. Wald Z Pr(|Z|) Intercept 3.0445 0.1709 17.81 0.0001 outcome2 -0.4543 0.2022 -2.25 0.0246 outcome3 -0.2930 0.1927 -1.52 0.1285 treatment2 0. 0.2000 0.00 1. treatment3 0. 0.2000 0.00 1. Glm anova(f) Wald Statistics Response: counts Factor Chi-Square d.f. P outcome5.49 20.0643 treatment 0.00 21. TOTAL 5.49 40.2409 Glm summary(f, outcome=c('1','2','3'), treatment=c('1','2','3')) Effects Response : counts Factor Low High Diff. Effect S.E. Lower 0.95 Upper 0.95 outcome - 1:2 2 1NA0.45 0.20 0.06 0.85 outcome - 3:2 2 3NA0.16 0.22 -0.26 0.58 treatment - 1:2 2 1NA0.00 0.20 -0.39 0.39 treatment - 3:2 2 3NA0.00 0.20 -0.39 0.39 sessionInfo() R version 2.12.1 (2010-12-16) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] splines stats graphics grDevices utils datasets methods [8] base other attached packages: [1] rms_3.1-0 Hmisc_3.8-3 survival_2.36-2 loaded via a namespace (and not attached): [1] cluster_1.13.2 grid_2.12.1 lattice_0.19-13 tools_2.12.1 Many thanks Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. [[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] Filling a logical matrices with values
Hello !! I have this problem: A matrix on True/False and as many numerical vectors as columns, but of different length. What I 'd like to get is this: set.seed(12) dat - as.data.frame(matrix(as.logical(sample(T:F, 30, T)),5,6)) colnames(dat) - letters[1:6] rownames(dat) - paste(letters[1:5],1:5, sep=) dat a b c d e f a1 TRUE TRUE TRUE TRUE TRUE TRUE b2 FALSE TRUE FALSE TRUE FALSE FALSE c3 FALSE FALSE TRUE FALSE TRUE TRUE d4 TRUE TRUE TRUE FALSE FALSE TRUE e5 TRUE TRUE TRUE TRUE TRUE FALSE v1 - c(1:3) names(v1) - c(a1, d4, e5) v2 - c(1:4) names(v2) - c( a1,b2, c3,e5) v1 a1 d4 e5 1 2 3 v2 a1 b2 c3 e5 1 2 3 4 Desirable Output dat ab cd e f a1 1 1 . b2 NA2 . c3 NANA d4 2 3 e5 3 4 .. Any suggestion , Thank you Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. [[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] adding zero to a number vector
Hi ! I'd like to create a vector that has this kind of numeration 001 002 003 . . . 099 I have looked at format help page but couldn't get any hint on how to do it. Thanks Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. [[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] Spatial Autocorrelation
Hi Paulo, you may want to take a look at http://cran.r-project.org/web/views/Spatial.html there, you can find all spatial packages that can be useful for your question. There is also a a mailing list R-sig-geo that where you can ask all those kind of question. Hope that this helps. Cheers Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: P.Branco pjlbra...@yahoo.com A: r-help@r-project.org Inviato: Martedì 6 ottobre 2009, 13:28:36 Oggetto: [R] Spatial Autocorrelation Hello, I have a matrix with the distances among sites. And I have another matrix with the presence and absence of each species in each site. I would like to test the spatial autocorrelation among sites. I have tried to use the function gearymoran of the ade4 package, but error messages keep popping up. Do you know any function for me to test the spatial autocorrelation of my data? Thanks, Paulo Branco -- View this message in context: http://www.nabble.com/Spatial-Autocorrelation-tp25767010p25767010.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. __ spazio gratuito per i tuoi file e i messaggi [[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] Taking the min of each row in a matrix
Hello Will, z=matrix(c(1,2,3,4,5,6), 2,byrow=T) min=apply(z,1,min) what do you need isapply ?apply and its family are very helpful. apply( matrix, columns, function) apply( matrix, rows, function) Check ?apply Cheers Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: Will Glass-Husain wglasshus...@gmail.com A: r-h...@stat.math.ethz.ch Inviato: Giovedì 29 gennaio 2009, 17:58:50 Oggetto: [R] Taking the min of each row in a matrix Hi, I'm a new user. I've been reading through the manual and looking at various examples but am still trying to make sense of the most efficient ways to handle matrices of data. If I have a 2D matrix of data, how do I get the mean, min, max value of each row? I see the mean function on a matrix will give me averages by row, but min and max give me the value for the entire matrix. I want the min (for example) of each row. pmin looks useful, but I can't seem to get the syntax right to apply to each column. Right now I am doing this. Is there a one-liner that would work instead? minResult - vector (mode=list, length=rowCount) for (row in 1:rowCount) { minResult[[row]] - min(corResult[row], na.rm = TRUE) } Thanks in advance. WILL __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Tinn-R
Hi, if you are on linux Emacs + ESS is quite popular too. Cheers Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: Tibert, Brock btib...@bentley.edu A: r-help@r-project.org r-help@r-project.org Inviato: Lunedì 26 gennaio 2009, 18:01:25 Oggetto: [R] Tinn-R Hi Everyone, I was hoping someone could help me with the settings for Tinn-R. I see in the screen shots that it has syntax help, or something similar (tips on what functions, etc). I can not seem to get this to turn on in the program, and I am wondering if I have to set up a few options. I quickly read through the help and could not figure it out. Many thanks! - Brock P.S. It appears as if Tinn-R is widely used, but would you recommend something different? I am new to R and programming, but have learned (somewhat) using VBA editors I have grown to love to the intelligent typing that goes along with it. [[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] Dataframe with unequal rows
Hi Rahul, try to see ?read.table you may substitute commas with a NA and then sum the NA. I hope that it can help. Cheers Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: rahul-a.agar...@ubs.com rahul-a.agar...@ubs.com A: r-help@r-project.org Inviato: Giovedì 8 gennaio 2009, 10:38:05 Oggetto: [R] Dataframe with unequal rows I have a data frame with unequal rows length separated by comma.I have to read the data first and then calculate number of comma in each row...how can I do that Regards Rahul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] motif search
Hi Alessia, you may want to post this kind of question on Bioc mailing list, is more appropriate. http://www.bioconductor.org/docs/mailList.html About your question , I'm not 100% sure, but check if Biostrings pkg can do what you need to do. http://www.bioconductor.org/workshops/2008/SeattleNov08/MatchAlign/ Best Regards Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: Alessia Deglincerti [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Martedì 9 dicembre 2008, 16:03:55 Oggetto: [R] motif search Hi, I am very new to R and wanted to know if there is a package that, given very long nucleotide sequences, searches and identifies short (7-10nt) motifs.. I would like to look for enrichment of certain motifs in genomic sequences. I tried using MEME (not an R package, I know), but the online version only allows sequences up to MAX 6 nucleotides, and that's too short for my needs.. Thanks A __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Significance of slopes
Hi Christian, please give always reproducible code, so we can see what have done and give you the best answer. lm function, generally as in this example form lm man page ( ?lm) trt - c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) ctl - c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) reg=lm(trt~ctl) summary(reg) Call: lm(formula = trt ~ ctl) Residuals: Min 1Q Median 3Q Max -1.09389 -0.33069 -0.15249 0.05128 1.45497 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 7.7957 2.1661 3.599 0.00699 ** ctl -0.6230 0.4279 -1.456 0.18351 --- Signif. codes: 0 â***â 0.001 â**â 0.01 â*â 0.05 â.â 0.1 â â 1 Residual standard error: 0.7485 on 8 degrees of freedom Multiple R-squared: 0.2095,Adjusted R-squared: 0.1106 F-statistic: 2.12 on 1 and 8 DF, p-value: 0.1835 Returns you all the answer (almost) for the questions that you ask; the p-value of the intercept line, is the p-value from the test( t test) if the intercept is different form zero. the ctl line has also the same interpretation, regarding the value returned. Meaning no is not significantly different form zero. If you want to test if the estimates ( slopes or intercept) are different from a specific value as in your case different for 0.5 you can apply a test. Type on R ?t.test and you can find the all the information you need. Hope this helps Best Regards Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: Christian Arnold [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Martedì 9 dicembre 2008, 21:54:23 Oggetto: [R] Significance of slopes Hello R community, I have a question regarding correlation and regression analysis. I have two variables, x and y. Both have a standard deviation of 1; thus, correlation and slope from the linear regression (which also must have an intercept of zero) are equal. I want to probe two particular questions: 1) Is the slope significantly different from zero? This should be easy with the lm function, as the p-value should reflect exactly that question. If I am wrong, lease correct me. 2) Is the slope significantly different from a non-zero value (e.g. 0.5)? How can I probe that hypothesis? Any ideas? I apologize if this question is too trivial and already answered somewhere, but I did not find it. [[elided Yahoo spam]] Christian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Significance of slopes
Hi Christian, please give always reproducible code, so we can see what have done and give you the best answer. lm function, generally as in this example form lm man page ( ?lm) trt - c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) ctl - c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) reg=lm(trt~ctl) summary(reg) Call: lm(formula = trt ~ ctl) Residuals: Min 1Q Median 3Q Max -1.09389 -0.33069 -0.15249 0.05128 1.45497 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 7.7957 2.1661 3.599 0.00699 ** ctl -0.6230 0.4279 -1.456 0.18351 --- Signif. codes: 0 â***â 0.001 â**â 0.01 â*â 0.05 â.â 0.1 â â 1 Residual standard error: 0.7485 on 8 degrees of freedom Multiple R-squared: 0.2095,Adjusted R-squared: 0.1106 F-statistic: 2.12 on 1 and 8 DF, p-value: 0.1835 Returns you all the answer (almost) for the questions that you ask; the p-value of the intercept line, is the p-value from the test( t test) if the intercept is different form zero. the ctl line has also the same interpretation, regarding the value returned. Meaning no is not significantly different form zero. If you want to test if the estimates ( slopes or intercept) are different from a specific value as in your case different for 0.5 you can apply a test. Type on R ?t.test and you can find the all the information you need. Hope this helps Best Regards Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: Christian Arnold [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Martedì 9 dicembre 2008, 21:54:23 Oggetto: [R] Significance of slopes Hello R community, I have a question regarding correlation and regression analysis. I have two variables, x and y. Both have a standard deviation of 1; thus, correlation and slope from the linear regression (which also must have an intercept of zero) are equal. I want to probe two particular questions: 1) Is the slope significantly different from zero? This should be easy with the lm function, as the p-value should reflect exactly that question. If I am wrong, lease correct me. 2) Is the slope significantly different from a non-zero value (e.g. 0.5)? How can I probe that hypothesis? Any ideas? I apologize if this question is too trivial and already answered somewhere, but I did not find it. [[elided Yahoo spam]] Christian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] How to avoid $ operator is invalid for atomic vectors
Hi Cruz you don't need to assign dimension or classes to your objects. It's easier if you do like this a=c(0,1,2,4,1,1) length(a) [1] 6 b=matrix(a,3,2,byrow=T) b [,1] [,2] [1,]01 [2,]24 [3,]11 of course you can change the colnames and assign what you prefer colnames(b)=c(x,y) but if you try to recall x with b$x is not going to work like that, you have two option: 1. switch form matrix to a dataframe: c=as.data.frame(b) c x y 1 0 1 2 2 4 3 1 1 c$x [1] 0 2 1 no problems. 2. Can get the column x on the matrix b as b[,1] [1] 0 2 1 just giving the position. Hope that this helps. Best Regards Anna Anna Freni Sterrantino Ph.D Student Department of Statistics University of Bologna, Italy via Belle Arti 41, 40124 BO. Da: cruz [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Giovedì 6 novembre 2008, 17:22:42 Oggetto: [R] How to avoid $ operator is invalid for atomic vectors Hi, I am writing this in a wrong way, can someone please correct me? A - matrix() length(A) - 6 dim(A) - c(3,2) colnames(A) - c(X,Y) A X Y [1,] NA NA [2,] NA NA [3,] NA NA A$X Error in A$X : $ operator is invalid for atomic vectors Thanks, cruz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport: [[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] Function Error
Hi Angelo, please read the posting guide, before posting! Anyway, for general rule, if you want to see what's going on in a function at each step, it may be helpful to install library(debug) that has very useful functions as mtrace that my resolve your problem. Cheers Anna - Messaggio originale - Da: Angelo Scozzarella [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Martedì 22 luglio 2008, 20:51:05 Oggetto: [R] Function Error Hi, Why this function doesn't work? function (x) { if (is.factor(x)) { if (!is.ordered(x)) { warning(La mediana non si puo' calcolare!!!) return(NA) } me - median(unclass(x)) if (me - floor(me) != 0) { warning(Mediana indeterminata) return(NA) } else { levels(x)[me] } } else if(class(x)==histogram){ N-sum(x$counts) cl-min(which(cumsum(x$counts)=N/2)) return(x$breaks[cl]+ (N/2-sum(x$counts[1:(cl-1)]))/(x$densit[cl]*N) } else median(x) } thanks Angelo Scozzarella __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Anna Freni Sterrantino Ph.D Student Depatment of Statistics University of Bologna, Italy via Belle arti 41, 40124 Bo Posta, news, sport, oroscopo: tutto in una sola pagina. [[elided Yahoo spam]] www.yahoo.it/latuapagina [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to change the class of data?
Hi Selina, try ?as.numeric, small example a=c(1,2,3,4,5) b=as.factor(a) class(b) c=as.numeric(b) class(c) in the case of a matrix of factor,try apply(matrix,1, as.numeric) Cheers A. - Messaggio originale - Da: Qman Fin [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Giovedì 12 giugno 2008, 8:24:08 Oggetto: [R] How to change the class of data? Hi all, I have some data x, which are actualy consisted of numerical enties. But the class of this matrix is set to be factor by someone else. I used class(x), it turns out to be factor. So I can not calculate them. How can I turn them into numerical data so that I can apply math operations on them? Thanks a lot for your help. Selina [[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. ___ pinione! http://www.ymailblogit.com/blog/ [[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] loop? apply? I want to repeat a task through 208 itterations.
hi Stephen, you may want to check ?apply What you want is : a-matrix(1:120,10,20) a[1:8,1:2]=NA apply(a,2, function(x) if(sum(!is.na(x)) (length(x)-3)) shapiro.test(x) else NA ) Cheers Anna - Messaggio originale - Da: stephen sefick [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Venerdì 4 aprile 2008, 8:44:45 Oggetto: [R] loop? apply? I want to repeat a task through 208 itterations. structure(list(RM215alk = c(15, 13, 12, 14, NA, 13, 16, 13, 16, #subset of data 13, 17, 13, 19, 13, 14, 14, 15, 15, 14, 16, 14, 15, 13, 14), NSCl = c(NA, NA, 2.9, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c(RM215alk, NSCl), class = data.frame, row.names = c(NA, -24L)) apply(if n=3(x.f, 2, shapiro.test)else(NULL)) #crappy code showing my lack of knowledge on the subject I would like to apply this to a 208 column data matrix, and this is the first time I have tried a repetitive task in R- so please bear with me. the shapiro.test requires 3 to 5000 observations and there are some columns that don't have three observation making it unnecessary to preform a test for normality. How do I do this? thanks stephen -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. La casella di posta intelligente. [[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] weibull model
the function survreg in the package survival should what are you looking for. Cheers Anna - Messaggio originale - Da: boshao zhang [EMAIL PROTECTED] A: r-help@r-project.org Inviato: Mercoledì 19 marzo 2008, 10:45:43 Oggetto: [R] weibull model Dear Helpers: If you know how to fit a Weibull model using R, you are my savior for my project. The hazard ramda is specified as t^alpha * (1+a*dose*exp(-b*dose)). Or, can we modify the Cox model to capture the proportional part above? Here t is the survial time, dose is a subject received in a exposed group. Thank you a lot. Boshao Looking for last minute shopping deals? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Tanti modi per restare in contatto con chi vuoi. [[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] Loading user defined functions autometically each time I start R
Hi, an easy way, is to save your functions in a file and have it in your working directoy and sources it. i.e. source(myfile.r) otherwise you can try to build your own package, see ?package.skeleton Hope it helps Regards A - Messaggio originale - Da: Arun Kumar Saha [EMAIL PROTECTED] A: [EMAIL PROTECTED] [EMAIL PROTECTED] Inviato: Mercoledì 27 febbraio 2008, 8:03:26 Oggetto: [R] Loading user defined functions autometically each time I start R Hi all, I wrote some user defined function for my own. Now I want to get a mechanism so that every time I start R, those function will automatically be loaded in R without manually copying pasting. Can gurus here pls tell me how to do that? Or I have to build my own packages bundled with those functions. However I am not familiar in writing R package yet. Regards, [[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] In chisq.test(x) : Chi-squared approximation may be incorrect
Hi! the warning you got Chi-squared approximation may be incorrect is because probably there are less than 5 observations in the cell. Maybe will help to try fisher.test() Cheers Anna - Messaggio originale - Da: My Coyne [EMAIL PROTECTED] A: [EMAIL PROTECTED] Inviato: Lunedì 14 gennaio 2008, 21:51:30 Oggetto: [R] In chisq.test(x) : Chi-squared approximation may be incorrect Hello, I received the following warning when running chi-square; n Is there a way to catch the 'error' code of 'warning' after run chisq.test(x)? n What does this error mean? Thank you for your help. [[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. ___ ttp://it.docs.yahoo.com/nowyoucan.html [[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.