Re: [R] Applying a certain formula to a repeated sample data
Thank you for providing a clarifying example. I think a useful function for you to get familiar with is the "ave" function. It is kind of like aggregate except that it works when the operation you want to apply to the group of elements will returns the same number of elements as were given to it. Also, in the future please figure out how to tell gmail to send plain text to the mailing list instead of HTML. You were lucky this time, but often HTML email gets horribly mangled as it goes through the mailing list and gets all the formatting removed. ### dta <- read.table( text = "n CR WW 1 8590 12516 2 8641 98143 3 8705 98916 4 8750 89911 5 8685 104835 6 8629 121963 7 8676 77655 1 8577 81081 2 8593 83385 3 8642 112164 4 8708 103684 5 8622 83982 6 8593 75944 7 8600 97036 1 8650 104911 2 8730 114098 3 8731 99421 4 8715 85707 5 8717 81273 6 8739 106462 7 8684 110635 1 8713 105214 2 8771 92456 3 8759 109270 4 8762 99150 5 8730 77306 6 8780 86324 7 8804 90214 1 8797 99894 2 8863 95177 3 8873 95910 4 8827 108511 5 8806 115636 6 8869 85542 7 8854 111018 1 8571 93247 2 8533 85105 3 8553 114725 4 8561 122195 5 8532 100945 6 8560 108552 7 8634 108707 1 8646 117420 2 8633 113823 3 8680 82763 4 8765 121072 5 8756 89835 6 8750 104578 7 8790 88429 ",header=TRUE) # one way to make a grouping vector dta$G <- cumsum( c( 1, diff( dta$n ) < 0 ) ) # your operation fn <- function( x ) { m <- mean( x ) ( x - m ) / m * 100 } # your operation, computing for each group gn <- function( x, g ) { ave( x, g, FUN = fn ) } # do the computations dta$CRpct <- gn( dta$CR, dta$G ) dta$WWpct <- gn( dta$WW, dta$G ) dta #>n CR WW GCRpct WWpct #> 1 1 8590 12516 1 -0.899861560 -85.4932369 #> 2 2 8641 98143 1 -0.311490540 13.7533758 #> 3 3 8705 98916 1 0.426857407 14.6493272 #> 4 4 8750 89911 1 0.946008306 4.2120148 #> 5 5 8685 104835 1 0.196123673 21.5097882 #> 6 6 8629 121963 1 -0.449930780 41.3621243 #> 7 7 8676 77655 1 0.092293493 -9.9933934 #> 8 1 8577 81081 2 -0.490594182 -10.9385886 #> 9 2 8593 83385 2 -0.304963951 -8.4078170 #> 10 3 8642 112164 2 0.263528632 23.2037610 #> 11 4 8708 103684 2 1.029253336 13.8891155 #> 12 5 8622 83982 2 0.031490843 -7.7520572 #> 13 6 8593 75944 2 -0.304963951 -16.5811987 #> 14 7 8600 97036 2 -0.223750725 6.5867850 #> 15 1 8650 104911 3 -0.682347538 4.5366096 #> 16 2 8730 114098 3 0.236197225 13.6908244 #> 17 3 8731 99421 3 0.247679034 -0.9337985 #> 18 4 8715 85707 3 0.063970082 -14.5988581 #> 19 5 8717 81273 3 0.086933701 -19.0170347 #> 20 6 8739 106462 3 0.339533510 6.0820746 #> 21 7 8684 110635 3 -0.291966014 10.2401827 #> 22 1 8713 105214 4 -0.534907614 11.6017662 #> 23 2 8771 92456 4 0.127203640 -1.9307991 #> 24 3 8759 109270 4 -0.009784895 15.9040146 #> 25 4 8762 99150 4 0.024462238 5.1696079 #> 26 5 8730 77306 4 -0.340840523 -18.0005879 #> 27 6 8780 86324 4 0.229945042 -8.4350859 #> 28 7 8804 90214 4 0.503922112 -4.3089157 #> 29 1 8797 99894 5 -0.500896767 -1.7465519 #> 30 2 8863 95177 5 0.245600995 -6.3860849 #> 31 3 8873 95910 5 0.358706717 -5.6651229 #> 32 4 8827 108511 5 -0.161579602 6.7289318 #> 33 5 8806 115636 5 -0.399101617 13.7369184 #> 34 6 8869 85542 5 0.313464428 -15.8628500 #> 35 7 8854 111018 5 0.143805846 9.1947595 #> 36 1 8571 93247 6 0.088415855 -11.0088128 #> 37 2 8533 85105 6 -0.355331643 -18.7792102 #> 38 3 8553 114725 6 -0.121780328 9.4889267 #> 39 4 8561 122195 6 -0.028359802 16.6179943 #> 40 5 8532 100945 6 -0.367009209 -3.6621512 #> 41 6 8560 108552 6 -0.040037368 3.5976637 #> 42 7 8634 108707 6 0.824102496 3.7455895 #> 43 1 8646 117420 7 -0.816125860 14.4890796 #> 44 2 8633 113823 7 -0.965257293 10.9818643 #> 45 3 8680 82763 7 -0.426089807 -19.3028471 #> 46 4 8765 121072 7 0.549000328 18.0499220 #> 47 5 8756 89835 7 0.445755490 -12.4073713 #> 48 6 8750 104578 7 0.376925598 1.9676287 #> 49 7 8790 88429 7 0.835791544 -13.7782761 #' Created on 2018-11-27 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0). ### On Wed, 28 Nov 2018, Ogbos Okike wrote: Dear Jim, I don't think my problem is clear the way I put. I have been trying to manually apply the formula to some rows. This is what I have done. I cut and past some rows from 1-7 and save each with a different file as shown below: 1 8590 12516 2 8641 98143 3 8705 98916 4 8750 89911 5 8685 104835 6 8629 121963 7 8676 77655 1 8577 81081 2 8593 83385 3 8642 112164 4 8708 103684 5 8622 83982 6 8593 75944 7 8600 97036 1 8650 104911 2 8730 114098 3 8731 99421 4 8715 85707 5 8717 81273 6 8739 106462 7 8684 110635 1 8713 105214 2 8771 92456 3 8759 109270 4 8762 99150 5 8730 77306 6 8780 86324 7 8804 90214 1 8797 99894 2 8863 95177 3 8873 95910 4 8827 108511 5 8806 115636 6 8869 85542 7 8854 111018 1 8571 93247 2 8533 85105 3 8553 114725 4 8561 122195 5 8532 100945 6 8560 108552 7 8634 108707 1 8646 117420 2
Re: [R] Applying a certain formula to a repeated sample data
Dear Jim, I don't think my problem is clear the way I put. I have been trying to manually apply the formula to some rows. This is what I have done. I cut and past some rows from 1-7 and save each with a different file as shown below: 1 8590 12516 2 8641 98143 3 8705 98916 4 8750 89911 5 8685 104835 6 8629 121963 7 8676 77655 1 8577 81081 2 8593 83385 3 8642 112164 4 8708 103684 5 8622 83982 6 8593 75944 7 8600 97036 1 8650 104911 2 8730 114098 3 8731 99421 4 8715 85707 5 8717 81273 6 8739 106462 7 8684 110635 1 8713 105214 2 8771 92456 3 8759 109270 4 8762 99150 5 8730 77306 6 8780 86324 7 8804 90214 1 8797 99894 2 8863 95177 3 8873 95910 4 8827 108511 5 8806 115636 6 8869 85542 7 8854 111018 1 8571 93247 2 8533 85105 3 8553 114725 4 8561 122195 5 8532 100945 6 8560 108552 7 8634 108707 1 8646 117420 2 8633 113823 3 8680 82763 4 8765 121072 5 8756 89835 6 8750 104578 7 8790 88429 Each of them are then read as: d1<-read.table("dat1",col.names=c("n","CR","WW")) d2<-read.table("dat2",col.names=c("n","CR","WW")) d3<-read.table("dat3",col.names=c("n","CR","WW")) d4<-read.table("dat4",col.names=c("n","CR","WW")) d5<-read.table("dat5",col.names=c("n","CR","WW")) d6<-read.table("dat6",col.names=c("n","CR","WW")) d7<-read.table("dat7",col.names=c("n","CR","WW")) And my formula for percentage change applied as follows for column 2: a1<-((d1$CR-mean(d1$CR))/mean(CR))*100 a2<-((d2$CR-mean(d2$CR))/mean(CR))*100 a3<-((d3$CR-mean(d3$CR))/mean(CR))*100 a4<-((d4$CR-mean(d4$CR))/mean(CR))*100 a5<-((d5$CR-mean(d5$CR))/mean(CR))*100 a6<-((d6$CR-mean(d6$CR))/mean(CR))*100 a7<-((d7$CR-mean(d7$CR))/mean(CR))*100 a1-a7 actually gives percentage change in the data. Instead of doing this one after the other, can you please give an indication on how I may apply this formula to the data frame with probably a code. Thank you again. Best Ogbos On Wed, Nov 28, 2018 at 5:15 AM Ogbos Okike wrote: > Dear Jim, > > I wish also to use the means calculated and apply a certain formula on > the same data frame. In particular, I would like to subtract the means of > each of these seven days from each of the seven days and and divide the > outcome by the same means. If I represent m1 by the means of each seven > days in column 1, and c1 is taken as column 1 data. My formula will be of > the form: > aa<-(c1-m1)/m1. > > I tried it on the first 7 rows and I have what I am looking for.: > -0.0089986156 > -0.0031149054 >0.0042685741 >0.0094600831 >0.0019612367 > -0.0044993078 >0.0009229349 > > But doing it manually will take much time. > > Many thanks for going a step further to assist me. > > Warmest regards. > Ogbos > > On Wed, Nov 28, 2018 at 4:31 AM Jim Lemon wrote: > >> Hi Ogbos, >> If we assume that you have a 3 column data frame named oodf, how about: >> >> oodf[,4]<-floor((cumsum(oodf[,1])-1)/28) >> col2means<-by(oodf[,2],oodf[,4],mean) >> col3means<-by(oodf[,3],oodf[,4],mean) >> >> Jim >> >> On Wed, Nov 28, 2018 at 2:06 PM Ogbos Okike >> wrote: >> > >> > Dear List, >> > I have three data-column data. The data is of the form: >> > 1 8590 12516 >> > 2 8641 98143 >> > 3 8705 98916 >> > 4 8750 89911 >> > 5 8685 104835 >> > 6 8629 121963 >> > 7 8676 77655 >> > 1 8577 81081 >> > 2 8593 83385 >> > 3 8642 112164 >> > 4 8708 103684 >> > 5 8622 83982 >> > 6 8593 75944 >> > 7 8600 97036 >> > 1 8650 104911 >> > 2 8730 114098 >> > 3 8731 99421 >> > 4 8715 85707 >> > 5 8717 81273 >> > 6 8739 106462 >> > 7 8684 110635 >> > 1 8713 105214 >> > 2 8771 92456 >> > 3 8759 109270 >> > 4 8762 99150 >> > 5 8730 77306 >> > 6 8780 86324 >> > 7 8804 90214 >> > 1 8797 99894 >> > 2 8863 95177 >> > 3 8873 95910 >> > 4 8827 108511 >> > 5 8806 115636 >> > 6 8869 85542 >> > 7 8854 111018 >> > 1 8571 93247 >> > 2 8533 85105 >> > 3 8553 114725 >> > 4 8561 122195 >> > 5 8532 100945 >> > 6 8560 108552 >> > 7 8634 108707 >> > 1 8646 117420 >> > 2 8633 113823 >> > 3 8680 82763 >> > 4 8765 121072 >> > 5 8756 89835 >> > 6 8750 104578 >> > 7 8790 88429 >> > >> > I wish to calculate average of the second and third columns based on the >> > first column for each repeated 7 days. The length of the data is 1442. >> That >> > is 206 by 7. So I should arrive at 207 data points for each of the two >> > columns after calculating the mean of each group 1-7. >> > >> > I have both tried factor/tapply and aggregate functions but seem not to >> be >> > making progress. >> > >> > Thank you very much for your idea. >> > >> > Best wishes >> > Ogbos >> > >> > [[alternative HTML version deleted]] >> > >> > __ >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > https://stat.ethz.ch/mailman/listinfo/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
Re: [R] Applying a certain formula to a repeated sample data
Dear Jim, I wish also to use the means calculated and apply a certain formula on the same data frame. In particular, I would like to subtract the means of each of these seven days from each of the seven days and and divide the outcome by the same means. If I represent m1 by the means of each seven days in column 1, and c1 is taken as column 1 data. My formula will be of the form: aa<-(c1-m1)/m1. I tried it on the first 7 rows and I have what I am looking for.: -0.0089986156 -0.0031149054 0.0042685741 0.0094600831 0.0019612367 -0.0044993078 0.0009229349 But doing it manually will take much time. Many thanks for going a step further to assist me. Warmest regards. Ogbos On Wed, Nov 28, 2018 at 4:31 AM Jim Lemon wrote: > Hi Ogbos, > If we assume that you have a 3 column data frame named oodf, how about: > > oodf[,4]<-floor((cumsum(oodf[,1])-1)/28) > col2means<-by(oodf[,2],oodf[,4],mean) > col3means<-by(oodf[,3],oodf[,4],mean) > > Jim > > On Wed, Nov 28, 2018 at 2:06 PM Ogbos Okike > wrote: > > > > Dear List, > > I have three data-column data. The data is of the form: > > 1 8590 12516 > > 2 8641 98143 > > 3 8705 98916 > > 4 8750 89911 > > 5 8685 104835 > > 6 8629 121963 > > 7 8676 77655 > > 1 8577 81081 > > 2 8593 83385 > > 3 8642 112164 > > 4 8708 103684 > > 5 8622 83982 > > 6 8593 75944 > > 7 8600 97036 > > 1 8650 104911 > > 2 8730 114098 > > 3 8731 99421 > > 4 8715 85707 > > 5 8717 81273 > > 6 8739 106462 > > 7 8684 110635 > > 1 8713 105214 > > 2 8771 92456 > > 3 8759 109270 > > 4 8762 99150 > > 5 8730 77306 > > 6 8780 86324 > > 7 8804 90214 > > 1 8797 99894 > > 2 8863 95177 > > 3 8873 95910 > > 4 8827 108511 > > 5 8806 115636 > > 6 8869 85542 > > 7 8854 111018 > > 1 8571 93247 > > 2 8533 85105 > > 3 8553 114725 > > 4 8561 122195 > > 5 8532 100945 > > 6 8560 108552 > > 7 8634 108707 > > 1 8646 117420 > > 2 8633 113823 > > 3 8680 82763 > > 4 8765 121072 > > 5 8756 89835 > > 6 8750 104578 > > 7 8790 88429 > > > > I wish to calculate average of the second and third columns based on the > > first column for each repeated 7 days. The length of the data is 1442. > That > > is 206 by 7. So I should arrive at 207 data points for each of the two > > columns after calculating the mean of each group 1-7. > > > > I have both tried factor/tapply and aggregate functions but seem not to > be > > making progress. > > > > Thank you very much for your idea. > > > > Best wishes > > Ogbos > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Applying a certain formula to a repeated sample data: SOLVED
On Wed, Nov 28, 2018 at 4:31 AM Jim Lemon wrote: > Hi Ogbos, > If we assume that you have a 3 column data frame named oodf, how about: > > Dear Jim, Thank you so much. The code just made life very easier for me. best regards Ogbos > oodf[,4]<-floor((cumsum(oodf[,1])-1)/28) > col2means<-by(oodf[,2],oodf[,4],mean) > col3means<-by(oodf[,3],oodf[,4],mean) > > Jim > > On Wed, Nov 28, 2018 at 2:06 PM Ogbos Okike > wrote: > > > > Dear List, > > I have three data-column data. The data is of the form: > > 1 8590 12516 > > 2 8641 98143 > > 3 8705 98916 > > 4 8750 89911 > > 5 8685 104835 > > 6 8629 121963 > > 7 8676 77655 > > 1 8577 81081 > > 2 8593 83385 > > 3 8642 112164 > > 4 8708 103684 > > 5 8622 83982 > > 6 8593 75944 > > 7 8600 97036 > > 1 8650 104911 > > 2 8730 114098 > > 3 8731 99421 > > 4 8715 85707 > > 5 8717 81273 > > 6 8739 106462 > > 7 8684 110635 > > 1 8713 105214 > > 2 8771 92456 > > 3 8759 109270 > > 4 8762 99150 > > 5 8730 77306 > > 6 8780 86324 > > 7 8804 90214 > > 1 8797 99894 > > 2 8863 95177 > > 3 8873 95910 > > 4 8827 108511 > > 5 8806 115636 > > 6 8869 85542 > > 7 8854 111018 > > 1 8571 93247 > > 2 8533 85105 > > 3 8553 114725 > > 4 8561 122195 > > 5 8532 100945 > > 6 8560 108552 > > 7 8634 108707 > > 1 8646 117420 > > 2 8633 113823 > > 3 8680 82763 > > 4 8765 121072 > > 5 8756 89835 > > 6 8750 104578 > > 7 8790 88429 > > > > I wish to calculate average of the second and third columns based on the > > first column for each repeated 7 days. The length of the data is 1442. > That > > is 206 by 7. So I should arrive at 207 data points for each of the two > > columns after calculating the mean of each group 1-7. > > > > I have both tried factor/tapply and aggregate functions but seem not to > be > > making progress. > > > > Thank you very much for your idea. > > > > Best wishes > > Ogbos > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Applying a certain formula to a repeated sample data
Hi Ogbos, If we assume that you have a 3 column data frame named oodf, how about: oodf[,4]<-floor((cumsum(oodf[,1])-1)/28) col2means<-by(oodf[,2],oodf[,4],mean) col3means<-by(oodf[,3],oodf[,4],mean) Jim On Wed, Nov 28, 2018 at 2:06 PM Ogbos Okike wrote: > > Dear List, > I have three data-column data. The data is of the form: > 1 8590 12516 > 2 8641 98143 > 3 8705 98916 > 4 8750 89911 > 5 8685 104835 > 6 8629 121963 > 7 8676 77655 > 1 8577 81081 > 2 8593 83385 > 3 8642 112164 > 4 8708 103684 > 5 8622 83982 > 6 8593 75944 > 7 8600 97036 > 1 8650 104911 > 2 8730 114098 > 3 8731 99421 > 4 8715 85707 > 5 8717 81273 > 6 8739 106462 > 7 8684 110635 > 1 8713 105214 > 2 8771 92456 > 3 8759 109270 > 4 8762 99150 > 5 8730 77306 > 6 8780 86324 > 7 8804 90214 > 1 8797 99894 > 2 8863 95177 > 3 8873 95910 > 4 8827 108511 > 5 8806 115636 > 6 8869 85542 > 7 8854 111018 > 1 8571 93247 > 2 8533 85105 > 3 8553 114725 > 4 8561 122195 > 5 8532 100945 > 6 8560 108552 > 7 8634 108707 > 1 8646 117420 > 2 8633 113823 > 3 8680 82763 > 4 8765 121072 > 5 8756 89835 > 6 8750 104578 > 7 8790 88429 > > I wish to calculate average of the second and third columns based on the > first column for each repeated 7 days. The length of the data is 1442. That > is 206 by 7. So I should arrive at 207 data points for each of the two > columns after calculating the mean of each group 1-7. > > I have both tried factor/tapply and aggregate functions but seem not to be > making progress. > > Thank you very much for your idea. > > Best wishes > Ogbos > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Applying a certain formula to a repeated sample data
Dear List, I have three data-column data. The data is of the form: 1 8590 12516 2 8641 98143 3 8705 98916 4 8750 89911 5 8685 104835 6 8629 121963 7 8676 77655 1 8577 81081 2 8593 83385 3 8642 112164 4 8708 103684 5 8622 83982 6 8593 75944 7 8600 97036 1 8650 104911 2 8730 114098 3 8731 99421 4 8715 85707 5 8717 81273 6 8739 106462 7 8684 110635 1 8713 105214 2 8771 92456 3 8759 109270 4 8762 99150 5 8730 77306 6 8780 86324 7 8804 90214 1 8797 99894 2 8863 95177 3 8873 95910 4 8827 108511 5 8806 115636 6 8869 85542 7 8854 111018 1 8571 93247 2 8533 85105 3 8553 114725 4 8561 122195 5 8532 100945 6 8560 108552 7 8634 108707 1 8646 117420 2 8633 113823 3 8680 82763 4 8765 121072 5 8756 89835 6 8750 104578 7 8790 88429 I wish to calculate average of the second and third columns based on the first column for each repeated 7 days. The length of the data is 1442. That is 206 by 7. So I should arrive at 207 data points for each of the two columns after calculating the mean of each group 1-7. I have both tried factor/tapply and aggregate functions but seem not to be making progress. Thank you very much for your idea. Best wishes Ogbos [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Basic optimization question (I'm a rookie)
Of course, this particular example is trivially solvable by hand: x ==y ==p/4 , a square. Note also that optimization with equality constraints are generally solvable by the method of Lagrange multipliers for smooth functions and constraints, so that numerical methods may not be needed for relatively simple cases. Cheers, Bert On Tue, Nov 27, 2018 at 3:19 PM FAIL PEDIA < soloparapaginas123456...@gmail.com> wrote: > Hello, and thanks to anyone who takes the time to read this > > I'm trying to learn to properly optimize a function with a constraint using > R. For example, maximize the area of a terrain with a maximum perimeter. > For this example the function would be: > > Area <- function(x,y){x*y} > > The restriction would be the following function: > > Perimeter <- function(x,y){2*(x+y)} > > The idea is to give a desired value to "Perimeter" and get the values of x > & y that maximize the area and respect the constraint. > > I've searched online for some time, and only found a video of a dude that > plotted the functions toggling the values to find the tangent optimum point > (something useless, because the idea is to make the optimization more > efficiently than using a paper and a pencil) > > Thanks again, and sorry if this question is silly. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [R ]Exporting rgl.snapshot and rgl.postscript
Hi Duncan Murdoch Thank you for your support. Best regards, Nhat Tran Vào Th 3, 27 thg 11, 2018 vào lúc 23:06 Duncan Murdoch < murdoch.dun...@gmail.com> đã viết: > On 27/11/2018 7:53 AM, Thanh Tran wrote: > > Dear all, > > > > > > > > I'm trying to plot a surface over the x-y plane. In my data, the response > > is KIC, and 4 factors are AC, AV, T, and Temp. I want to have response > > surface of KIC with two factors, i.e., AC and AV. A typical second-degree > > response modeling is as follows: > > > > > > > >> data<-read.csv("2.csv", header =T) > > > >> mod <- > lm(KIC~AC+I(AC^2)+AV+I(AV^2)+T+I(T^2)+Temp+I(Temp^2)+AC:AV+AC:T+AC:Temp+AV:T+AV:Temp+T:Temp, > > > > + data = data) > > > >> library(rgl) > > > >> KIC <- function(AC, AV, Temp, T) predict(mod, newdata = data.frame(AC, > AV, Temp, T)) > > > >> persp3d(KIC, xlim = c(4, 5), # The range of values for AC > > > > + ylim = c(4, 7), # The range for AV > > > > + xlab = "AC", ylab = "AV", zlab = "KIC", > > > > + col = "lightblue", > > > > + otherargs = list(Temp = 15, T = 40)) > > > >> rgl.snapshot("1.png", fmt = "png", top = TRUE ) > > > >> rgl.postscript("1.pdf","pdf") > > > > > > > > The problem is that the figure created by *rgl.snapshot* (attached Figure > > 1) has low quality, while the figure created by *rgl.postscript* > (attached > > Figure 2) doesn’t have adequate details. > > You can improve the rgl.snapshot output by starting from a large window. > You can do this either by using the mouse to enlarge the window, or > specifying values for windowRect in par3d() or open3d(), e.g. > > open3d(windowRect=c(0,0, 1800, 1800)) > > Whether very large values will be respected depends on the system. For > example, my Macbook Air reduces that request so the whole window is > visible, > > > par3d("windowRect") > [1]0 45 1440 901 > > You can set the default to be a large window using > > r3dDefaults <- getr3dDefaults() > r3dDefaults$windowRect <- c(0,0, 1800, 1800) > > (This will only be respected by the *3d functions like open3d(), not the > low-level rgl.* functions like rgl.open().) > > The rgl.postscript() display is limited by what the GL2PS library can > do, so if it doesn't do what you want, there's not much you can do to > improve it. > > Duncan Murdoch > > > > > > > > > Can somebody please show me how to properly export the file? I would > prefer > > the Figure have the TIFF or PDF with the resolution 600 dpi. I really > > appreciate your support and help. > > > > > > > > Best regards, > > > > Nhat Tran > > > > > > > > Ps: I also added a CSV file for practicing R. > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Basic optimization question (I'm a rookie)
Hi, R is quite good at optimization. Here's a basic tutorial: https://www.is.uni-freiburg.de/resources/computational-economics/5_OptimizationR.pdf There are a LOT of possibilities: https://cran.r-project.org/web/views/Optimization.html Sarah On Tue, Nov 27, 2018 at 6:19 PM FAIL PEDIA wrote: > > Hello, and thanks to anyone who takes the time to read this > > I'm trying to learn to properly optimize a function with a constraint using > R. For example, maximize the area of a terrain with a maximum perimeter. > For this example the function would be: > > Area <- function(x,y){x*y} > > The restriction would be the following function: > > Perimeter <- function(x,y){2*(x+y)} > > The idea is to give a desired value to "Perimeter" and get the values of x > & y that maximize the area and respect the constraint. > > I've searched online for some time, and only found a video of a dude that > plotted the functions toggling the values to find the tangent optimum point > (something useless, because the idea is to make the optimization more > efficiently than using a paper and a pencil) > > Thanks again, and sorry if this question is silly. > -- Sarah Goslee (she/her) http://www.sarahgoslee.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Basic optimization question (I'm a rookie)
Hello, and thanks to anyone who takes the time to read this I'm trying to learn to properly optimize a function with a constraint using R. For example, maximize the area of a terrain with a maximum perimeter. For this example the function would be: Area <- function(x,y){x*y} The restriction would be the following function: Perimeter <- function(x,y){2*(x+y)} The idea is to give a desired value to "Perimeter" and get the values of x & y that maximize the area and respect the constraint. I've searched online for some time, and only found a video of a dude that plotted the functions toggling the values to find the tangent optimum point (something useless, because the idea is to make the optimization more efficiently than using a paper and a pencil) Thanks again, and sorry if this question is silly. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Bootstrapping One- and Two-Sample Hypothesis Tests of Proportion
Hello R Experts! Does anyone know of a relatively straightforward way to bootstrap hypothesis tests for proportion in R? Thanks in advance! Janh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] gemo_text issue
Hi, I had to include library(reshape2) to get things working as you use melt(). Explicitly setting the x and y values in geom_text() is needed since you are providing new data. zp1 <- zp1 + geom_text(data=test2, x=test2$con, y=test2$Prob, label = test2$Project, size = 6, color = "white") Cheers, Ben > On Nov 27, 2018, at 3:04 PM, Reith, William [USA] > wrote: > > I am experiencing issues with trying to label points added to a ggplot via > geom_point. I think an underlying issue is the fact that I already used > ggplot function to create a 5x5 risk matrix "background", but I am not > certain. I have tried multiple solutions online but cannot find one that has > a similar the background plotting I am attempting. > > I have attached the .R file and a picture of what I am creating minus the > buggy text labels. Code is also pasted below. > > Thanks, > > William > > > library(ggplot2) > > Project<-c("C","C","C","C","C","B","B","B","D","E","E","F","F","F","F") > Prob<-c(3,3,3,2,2,2,2,2,3,4,3,5,4,3,3) > con<-c(3.675941831,2.354582402,2.354582402,2.354582402,1.95075378,3.0602443,3.0602443,3.283695274,1.904452395,3.579022044,3.579022044,2.58190428,1.76065948,2.365243619,1.354491286) > test2<-data.frame(Project,Prob,con) > > ### build risk coloring matrix ### > myData <- matrix(c(1,2,3,3,3,1,2,2,3,3,1,1,2,2,3,1,1,2,2,2,1,1,1,1,2), nrow = > 5, ncol = 5, byrow = TRUE) > rownames(myData) <- c("5", "4", "3", "2","1") > colnames(myData) <- c("1", "2", "3", "4","5") > > ### convert to data frame ### > longData <- melt(myData) > colnames(longData) <- c("Probability", "Consequence", "value") > longData$value<-as.factor(longData$value) > > ### define color tiles ### > color<-c("green" ,"green" ,"green","green" ,"green", >"yellow","yellow","green","green" ,"green", >"red" ,"yellow","yellow","yellow","green", >"red" ,"red" ,"yellow","yellow","green", >"red" ,"red" ,"red" ,"yellow","yellow") > > ### create color background 5x5 ### > zp1 <- ggplot(longData,aes(x = Consequence, y = Probability)) #, fill = > value)) > zp1 <- zp1 + geom_tile(fill = color) > zp1 <- zp1 + scale_x_continuous(breaks = 0:6, expand = c(0, 0)) > zp1 <- zp1 + scale_y_continuous(breaks = 0:6, expand = c(0, 0)) > zp1 <- zp1 + coord_fixed() > zp1 <- zp1 + theme_bw() > print(zp1) > > ### Add title and lines ### > zp1 <- zp1 + ggtitle("5x5 Plot")+theme(plot.title = element_text(hjust = 0.5)) > zp1 <- zp1 + geom_vline(xintercept=c(1.5:5.5)) > zp1 <- zp1 + geom_hline(yintercept=c(1.5:5.5)) > print(zp1) > > ### Plot points ### > zp1 <- zp1 + geom_point(data=test2, x=test2$con, y=test2$Prob, alpha = 1, > size = 9, color = "blue") > print(zp1) > > ### This is the line I cannot get working; tried multiple approaches ### > ### intent is to add white labels to plotted points ### > zp1 <- zp1 + geom_text(data=test2, label = test2$Project, size = 6, color = > "white") > print(zp1) > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. Ben Tupper Bigelow Laboratory for Ocean Sciences 60 Bigelow Drive, P.O. Box 380 East Boothbay, Maine 04544 http://www.bigelow.org Ecological Forecasting: https://eco.bigelow.org/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] gemo_text issue
I am experiencing issues with trying to label points added to a ggplot via geom_point. I think an underlying issue is the fact that I already used ggplot function to create a 5x5 risk matrix "background", but I am not certain. I have tried multiple solutions online but cannot find one that has a similar the background plotting I am attempting. I have attached the .R file and a picture of what I am creating minus the buggy text labels. Code is also pasted below. Thanks, William library(ggplot2) Project<-c("C","C","C","C","C","B","B","B","D","E","E","F","F","F","F") Prob<-c(3,3,3,2,2,2,2,2,3,4,3,5,4,3,3) con<-c(3.675941831,2.354582402,2.354582402,2.354582402,1.95075378,3.0602443,3.0602443,3.283695274,1.904452395,3.579022044,3.579022044,2.58190428,1.76065948,2.365243619,1.354491286) test2<-data.frame(Project,Prob,con) ### build risk coloring matrix ### myData <- matrix(c(1,2,3,3,3,1,2,2,3,3,1,1,2,2,3,1,1,2,2,2,1,1,1,1,2), nrow = 5, ncol = 5, byrow = TRUE) rownames(myData) <- c("5", "4", "3", "2","1") colnames(myData) <- c("1", "2", "3", "4","5") ### convert to data frame ### longData <- melt(myData) colnames(longData) <- c("Probability", "Consequence", "value") longData$value<-as.factor(longData$value) ### define color tiles ### color<-c("green" ,"green" ,"green","green" ,"green", "yellow","yellow","green","green" ,"green", "red" ,"yellow","yellow","yellow","green", "red" ,"red" ,"yellow","yellow","green", "red" ,"red" ,"red" ,"yellow","yellow") ### create color background 5x5 ### zp1 <- ggplot(longData,aes(x = Consequence, y = Probability)) #, fill = value)) zp1 <- zp1 + geom_tile(fill = color) zp1 <- zp1 + scale_x_continuous(breaks = 0:6, expand = c(0, 0)) zp1 <- zp1 + scale_y_continuous(breaks = 0:6, expand = c(0, 0)) zp1 <- zp1 + coord_fixed() zp1 <- zp1 + theme_bw() print(zp1) ### Add title and lines ### zp1 <- zp1 + ggtitle("5x5 Plot")+theme(plot.title = element_text(hjust = 0.5)) zp1 <- zp1 + geom_vline(xintercept=c(1.5:5.5)) zp1 <- zp1 + geom_hline(yintercept=c(1.5:5.5)) print(zp1) ### Plot points ### zp1 <- zp1 + geom_point(data=test2, x=test2$con, y=test2$Prob, alpha = 1, size = 9, color = "blue") print(zp1) ### This is the line I cannot get working; tried multiple approaches ### ### intent is to add white labels to plotted points ### zp1 <- zp1 + geom_text(data=test2, label = test2$Project, size = 6, color = "white") print(zp1) __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] EXAMPLE OF HOW TO USE R FOR EXPONENTIAL DISTRIBUTION & EXPONENTIAL REGRESSION
Thank you for the clarification. I'll share a function I got tomorrow morning. Regards On Tue, 27 Nov 2018, 18:38 Bert Gunter, wrote: > ... but do note that a nonlinear fit to the raw data will give a(somewhat) > different result than a linear fit to the transformed data. In the former, > the errors are additive and in the latter they are multiplicative. Etc. > > Cheers, > Bert > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Tue, Nov 27, 2018 at 9:11 AM Sarah Goslee > wrote: > >> Hi, >> >> Please also include R-help in your replies - I can't provide >> one-on-one tutorials. >> >> Without knowing where you got your sample code, it's hard to help. But >> what are you trying to do? >> >> It doesn't have to be that complicated: >> >> x <- 1:10 >> y <- c(0.00, 0.00,0.0033,0.0009,0.0025,0.0653,0.1142,0.2872,0,1 ) >> plot(x, y, pch=20) >> >> # basic straight line of fit >> fit <- glm(y~x) >> >> abline(fit, col="blue", lwd=2) >> exp.lm <- lm(y ~ exp(x)) >> lines(1:10, predict(exp.lm, newdata=data.frame(x=1:10))) >> >> >> On Tue, Nov 27, 2018 at 9:34 AM Tolulope Adeagbo >> wrote: >> > >> > Hello, >> > >> > So I found this example online but there seems to be an issue with the >> "Start" points. the result is giving somewhat a straight line >> > >> > # get underlying plot >> > x <- 1:10 >> > y <- c(0.00, 0.00,0.0033,0.0009,0.0025,0.0653,0.1142,0.2872,0,1 ) >> > plot(x, y, pch=20) >> > >> > # basic straight line of fit >> > fit <- glm(y~x) >> > co <- coef(fit) >> > abline(fit, col="blue", lwd=2) >> > >> > # exponential >> > f <- function(x,a,b) {a * exp(b * x)} >> > fit <- nls(y ~ f(x,a,b), start = c(a=1 , b=c(0,1))) >> > co <- coef(fit) >> > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="green", lwd=2) >> > >> > >> > # exponential >> > f <- function(x,a,b) {a * exp(b * x)} >> > fit <- nls(y ~ f(x,a,b), start = c(a=1, b=1)) >> > co <- coef(fit) >> > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="green", lwd=2) >> > # logarithmic >> > f <- function(x,a,b) {a * log(x) + b} >> > fit <- nls(y ~ f(x,a,b), start = c(a=1, b=1)) >> > co <- coef(fit) >> > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="orange", lwd=2) >> > >> > # polynomial >> > f <- function(x,a,b,d) {(a*x^2) + (b*x) + d} >> > fit <- nls(y ~ f(x,a,b,d), start = c(a=1, b=1, d=1)) >> > co <- coef(fit) >> > curve(f(x, a=co[1], b=co[2], d=co[3]), add = TRUE, col="pink", lwd=2) >> > >> > On Tue, Nov 27, 2018 at 12:28 PM Sarah Goslee >> wrote: >> >> >> >> Hi, >> >> >> >> Using rseek.org to search for exponential regression turns up lots of >> information, as does using Google. >> >> >> >> Which tutorials have you worked thru already, and what else are you >> looking for? >> >> >> >> Sarah >> >> >> >> On Tue, Nov 27, 2018 at 5:44 AM Tolulope Adeagbo < >> tolulopeadea...@gmail.com> wrote: >> >>> >> >>> Good day, >> >>> Please i nee useful materials to understand how to use R for >> exponential >> >>> regression. >> >>> Many thanks. >> >> >> >> >> -- >> Sarah Goslee (she/her) >> http://www.numberwright.com >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] EXAMPLE OF HOW TO USE R FOR EXPONENTIAL DISTRIBUTION & EXPONENTIAL REGRESSION
... but do note that a nonlinear fit to the raw data will give a(somewhat) different result than a linear fit to the transformed data. In the former, the errors are additive and in the latter they are multiplicative. Etc. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Nov 27, 2018 at 9:11 AM Sarah Goslee wrote: > Hi, > > Please also include R-help in your replies - I can't provide > one-on-one tutorials. > > Without knowing where you got your sample code, it's hard to help. But > what are you trying to do? > > It doesn't have to be that complicated: > > x <- 1:10 > y <- c(0.00, 0.00,0.0033,0.0009,0.0025,0.0653,0.1142,0.2872,0,1 ) > plot(x, y, pch=20) > > # basic straight line of fit > fit <- glm(y~x) > > abline(fit, col="blue", lwd=2) > exp.lm <- lm(y ~ exp(x)) > lines(1:10, predict(exp.lm, newdata=data.frame(x=1:10))) > > > On Tue, Nov 27, 2018 at 9:34 AM Tolulope Adeagbo > wrote: > > > > Hello, > > > > So I found this example online but there seems to be an issue with the > "Start" points. the result is giving somewhat a straight line > > > > # get underlying plot > > x <- 1:10 > > y <- c(0.00, 0.00,0.0033,0.0009,0.0025,0.0653,0.1142,0.2872,0,1 ) > > plot(x, y, pch=20) > > > > # basic straight line of fit > > fit <- glm(y~x) > > co <- coef(fit) > > abline(fit, col="blue", lwd=2) > > > > # exponential > > f <- function(x,a,b) {a * exp(b * x)} > > fit <- nls(y ~ f(x,a,b), start = c(a=1 , b=c(0,1))) > > co <- coef(fit) > > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="green", lwd=2) > > > > > > # exponential > > f <- function(x,a,b) {a * exp(b * x)} > > fit <- nls(y ~ f(x,a,b), start = c(a=1, b=1)) > > co <- coef(fit) > > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="green", lwd=2) > > # logarithmic > > f <- function(x,a,b) {a * log(x) + b} > > fit <- nls(y ~ f(x,a,b), start = c(a=1, b=1)) > > co <- coef(fit) > > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="orange", lwd=2) > > > > # polynomial > > f <- function(x,a,b,d) {(a*x^2) + (b*x) + d} > > fit <- nls(y ~ f(x,a,b,d), start = c(a=1, b=1, d=1)) > > co <- coef(fit) > > curve(f(x, a=co[1], b=co[2], d=co[3]), add = TRUE, col="pink", lwd=2) > > > > On Tue, Nov 27, 2018 at 12:28 PM Sarah Goslee > wrote: > >> > >> Hi, > >> > >> Using rseek.org to search for exponential regression turns up lots of > information, as does using Google. > >> > >> Which tutorials have you worked thru already, and what else are you > looking for? > >> > >> Sarah > >> > >> On Tue, Nov 27, 2018 at 5:44 AM Tolulope Adeagbo < > tolulopeadea...@gmail.com> wrote: > >>> > >>> Good day, > >>> Please i nee useful materials to understand how to use R for > exponential > >>> regression. > >>> Many thanks. > >> > > > -- > Sarah Goslee (she/her) > http://www.numberwright.com > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] EXAMPLE OF HOW TO USE R FOR EXPONENTIAL DISTRIBUTION & EXPONENTIAL REGRESSION
Hi, Please also include R-help in your replies - I can't provide one-on-one tutorials. Without knowing where you got your sample code, it's hard to help. But what are you trying to do? It doesn't have to be that complicated: x <- 1:10 y <- c(0.00, 0.00,0.0033,0.0009,0.0025,0.0653,0.1142,0.2872,0,1 ) plot(x, y, pch=20) # basic straight line of fit fit <- glm(y~x) abline(fit, col="blue", lwd=2) exp.lm <- lm(y ~ exp(x)) lines(1:10, predict(exp.lm, newdata=data.frame(x=1:10))) On Tue, Nov 27, 2018 at 9:34 AM Tolulope Adeagbo wrote: > > Hello, > > So I found this example online but there seems to be an issue with the > "Start" points. the result is giving somewhat a straight line > > # get underlying plot > x <- 1:10 > y <- c(0.00, 0.00,0.0033,0.0009,0.0025,0.0653,0.1142,0.2872,0,1 ) > plot(x, y, pch=20) > > # basic straight line of fit > fit <- glm(y~x) > co <- coef(fit) > abline(fit, col="blue", lwd=2) > > # exponential > f <- function(x,a,b) {a * exp(b * x)} > fit <- nls(y ~ f(x,a,b), start = c(a=1 , b=c(0,1))) > co <- coef(fit) > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="green", lwd=2) > > > # exponential > f <- function(x,a,b) {a * exp(b * x)} > fit <- nls(y ~ f(x,a,b), start = c(a=1, b=1)) > co <- coef(fit) > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="green", lwd=2) > # logarithmic > f <- function(x,a,b) {a * log(x) + b} > fit <- nls(y ~ f(x,a,b), start = c(a=1, b=1)) > co <- coef(fit) > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="orange", lwd=2) > > # polynomial > f <- function(x,a,b,d) {(a*x^2) + (b*x) + d} > fit <- nls(y ~ f(x,a,b,d), start = c(a=1, b=1, d=1)) > co <- coef(fit) > curve(f(x, a=co[1], b=co[2], d=co[3]), add = TRUE, col="pink", lwd=2) > > On Tue, Nov 27, 2018 at 12:28 PM Sarah Goslee wrote: >> >> Hi, >> >> Using rseek.org to search for exponential regression turns up lots of >> information, as does using Google. >> >> Which tutorials have you worked thru already, and what else are you looking >> for? >> >> Sarah >> >> On Tue, Nov 27, 2018 at 5:44 AM Tolulope Adeagbo >> wrote: >>> >>> Good day, >>> Please i nee useful materials to understand how to use R for exponential >>> regression. >>> Many thanks. >> -- Sarah Goslee (she/her) http://www.numberwright.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] [R ]Exporting rgl.snapshot and rgl.postscript
On 27/11/2018 7:53 AM, Thanh Tran wrote: Dear all, I'm trying to plot a surface over the x-y plane. In my data, the response is KIC, and 4 factors are AC, AV, T, and Temp. I want to have response surface of KIC with two factors, i.e., AC and AV. A typical second-degree response modeling is as follows: data<-read.csv("2.csv", header =T) mod <- lm(KIC~AC+I(AC^2)+AV+I(AV^2)+T+I(T^2)+Temp+I(Temp^2)+AC:AV+AC:T+AC:Temp+AV:T+AV:Temp+T:Temp, + data = data) library(rgl) KIC <- function(AC, AV, Temp, T) predict(mod, newdata = data.frame(AC, AV, Temp, T)) persp3d(KIC, xlim = c(4, 5), # The range of values for AC + ylim = c(4, 7), # The range for AV + xlab = "AC", ylab = "AV", zlab = "KIC", + col = "lightblue", + otherargs = list(Temp = 15, T = 40)) rgl.snapshot("1.png", fmt = "png", top = TRUE ) rgl.postscript("1.pdf","pdf") The problem is that the figure created by *rgl.snapshot* (attached Figure 1) has low quality, while the figure created by *rgl.postscript* (attached Figure 2) doesn’t have adequate details. You can improve the rgl.snapshot output by starting from a large window. You can do this either by using the mouse to enlarge the window, or specifying values for windowRect in par3d() or open3d(), e.g. open3d(windowRect=c(0,0, 1800, 1800)) Whether very large values will be respected depends on the system. For example, my Macbook Air reduces that request so the whole window is visible, > par3d("windowRect") [1]0 45 1440 901 You can set the default to be a large window using r3dDefaults <- getr3dDefaults() r3dDefaults$windowRect <- c(0,0, 1800, 1800) (This will only be respected by the *3d functions like open3d(), not the low-level rgl.* functions like rgl.open().) The rgl.postscript() display is limited by what the GL2PS library can do, so if it doesn't do what you want, there's not much you can do to improve it. Duncan Murdoch Can somebody please show me how to properly export the file? I would prefer the Figure have the TIFF or PDF with the resolution 600 dpi. I really appreciate your support and help. Best regards, Nhat Tran Ps: I also added a CSV file for practicing R. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 ]Exporting rgl.snapshot and rgl.postscript
Dear all, I'm trying to plot a surface over the x-y plane. In my data, the response is KIC, and 4 factors are AC, AV, T, and Temp. I want to have response surface of KIC with two factors, i.e., AC and AV. A typical second-degree response modeling is as follows: > data<-read.csv("2.csv", header =T) > mod <- > lm(KIC~AC+I(AC^2)+AV+I(AV^2)+T+I(T^2)+Temp+I(Temp^2)+AC:AV+AC:T+AC:Temp+AV:T+AV:Temp+T:Temp, + data = data) > library(rgl) > KIC <- function(AC, AV, Temp, T) predict(mod, newdata = data.frame(AC, AV, > Temp, T)) > persp3d(KIC, xlim = c(4, 5), # The range of values for AC + ylim = c(4, 7), # The range for AV + xlab = "AC", ylab = "AV", zlab = "KIC", + col = "lightblue", + otherargs = list(Temp = 15, T = 40)) > rgl.snapshot("1.png", fmt = "png", top = TRUE ) > rgl.postscript("1.pdf","pdf") The problem is that the figure created by *rgl.snapshot* (attached Figure 1) has low quality, while the figure created by *rgl.postscript* (attached Figure 2) doesn’t have adequate details. Can somebody please show me how to properly export the file? I would prefer the Figure have the TIFF or PDF with the resolution 600 dpi. I really appreciate your support and help. Best regards, Nhat Tran Ps: I also added a CSV file for practicing R. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] EXAMPLE OF HOW TO USE R FOR EXPONENTIAL DISTRIBUTION & EXPONENTIAL REGRESSION
Hi, Using rseek.org to search for exponential regression turns up lots of information, as does using Google. Which tutorials have you worked thru already, and what else are you looking for? Sarah On Tue, Nov 27, 2018 at 5:44 AM Tolulope Adeagbo wrote: > Good day, > Please i nee useful materials to understand how to use R for exponential > regression. > Many thanks. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Sarah Goslee (she/her) http://www.sarahgoslee.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] EXAMPLE OF HOW TO USE R FOR EXPONENTIAL DISTRIBUTION & EXPONENTIAL REGRESSION
Good day, Please i nee useful materials to understand how to use R for exponential regression. Many thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.