[R] 3D Plot of Convex hull
I have a data set in which I am trying to plot a convex hull in 3 dim. Below is a subset of the points I would use. Columns 2,3,4 are my x,y,z coordinates. I found some ways to plot 2D convext hulls or find a convex hull for higher dimensions, but not how to plot the data. I have have attached an example of what I am shooting for in my plot. Thanks for the help! 6466574 37 225 27 53.69230 5 6466575 38 225 27 47.54898 5 6466576 39 225 27 58.71439 5 6466577 40 225 27 67.40830 5 6466578 41 225 27 64.40646 5 6466579 42 225 27 71.59792 5 6466580 43 225 27 66.10197 5 6466581 44 225 27 61.53381 5 6466582 45 225 27 69.49900 5 6466583 46 225 27 93.91280 5 6466800 31 226 27 102.78361 5 6466801 32 226 27 69.58787 5 6466802 33 226 27 67.53348 5 6466803 34 226 27 66.83624 5 6466804 35 226 27 52.74981 5 6466805 36 226 27 58.10865 5 6466806 37 226 27 64.29259 5 6466807 38 226 27 55.37983 5 6466808 39 226 27 58.48212 5 6466809 40 226 27 66.21062 5 6466810 41 226 27 58.39149 5 6466811 42 226 27 60.40741 5 6466812 43 226 27 60.95507 5 6466813 44 226 27 64.16653 5 6466814 45 226 27 62.48255 5 6466815 46 226 27 74.37065 5 6466816 47 226 27 100.51262 5 http://r.789695.n4.nabble.com/file/n4680712/turbo_ch3d_lung3.jpg -- View this message in context: http://r.789695.n4.nabble.com/3D-Plot-of-Convex-hull-tp4680712.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] R packages for CAT scans
Does anyone know of a package that would allow data from a CT scan to be loaded into R? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/R-packages-for-CAT-scans-tp4676418.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] readTiff - Sorry can't handle images with 32-bit samples
I tried using readTiff() and got the error message Sorry can't handle images with 32-bit samples line of code x - readTiff(C:/Users/550062/Desktop/Data/example1.tif) So far I have not had any luck finding this error message on google. Any guess at what it means and how to get the code to work? Thanks! -- View this message in context: http://r.789695.n4.nabble.com/readTiff-Sorry-can-t-handle-images-with-32-bit-samples-tp4672465.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] Autofilling a large matrix in R
I wish to create a matrix of all possible percentages with two decimal place percision. I then want each row to sum to 100%. I started with the code below with the intent to then subset the data based on the row sum. This works great for 2 or 3 columns, but if I try 4 or more columns the number of rows become to large. I would like to find a way to break it down into some kind of for loop, so that I can remove the rows that don't sum to 100% inside the for loop rather than outside it. My first thought was to take list from 1:10, 11:20, etc. but that does not get all of the points. g-as.matrix(expand.grid(rep(list(1:100), times=3))) Any thoughts how to split this into pieces? -- View this message in context: http://r.789695.n4.nabble.com/Autofilling-a-large-matrix-in-R-tp4645991.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] Removing duplicates without a for loop
I have several thousand rows of shipment data imported into R as a data frame, with two columns of particular interest, col 1 is the entry date, and col 2 is the tracking number (colname is REQ.NR). Tracking numbers should be unique but on occassion aren't because they get entered more than once. This creates two or more rows of with the same tracking number but different dates. I wrote a for loop that will keep the row with the oldest date but it is extremely slow. Any suggestions of how I should write this so that it is faster? # Creates a vector of on the unique tracking numbers # u-na.omit(unique(Para.5C$REQ.NR)) # Create Data Frame to rbind unique rows to # Para.5C.final-data.frame() # For each value in u subset Para.5C find the min date and rbind it to Para.5C.final # for(i in 1:length(u)) { x-subset(Para.5C,Para.5C$REQ.NR==u[i]) Para.5C.final-rbind(Para.5C.final,x[which(x[,1]==min(x[,1])),]) } -- View this message in context: http://r.789695.n4.nabble.com/Removing-duplicates-without-a-for-loop-tp4644255.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] Trying to learn how to write a function... can't define a variable??
I am just starting to experiment with writing a function and have run into what seems like a limitation or more likely a lack of understanding on my part. Very Simple Example: I want to define a function that does 1+1=2. z-1 ADD-function(x) { x-x+1 } ADD(z) z output for z is 1 not the expected 2. Now if I were to do print(x+1) instead of x-x+1 it does return 2, so the function seems ok with x+1, but not ok with x-. Is there a way to define a variable inside a function or am I violating some rule that I don't know about? Thanks for the help! Will -- View this message in context: http://r.789695.n4.nabble.com/Trying-to-learn-how-to-write-a-function-can-t-define-a-variable-tp4642528.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] Revolution Analytics
Has anyone every used Revolution Analytics? It claims to be faster than R, but when I ran a for loop of linear regression that requires a couple of minutes to process in RStudio. Revolution Analytics has a run time that was exactly the same. I was just wondering if anyone has experience with the two and what your thoughts are. Thanks, William -- View this message in context: http://r.789695.n4.nabble.com/Revolution-Analytics-tp4642248.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] Speeding up a loop
1.15 60 0.553555415 0.574892872 1.15 60 0.563183983 0.564029359 Shouldn't the function row out the second one, since it it higher in position 3 and lower in position 4 i.e. it should not all be yes? -- View this message in context: http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637438.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] Bug in my code (finding nonzero min)
Can someone verify for me if the for loop below is really calculating the nonzero min for each row of a matrix? I have a bug somewhere in the is section of code. My first guess is how I am find the the nonzero min of each row of my matrix. The overall idea is to make sure I am investing all of my money, i.e. new.set is a set of indicator variables for each stock for a particular portfolio, i.e. 0=did not buy, 1=bought. y are the stocks I could still buy, assuming I have the money, data3[,5] are their cost, so for each portfolio, i.e. the rows of new.set I have the option to purchase another stock at a cost listed in the rows of variable remain. Obvisouly the cheapest stock needs to have a cost0 in order for me to be allowed to buy it. My code is intended to weed out portfolios where I could have bought another stock, by taking budget-portfolio cost - (cheapest available stock) and subsetting new.set when this is negative, i.e. buying the cheapest available stock puts me over budget. My problem is that my code is still allowing examples like the following budget of 10, portfolio cost 6, cheapest availabe stock 3 despite the diff variable being negative. Any ideas? y-1-new.set[,6:26] remain-y*data3[,5] minn-matrix(0,nrow(remain),1) for(q in 1:nrow(remain)) { remainc-remain[q,] minn[q,]-min(remainc[which(remainc0)]) } maxcost-matrix(150,nrow(new.set),1) diff-maxcost[,1]-new.set[,5]-minn[,1] new.set-subset(new.set,diff0) -- View this message in context: http://r.789695.n4.nabble.com/Bug-in-my-code-finding-nonzero-min-tp4637399.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] Speeding up a loop
next for loop question. I need a loop that removes a row from a matrix if it is worse in positions 1,2,3,4 than another row in the matrix. right now my matrix is 503028x26. Rule to define worse position1 is smaller, position2 is smaller, position3 is higher, and position4 is smaller Example: row1: 1, 10, 3, 3 row2: 3, 7, 5, 2 row2 is not worse than row1 since it is better in position 1, eventhough it is worse in all other positions. row3: 2,5,7,1 row3 however is worse than row2 and should be removed from the matrix. Any ideas? Should I break this into pieces or do it all at once? Is there something faster than a loop? My current loops takes well over 24 hours to run. m-matrix(0,1,24) for(i in 1:n) { a-matrix(x[i,1:4],1,4) j=1 nn-nrow(m) counter-0 while(j=nn) { if(a[1]m[j,1] a[2]m[j,2] a[3]m[j,4] a[4]m[j,4]) { mlt;-m[-j,] nnlt;-length(m[,1]) counterlt;-1 } else jlt;-j+1 } if(counter==1) { blt;-cbind(a,x) mlt;-rbind(m,b) } if(counter==0) { if(a[1]min(m[,1]) || a[3]min(m[,3]) || a[4]min(m[,4]) || a[5]max(m[,5])) { b-cbind(a,x) m-rbind(m,b) } } } -- View this message in context: http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637305.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] Speeding up a loop
Any chance I could ask for an idiots guide for function to.keep(x). I understand how to use it but not what some of the lines are doing. Comments would be extremely helpful. -- View this message in context: http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637316.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] Speeding up a loop
General problem: I have 20 projects that can be invested in and I need to decide which combinations meet a certain set of standards. The total possible combinations comes out to 2^20. However I know for a fact that the number of projects must be greater than 5 and less than 13. So far the the code below is the best I can come up with for iteratively creating a set to check against my set of standards. Code x-matrix(0,nrow=1,ncol=20) for(i in 1:2^20) { x[1]-x[1]+1 for(j in 1:20) { if(x[j]1) { x[j]=0 if(j20) { x[j+1]=x[j+1]+1 } } } if(sum(x)5 sum(x)13) { # insert criteria here. } } my code forces me to create all 2^20 x's and then use an if statement to decide if x is within my range of projects. Is there a faster way to increment x. Any ideas on how to kill the for loop so that it won't attempt to process an x where the sum is greater than 12 or less than 6? -- View this message in context: http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201.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] Speeding up a loop
That is faster than what I was doing and reducing 15% of my iterations it still very helpful. Next question. I need to multiply each row x[i,] of the matrix x by another matrix A. Specifically for(i in 1:n) { If (x[i,]%*%A[,1].5 || x[i,]%*%A[,2]42 || x[i,]%*%A[,3]150) { x-x[-i,] n-n-1 }. #In other words remove row i from x if it does not meet criteria (=.5, =42, =150). When multiplied to A } Is there a better way than using a for loop for this or x-x[-i,] for that matter? I assume building a new matrix would be worse. Ideally I want to also exclude some x[,i] as well example if x[1,] is better than x[2,] in all three categories i.e. bigger, bigger, and smaller than x[2,] when multiplied to A then I want to exclude x[2,] as well. Any suggestions on whether it is better to do this all at once or in stages? Thanks for helping! -- View this message in context: http://r.789695.n4.nabble.com/Speeding-up-a-loop-tp4637201p4637255.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] Correct Interpretation of survreg() coeffs
Am I correct in assuming that the output below essentially translates to Males have a mean time that is significantly lower than Females? Is this the correct way to interpret the fact that the coefficient is negative? Assume the variale sex is treated as a factor with Female =0 and Male=1. survmodel-survreg(survobj~sex,data=data1, dist=weibull) survsum-summary(survmodel) survsum Value Std. Error z p SexMale-0.47830 0.3745 -1.2770 2.02e-01 -- View this message in context: http://r.789695.n4.nabble.com/Correct-Interpretation-of-survreg-coeffs-tp4608655.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] Creating a survival object with and without an event indicator
When reading about surv(). I saw the following statement Although unusual, the event indicator can be omitted, in which case all subjects are assumed to have an event. So I tried the following 1. survobj-surv(mydata$Time) vs. 2. survobj-surv(mydata$Time, mydata$Event) where mydata$Event is a column of all ones. I did not get the same answer when I ran survreg(survobj~shift, data=mydata) on each. The second case actually failed to converge. I then tried a column of all zeros just to make sure I wasn't misreading something but still got the warning message failed to converge. Can anyone explain what exactly R is doing for case 1? -- View this message in context: http://r.789695.n4.nabble.com/Creating-a-survival-object-with-and-without-an-event-indicator-tp4605945.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] How does survreg ordered factors vs not ordered factors?
Consider the following generic code for a survival model survobj-Surv(data$Time,data$Satisfactory) survmodel-survreg(survobj~x1+x2+x3+x4+x5+x6, data=data, dist=weibull) survsum-summary(survmodel) survsum My question: Does anyone know what exactly survreg() does differently if x1-factor(data$x1, ordered=TRUE) x2-factor(data$x2, ordered=TRUE) vs. x1-factor(data$x1) x2-factor(data$x2) Thanks, William -- View this message in context: http://r.789695.n4.nabble.com/How-does-survreg-ordered-factors-vs-not-ordered-factors-tp4580395p4580395.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] Inverse matrix using eigendecomposition
Sorry but I am not a student, at least not since 2007. However I am performing grunt work for a someone with a Ph.D. so it does remind me of the student days. I just have a pay check instead of student loans. -- View this message in context: http://r.789695.n4.nabble.com/Inverse-matrix-using-eigendecomposition-tp4188673p4190557.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] hclust and ggplot2
I saw an example online of taking hclust dendrogram and plotting it using ggplot2 and thought I would give it a try to see what it would look like. I get an error when trying to use ggplot; Error: ggplot2 doesn't know how to deal with data of class phylo. Regular plot works fine but I can't get ggplot2 to work. see code below rows=100 columns=100 #create matrix all=matrix(nrow=rows, ncol=columns) #initialize first column all[,1]=rbinom(rows,1,.5) #set probability probv=.9 for (j in 2:columns) { for (i in 1:rows) { #set the probability based on the values in the columns to the left if (all[i,j-1]==1) {all[i,j]=rbinom(1,1,1-probv)} else {all[i,j]=rbinom(1,1,probv)} } } #make the first row an outlier all[5,]=rbinom(columns,1,.1) all[4,]=rbinom(columns,1,.1) all[3,]=rbinom(columns,1,.1) all[2,]=rbinom(columns,1,.1) all[1,]=rbinom(columns,1,.1) all[6:9,]=rbinom(columns,1,.1) all[10:19,]=rbinom(columns,1,.3) all[20:29,]=rbinom(columns,1,.7) #1 to 10 .5 11 to 89 .9 .1 90 columns #calculate the distances for clustering rand1=dist(all) #cluster on those distances and plot hc1=hclust(rand1,average) plot(hc1) ## now plot using ggplot and polar coordinates. Line starting p-ggplot(data=x) yields the error. This is the online code I found. library(ape) library(cluster) library(ggplot2) x - as.phylo(hc1) p - ggplot(data=x) p - p + geom_segment(aes(y=x,x=y,yend=xend,xend=yend), colour=blue,alpha=1) p - p + geom_text(data=label.phylo(x), aes(x=y, y=x, label=label),family=3, size=3) + xlim(0, xlim) + coord_polar() theme - theme_update( axis.text.x = theme_blank(), axis.ticks = theme_blank(), axis.title.x = theme_blank(), axis.title.y = theme_blank(), legend.position = none ) p - p + theme_set(theme) print(p) -- View this message in context: http://r.789695.n4.nabble.com/hclust-and-ggplot2-tp4193353p4193353.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] Inverse matrix using eigendecomposition
General goal: Write R code to find the inverse matrix of an nxn positive definite symmetric matrix. Use solve() to verify your code works. Started with a 3x3 matrix example to build the code, but something dosen't seem to be working. I just don't know where I am going wrong. ##Example matrix I found online A-c(4,1,-1,1,2,1,-1,1,2) m-matrix(A,nrow=3,ncol=3) ##Caculate the eigen vectors and eigenvalues E-eigen(m, sym=TRUE) Q-E$vectors V-E$values n-nrow(m) ##normalize the eigenvectors for(i in 1:n){ Q[,i]-Q[,i]/sqrt(sum(Q[,i]^2)) } ##verify dot product of vectors are orthogonal sum(Q[,1]*Q[,2]) sum(Q[,1]*Q[,3]) sum(Q[,2]*Q[,3]) ##Begin creating QDQ^T matrix. Where Q are orthonormal eigenvectors, and D is a diagonal matrix with 1/eigenvalues on the diagonal. and Q^T is the transpose of Q. R-t(Q) D-mat.or.vec(n,n) for(i in 1:n) { D[i,i]-1/V[i] } P-Q*D*R ## P should be the inverse of the matrix m. Check using solve(m) ## solve(m) does not equal P? Any ideas of what I am missing/not understanding? -- View this message in context: http://r.789695.n4.nabble.com/Inverse-matrix-using-eigendecomposition-tp4188673p4188673.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] 3D Bar Graphs in ggplot2?
So I take it 3D pie charts are out? P.S. It is not about hiding anything. It is about consulting and being told by your client to make 3D pie charts and change this font or that color to make the graphs more apealing. Given that I am the one trying to open the door to using R where I work it would be much easier if I could simply use a 2D graph. -- View this message in context: http://r.789695.n4.nabble.com/3D-Bar-Graphs-in-ggplot2-tp3713305p3715382.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] 3D Bar Graphs in ggplot2?
Does anyone know how to create a 3D Bargraph using ggplot2/qplot. I don't mean 3D as in x,y,z coordinates. Just a 2D bar graph with a 3D shaped bard. See attached excel file for an example. Before anyone asks I know that 3D looking bars don't add anything except prettiness. http://r.789695.n4.nabble.com/file/n3713305/Example.xlsx Example.xlsx -- View this message in context: http://r.789695.n4.nabble.com/3D-Bar-Graphs-in-ggplot2-tp3713305p3713305.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] qplot and for loops
I just wanted the post the results of the emails I been sending/getting. The following command will create the graphs and save them to the location of your choice. The names are graph1.png, graph2.png etc. for(i in 1:4) { png( file=paste(C:/Insert file location/graph,i,.png, sep=) ) print( qplot(x=mydata[,i]) ) dev.off()} Thanks for the help you guys. -- View this message in context: http://r.789695.n4.nabble.com/qplot-and-for-loops-tp3663292p3666489.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] qplot and for loops
I have 4 columns and 56 rows of made up data that I want to plot as a series of bar graphs. The idea is to create one bar graph for each of the 4 columns using a for loop. I tried the following command in RStudio and when I type x in the console I get just the 4th graph instead of all four graphs. I did not define what x is before hand. I was not sure what it would be. Any suggestions on how you would properly define x? for(i in 1:4){ qplot(x[i]-mydata[,i]) } The headers of the columns are Trial.1 Trial.2 Trial.3 and Trial.4. Also note that I can easily make any of the four graphs by i=1 or i=2, etc. qplot(x-mydata[,i]) I just need to figure out how to make it loop correctly. The ultimate goal would also be to save these graphs to my computer with automatically generated file names. Something like test graph1.png, test graph2.png, etc. Thanks For The Help! -- View this message in context: http://r.789695.n4.nabble.com/qplot-and-for-loops-tp3663292p3663292.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] XLConnect Error
Any ideas of what is happening when I attempt to load XLConnect? I think I installed everything correctly. I posted what I get when I installed rJava as well as when I attempted to load rJava directly. Thanks in advance for any help you can give on this. library(XLConnect) Loading required package: XLConnectJars Loading required package: rJava Error : .onLoad failed in loadNamespace() for 'rJava', details: call: fun(...) error: JAVA_HOME cannot be found from the Registry Error: package 'rJava' could not be loaded This is the mesage I get when I install rjava: Installing package(s) into ‘C:/Users/550062/Documents/R/win-library/2.13’ (as ‘lib’ is unspecified) trying URL 'http://cran.opensourceresources.org/bin/windows/contrib/2.13/rJava_0.9-0.zip' Content type 'application/zip' length 654181 bytes (638 Kb) opened URL downloaded 638 Kb package 'rJava' successfully unpacked and MD5 sums checked The downloaded packages are in C:\Users\550062\AppData\Local\Temp\RtmppIjwgg\downloaded_packages If I try loading rJava directly I get the samer error as XLConnect: library(rJava) Error : .onLoad failed in loadNamespace() for 'rJava', details: call: fun(...) error: JAVA_HOME cannot be found from the Registry Error: package/namespace load failed for 'rJava -- View this message in context: http://r.789695.n4.nabble.com/XLConnect-Error-tp3628528p3628528.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] trying to import xls or xlsx files
library(xlsReadWrite) mydata-read.xls(file path, header=TRUE) however if I change xls to csv it works just fine. Any ideas what I'm doing wrong? I have have also using the package gdata with the exact same error. Below is the error that pops up. Error in findPerl(verbose = verbose) : perl executable not found. Use perl= argument to specify the correct path. Error in file.exists(tfn) : invalid 'file' argument -- View this message in context: http://r.789695.n4.nabble.com/trying-to-import-xls-or-xlsx-files-tp3620580p3620580.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] qplot/ggplot2 Questions
I took some data from an online poll about which R GUI people used most and I am messing around with it to learn how to use qplot. Specifically I am making a horizontal bar graph and I have two questions. 1. The categories are ordered in rather strange way at least to me. It is not alphabetical or ascending/descending order of votes cast so i had to manually state the order I wanted which is fine, but is there an easy way put the cateogies in alphabetical order or in my case descending order? Maybe something like: order=alphabetical 2. Is there an easy way to take a bar graph of count data and turn it into a bar graph of percentages. I know I can count how many items are in each category then divide by the total and then graph that, but is there something quick like geom=percent or something that would do it automatically? Code: library(ggplot2) x-R.GUI.Poll$Poll q-qplot(x, main=Most Popular R-GUIs, ylab=Votes Received, xlab=R GUI, fill=I(blue), colour=I(black))+coord_flip()+scale_x_discrete( limits=c(R via a data mining tool plugin,Rexcel,JGR (Java Gui for R),RKWard,Revolution Analytics,R Commander,Rattle GUI,ESS (Emacs Speaks Statistics),Tinn-R,RapidMiner R extension,Eclipse with StatET,Rstudio,Built-in R console)) q-q+opts(axis.text.x = theme_text(colour = black, size = 12)) q-q+opts(plot.title = theme_text(colour = black, face=bold, size = 16, vjust=2)) q-q+opts(axis.text.y = theme_text(colour = black, hjust=1)) q-q+opts(axis.title.y = theme_text(face= bold, size= 12, angle=90)) q-q+opts(axis.title.x = theme_text(face= bold, size= 12, vjust=-.5)) q -- View this message in context: http://r.789695.n4.nabble.com/qplot-ggplot2-Questions-tp3614722p3614722.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] ggplot2 Histogram with density curve
I am learning ggplot2 commands and I have figured out how to create histograms and density curves but I am not sure how to add a density curve on top of a histogram. Here are the two graphs that I created. ## Histogram t-rnorm(500) w-qplot(t, main=Normal Random Sample, fill=I(blue), colour=I(black), geom=histogram) w ##Density Curve t-rnorm(500) r-qplot(t, main=Normal Random Sample, colour=I(black), geom=density, adjust=4) r -- View this message in context: http://r.789695.n4.nabble.com/ggplot2-Histogram-with-density-curve-tp3579894p3579894.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] ggplot 2: Histogram with bell curve?
I am learning ggplot2 commands specifically qplot for the time being and I have figured out how to create histograms and normal density curves but I am not sure how to add a normal bell curve or other dist. as well on top of a histogram. Here are the two graphs that I created. ## Histogram t-rnorm(500) w-qplot(t, main=Normal Random Sample, fill=I(blue), colour=I(black), geom=histogram) w ##Density Curve t-rnorm(500) r-qplot(t, main=Normal Random Sample, colour=I(black), geom=density, adjust=4) r -- View this message in context: http://r.789695.n4.nabble.com/ggplot-2-Histogram-with-bell-curve-tp3580359p3580359.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] qplot fill and colour not working as expected
I am just learning to use qplot and can't get the fill/colour to work. Below is the R code for a scatter plot and bar graph. library(ggplot2) x-c(1,2,3,4,5,6,7) y-c(1,2,3,2,5,6,3) qplot(x,y, main=Scatter Plot Test, xlab=X Label Test, ylab=Y Label Test, colour=blue)z-c(van, van, van, car, car, truck, truck, truck, truck, van, van) qplot(z, main=Bar Graph Test, ylab=Vehichle Count, xlab=Vehicle Category, fill=blue) If I set fill=z, then I can get something different, i.e. three preselected colors are used, but what if I want all three bars to just be blue instead of the default? I am having the same issue if I try to use colour. How do I change the default color to blue instead of black. Second question what exactly is the difference between colour and fill? -- View this message in context: http://r.789695.n4.nabble.com/qplot-fill-and-colour-not-working-as-expected-tp3576949p3576949.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] MANOVA Post Hoc Testing Tukeys
I used manova() with one predictor variable and four factor levels call them A, B, C, and D. There are 12 response variables. I now want to perform pairwise comparisons for A-B, A-C, etc. for all 12 response variables. If I were doing an ANOVA test I would run TukeyHSD() and be done. However manova in R does not have Tukey's test or an equivalent that I know of. Online I read that at this point I should run 12 anovas and then use a Tukey's test after each ANOVA. Here is my question: Is this the best way to go about Post Hoc Testing in R after a MANOVA test? Also if this is the best path shouldn't I have some kind of familywise error correction like Bonferroni of .05/13=.0038? The post I saw said nothing about a Bonferroni correction. Thanks for the help. -- View this message in context: http://r.789695.n4.nabble.com/MANOVA-Post-Hoc-Testing-Tukeys-tp3526143p3526143.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] histograms and for loops
The following code works mostly. It runs fine but... 1. Is there a way to increment the xlab for each graph? I would like to have Graph 1, Graph 2, etc. Right now it just gives me Graph i over and over again. 2. Is there a way to get the x-axis and y-axis to be bold or at least a darker color? Right now it is light gray. 3. Is there a way to modify this code to automatically save them? I assume the answer is do it manually. This is not the most important. for(i in 1:12){ hist(zNort1[,i], freq=FALSE, xlab=Graph i, col=blue, main=Standardized Residuals Histogram, ylim=c(0,1), xlim=c(-3.0,3.0)) zNortmin-min(zNort1[,1]) zNortmax-max(zNort1[,1]) zNortmean-mean(zNort1[,1]) zNortsd-sd(zNort1[,1]) X1-seq(-3.0, 3.0, by=.01) lines(X1, dnorm(X1, zNortmean, zNortsd) , col=black) } -- View this message in context: http://r.789695.n4.nabble.com/histograms-and-for-loops-tp3503648p3503648.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] Storing data from a test as a vector or matrix
I just finished a MANOVA test and got the following output: summary(M, test=Pillai) Df Pillai approx F num Df den DfPr(F) as.factor(X) 3 1.1922 6.5948 36360 2.2e-16 *** Residuals 129 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 I would like to store the values Df=3, Pillai=1.1922, P-value, etc. as a vector. I have tried the following code that did not work: S=summary(M, test=Pillai) S1-as.vector(S$Df, S$Pillai) but I am getting an error every time. I have also tried just S$Df. Is there a way to find out if Df and Pillai are correct headers to reference. For example maybe it is df or degreesfreedom etc. I know the concept works because I have used it for logistic regression. v1 - as.vector(exp(L1$coefficients)) The difference is that I know coefficients is the correct header to refer to. -- View this message in context: http://r.789695.n4.nabble.com/Storing-data-from-a-test-as-a-vector-or-matrix-tp3495626p3495626.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] Storing data from a test as a vector or matrix
SA gives the output: Response IPS1 : Df Sum Sq Mean Sq F value Pr(F) as.factor(WSD) 3 3.3136 1.10455 23.047 5.19e-12 *** Residuals 129 6.1823 0.04793 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 . . . There are 11 more just like this output. Just increment IPS1 to IPS2, etc. Goal: save 3 3.3136 1.10455 23.047 5.19e-12 as a vector. Str(SA) gives the output: str(SA) str(SA) List of 12 $ Response IPS1 :Classes 'anova' and 'data.frame': 2 obs. of 5 variables: ..$ Df : num [1:2] 3 129 ..$ Sum Sq : num [1:2] 3.31 6.18 ..$ Mean Sq: num [1:2] 1.1045 0.0479 ..$ F value: num [1:2] 23 NA ..$ Pr(F) : num [1:2] 5.19e-12 NA There are several more but they are just repeats of this one only with IPS2, IPS3,... The command: SA1-as.vector(SA$Reponse IPS1) Returns NULL As do several variations I have tried. Any ideas. -- View this message in context: http://r.789695.n4.nabble.com/Storing-data-from-a-test-as-a-vector-or-matrix-tp3495626p3495950.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] Storing data from a test as a vector or matrix
I figured out that attributes is the command that I was trying to find. It allowed me to find out that I was needing to use stats not Df or Pillai etc. Following command worked. S1-as.vector(S$stats[1,]) However when I try the same thing with summary.aov it is not working. SA-summary.aov(M) SA1-as.vector(SA$Reponse IPS1) or SA1-as.vector(SA$Reponse IPS1[1,]) Using attributes command I get Response IPS1. I have tried several variations like including the first space in the quotes, deleting the space between the two words, adding in [1,], etc. The error is stating unexpected text. I have even tried using which works for the stats line above but does not work here. Again thanks for any suggestions on what I am not understanding here. -- View this message in context: http://r.789695.n4.nabble.com/Storing-data-from-a-test-as-a-vector-or-matrix-tp3495626p3495901.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] Writing Macros for RExcel
I have columns of data in Excel 2007, A2:A196, B2:B196...ET2:ET196 that I would like to place into arrays in R. I have been trying to write a macro that would automatically create all of my arrays for me with a array names coming from the cells A1, B1, etc. I can manually create an array using RExcelPut R Var Array, but I don't want to manually create all 150 arrays this way. Thanks for the help. -- View this message in context: http://r.789695.n4.nabble.com/Writing-Macros-for-RExcel-tp3478981p3478981.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 normality req. for ANOVA
I am conducting an experiment with four independent variables each of which has three or more factor levels. The sample size is quite large i.e. several thousand. The dependent variable data does not pass a normality test but visually looks close to normal so is there a way to compute the affect this would have on the p-value for ANOVA or is there a way to perform an nonparametric test in R that will handle this many independent variables. Simply saying ANOVA is robust to small departures from normality is not going to be good enough for my client. I need to compute an error amount for ANOVA or find a nonparametric equivalent. Thanks, William -- View this message in context: http://r.789695.n4.nabble.com/Problems-with-normality-req-for-ANOVA-tp2310275p2310275.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] Problems with normality req. for ANOVA
I am testing normality on the studetized residuals that are generated after performing ANOVA and yes I used Levene's test to see if the variances can be assumed equal. They infact are not, but I have found a formula for determining whether the p-value for ANOVA will become larger or smaller as a result of unequal variances and unequal sample sizes. Fortuneately it turns out the p-value is greater. Despite this the ANOVA test is still significant with p=.000. The problem I have is that I am expected, by my client, to find a similiar formula that states which way the p-value would be pushed by a lack of normality. Despite numerous citations that ANOVA is robust to departures of normality my client does not care. They want numerical proof. This lead to looking for a method for estimating the effects non normality would have on the p-value for ANOVA. In other words can I build a confidence interval for the p-value? Hence the error term I am speaking of would be a the margin or error for p-value confidence interval. William W. Reith III Business Analytics J9 SAC (757)-203-3400 Best Contact From 7:00am-4:00pm J9 Office (757)-203-3772 Booz Office (757) 466-3253 Mobile (434)-989-7948 From: David Winsemius [via R] [ml-node+2310616-1859960724-371...@n4.nabble.com] Sent: Monday, August 02, 2010 1:33 PM To: Reith, William [USA] Subject: Re: Problems with normality req. for ANOVA On Aug 2, 2010, at 9:33 AM, wwreith wrote: I am conducting an experiment with four independent variables each of which has three or more factor levels. The sample size is quite large i.e. several thousand. The dependent variable data does not pass a normality test but visually looks close to normal so is there a way to compute the affect this would have on the p-value for ANOVA or is there a way to perform an nonparametric test in R that will handle this many independent variables. Simply saying ANOVA is robust to small departures from normality is not going to be good enough for my client. The statistical assumption of normality for linear models do not apply to the distribution of the dependent variable, but rather to the residuals after a model is estimated. Furthermore, it is the homoskedasticity assumption that is more commonly violated and also greater threat to validity. (And if you don't already know both of these points, then you desperately need to review your basic modeling practices.) I need to compute an error amount for ANOVA or find a nonparametric equivalent. You might get a better answer if you expressed the first part of that question in unambiguous terminology. What is error amount? For the second part, there is an entire Task View on Robust Statistical Methods. -- David Winsemius, MD West Hartford, CT __ [hidden email]https://webmail.bah.com/OWA/UrlBlockedError.aspx mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. View message @ http://r.789695.n4.nabble.com/Problems-with-normality-req-for-ANOVA-tp2310275p2310616.html To unsubscribe from Problems with normality req. for ANOVA, click here (link removed) =. -- View this message in context: http://r.789695.n4.nabble.com/Problems-with-normality-req-for-ANOVA-tp2310275p2310738.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.