Further to my email below, I have just realised that I forgot to include the specification of L and R. Hence, the code needs to include the following additional lines at the start;- L<-7.5e6 R<-2.5e6 Apologies for any confusion caused! Best regards, Tony> On 12 Jul 2017, at 10:03 AM, HUL-Anthony Egerton <aegerton at huntingtonunderwriting.com> wrote: > > I am trying to code a basic Monte Carlo Simulation in R where a Poisson distribution generates a frequency output that is then input into a Lognormal distribution, which produces a different, independent severity for each incidence. The individual incidences are then summed to produce an aggregate amount per period/iteration. > > Here is the code;- > > scale<-15.08707 > shape<-0.8592507 > lambda.risk<-1.75 > L<-7.5e5 > R<-2.5e6 > iterations<-replicate(10000,{ > claims1<-0 > claims2<-0 > claims3<-0 > claims4<-0 > claims5<-0 > claims6<-0 > claims7<-0 > claims<-c(claims1,claims2,claims3,claims4,claims5,claims6,claims7) > freq<-(qpois(runif(1),lambda.risk)) > sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) > if(freq>=1){claims1<-sev} > sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) > if(freq>=2){claims2<-sev} > sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) > if (freq>=3) {claims3<-sev} > sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) > if (freq>=4) {claims4<-sev} > sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) > if (freq>=5) {claims5<-sev} > sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) > if (freq>=6) {claims6<-sev} > sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) > if (freq>=7) {claims7<-sev} > claims<-c(claims1,claims2,claims3,claims4,claims5,claims6,claims7) > min(22.5e6,sum(claims)) > }) > > I am new to R, but am sure that there must be a simpler way to code this process. > > Furthermore, as the Poisson lambda increases, there is a need to include provision for potentially more incidences, which will require a manual expansion of the code to claims8, claims9 etc. > > Can you assist, please? > > Best regards, > > Anthony A H Egerton MA MBA ACII > ?????? > HUNTINGTON UNDERWRITING LIMITED > Labuan FT, Malaysia > > > > CONFIDENTIALITY NOTE: > > The information contained in this email message may be legally privileged and contain confidential information and is intended only for the use of the individual or entity to whom it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copy of this message is strictly prohibited. If you have received this email in error, please immediately delete this message. > > Begin forwarded message: > >> From: r-help-request at r-project.org >> Date: 8 July 2017 at 6:00:02 PM SGT >> To: r-help at r-project.org >> Subject: R-help Digest, Vol 173, Issue 8 >> Reply-To: r-help at r-project.org >> >> Send R-help mailing list submissions to >> r-help at r-project.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >> https://stat.ethz.ch/mailman/listinfo/r-help >> or, via email, send a message with subject or body 'help' to >> r-help-request at r-project.org >> >> You can reach the person managing the list at >> r-help-owner at r-project.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of R-help digest..." >> >> >> Today's Topics: >> >> 1. R loop function in Tableau (Dai, Shengyu) >> 2. Factor vs character in a data.frame vs vector (John Kane) >> 3. Re: Factor vs character in a data.frame vs vector (Marc Schwartz) >> 4. Re: Scoring and Ranking Methods (David Winsemius) >> 5. Re: R loop function in Tableau (David Winsemius) >> 6. Re: [Rd] italic font on cairo devices in R 3.4 (frederik at ofb.net) >> 7. Re: [Rd] italic font on cairo devices in R 3.4 (frederik at ofb.net) >> 8. Beginner s quwry about cfa in lavaan (Martina Hule?ov?) >> 9. Re: [Rd] italic font on cairo devices in R 3.4 (Ilia Kats) >> 10. Re: Beginner s quwry about cfa in lavaan (Bert Gunter) >> 11. Re: Factor vs character in a data.frame vs vector (Marc Schwartz) >> 12. Re: Factor vs character in a data.frame vs vector (John Kane) >> 13. Re: [Rd] italic font on cairo devices in R 3.4 (Yixuan Qiu) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Thu, 06 Jul 2017 17:19:47 -0400 >> From: "Dai, Shengyu" <dais2 at rpi.edu> >> To: <r-help at r-project.org> >> Subject: [R] R loop function in Tableau >> Message-ID: <15947CD3-CD7B-4BB6-A994-D49D514DF0DE at rpi.edu> >> Content-Type: text/plain; charset="UTF-8" >> >> Hi R helpers, >> >> >> >> I hope this email finds you well. >> >> >> >> I am having trouble with R loop function in Tableau. Please see the attachment of a simple dataset. The problem is to test whether the value of columns is match. >> >> >> >> Because Tableau do not have iteration function, I coded ?if statement? in Tableau to realize the function, which is slow if having huge amount of data. I wonder to integrate Tableau with R studio to realize this functionality. >> >> >> >> I did not find too much useful information online and I am asking helps for any examples of related low-level data calculation. >> >> >> >> Thank you very much. Your helps and supports are really appreciated! >> >> >> >> Best, >> >> >> >> -- >> >> >> >> Shengyu (Freddy) Dai >> >> Master of Science in Business Analytics >> >> Lally School of Management >> >> Rensselaer Polytechnic Institute >> >> Mobile: (513)328-5659 >> >> >> >> >> >> ------------------------------ >> >> Message: 2 >> Date: Fri, 7 Jul 2017 11:03:51 +0000 >> From: John Kane <jrkrideau at yahoo.ca> >> To: R R-help <r-help at stat.math.ethz.ch> >> Subject: [R] Factor vs character in a data.frame vs vector >> Message-ID: <184884580.507511.1499425431478 at mail.yahoo.com> >> Content-Type: text/plain; charset="UTF-8" >> >> This is not? serious problem but I just wonder if someone can explain what is happening. >> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. >> Thanks >> >> #===============================================>> dat1 <- data.frame(aa = letters[1:10]) >> str(dat1) >> data.frame':????10 obs. of??1 variable: >> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>> bb = letters[1:10] >> str(bb) >> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >> #=============================================================>> >> >> [[alternative HTML version deleted]] >> >> >> >> ------------------------------ >> >> Message: 3 >> Date: Fri, 7 Jul 2017 09:37:12 -0500 >> From: Marc Schwartz <marc_schwartz at me.com> >> To: John Kane <jrkrideau at yahoo.ca> >> Cc: R R-help <r-help at stat.math.ethz.ch> >> Subject: Re: [R] Factor vs character in a data.frame vs vector >> Message-ID: <36A7CFEC-57B6-4652-BC93-AB9E0EED14AF at me.com> >> Content-Type: text/plain; charset="us-ascii" >> >> >>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <r-help at r-project.org> wrote: >>> >>> This is not serious problem but I just wonder if someone can explain what is happening. >>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character. It's probably something simple that I have read and forgotten but I thought I'd ask. >>> Thanks >>> >>> #===============================================>>> dat1 <- data.frame(aa = letters[1:10]) >>> str(dat1) >>> data.frame': 10 obs. of 1 variable: >>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>> bb = letters[1:10] >>> str(bb) >>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>> #=============================================================>>> >> >> >> See the 'stringsAsFactors' argument in ?data.frame. >> >> dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE) >> >>> str(dat1) >> 'data.frame': 10 obs. of 1 variable: >> $ aa: chr "a" "b" "c" "d" ... >> >> >> Regards, >> >> Marc Schwartz >> >> >> >> ------------------------------ >> >> Message: 4 >> Date: Fri, 7 Jul 2017 08:47:57 -0700 >> From: David Winsemius <dwinsemius at comcast.net> >> To: Dhivya Narayanasamy <dhiv.shreya at gmail.com> >> Cc: r-help mailing list <r-help at r-project.org> >> Subject: Re: [R] Scoring and Ranking Methods >> Message-ID: <B6A35831-5E7D-407A-BB82-504F33E0F488 at comcast.net> >> Content-Type: text/plain; charset=us-ascii >> >> >>> On Jul 7, 2017, at 2:29 AM, Dhivya Narayanasamy <dhiv.shreya at gmail.com> wrote: >>> >>> Hi, >>> >>> I am doing predictive modelling of Multivariate Time series Data of a Motor >>> in R using various models such as Arima, H2O.Randomforest, glmnet, lm and >>> few other models. >>> >>> I created a function to select a model of our choice and do prediction. >>> >>> Model1 <- function(){ >>> .. >>> return() >>> } >> >> That looks like a prescription for serious disappointment. I seriously doubt that you have done any testing using similar code. You would have created a function that returns NULL. I get the sense that you need to study and work through the examples in the "Introduction to R" document. >> >> >> >>> Model2 <- function(){ >>> ... >>> return() >>> } >>> Model3 <- function(){ >>> ... >>> return() >>> } >>> main <- function(n){ >>> if(n == 1) { >>> Model1() >>> } >>> else if(n == 2){ >>> Model2() >>> } >>> else if(n == 3){ >>> Model3() >>> }} >>> Now I am supposed to automate these models which gives RMSE and MAPE of >>> each model. I would like to provide scores (eg. out of 5) for each model >>> based on the performance. For example, if Arima gives a low RMSE than other >>> models, it will be scored high and the second lowest RMSE model will score >>> a less than Arima and so on. >>> >>> And every time i run those models with different input Data [motor2, motor3 >>> ..], it must give the mean score of a model. what I mean to say is, >>> >>> 1. for motor1 it will give scores of each model, let's say *s1*. >>> 2. for motor2 run it give scores of each model, and let's call it *s2*. >>> And i want a mean score of that model every time i run it with different >>> input. It is more like scoring and ranking method. >>> >>> Are there any methods or packages in R that can give a glimpse of how it is >>> done? or any examples? Any suggestions would be very helpful. >> >> The 'switch'-function can dispatch to different functions on the basis of the value of an indicator variable. >> >> >>> >>> Thank you. >>> Dhivya >>> >>> [[alternative HTML version deleted]] >> >> Please read the Posting Guide. Rhelp is a plain text mailing list. >>> >>> ______________________________________________ >>> R-help at 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. >> >> David Winsemius >> Alameda, CA, USA >> >> >> >> ------------------------------ >> >> Message: 5 >> Date: Fri, 7 Jul 2017 08:57:50 -0700 >> From: David Winsemius <dwinsemius at comcast.net> >> To: "Dai, Shengyu" <dais2 at rpi.edu> >> Cc: r-help at r-project.org >> Subject: Re: [R] R loop function in Tableau >> Message-ID: <5B17A446-46C5-4371-94D3-A5C9A7CA6E7B at comcast.net> >> Content-Type: text/plain; charset=utf-8 >> >> >>> On Jul 6, 2017, at 2:19 PM, Dai, Shengyu <dais2 at rpi.edu> wrote: >>> >>> Hi R helpers, >>> >>> >>> >>> I hope this email finds you well. >>> >>> >>> >>> I am having trouble with R loop function in Tableau. >>> >> >> There is no "R loop function". (There is an R `for`-function.) If you are having trouble with code then it should be provided. If the problem is with the Tableau code then this is the wrong place. Tableau is not either free or open source. You would in that case need to contact Tableau or get assistance from your academic institution. >> >>> Please see the attachment of a simple dataset. >> >> No data attached. Probably scrubbed by the mail server. Any data needs to be a .txt file. >> >>> The problem is to test whether the value of columns is match. >> >> There is a `match` function. It's vectorized, so may not need to be wrapped with a function that would provide looping. >> >>> >>> Because Tableau do not have iteration function, I coded ?if statement? in Tableau to realize the function, which is slow if having huge amount of data. I wonder to integrate Tableau with R studio to realize this functionality. >>> >>> >>> >>> I did not find too much useful information online and I am asking helps for any examples of related low-level data calculation. >> >> That is then the fault of Tableau (if true), since there is a huge amount of online documentation for R. The Rhelp Archives and StackOverflow have thousands of worked examples of "low-level data calculation". I suspect with estimated probability approaching unity that StackOverflow will have questions tagged jointly with [r] and [tableau]. >> >> >>> >>> Thank you very much. Your helps and supports are really appreciated! >>> >>> >>> >>> Best, >>> >>> >>> >>> -- >>> >>> >>> >>> Shengyu (Freddy) Dai >>> >>> Master of Science in Business Analytics >>> >>> Lally School of Management >>> >>> Rensselaer Polytechnic Institute >>> >>> Mobile: (513)328-5659 >>> >>> >>> >>> ______________________________________________ >>> R-help at 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. >> >> David Winsemius >> Alameda, CA, USA >> >> >> >> ------------------------------ >> >> Message: 6 >> Date: Fri, 7 Jul 2017 09:17:34 -0700 >> From: frederik at ofb.net >> To: Ilia Kats <ilia-kats at gmx.net> >> Cc: r-devel at r-project.org, r-help at r-project.org >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: <20170707161734.GA833 at ofb.net> >> Content-Type: text/plain; charset=us-ascii >> >> Hi Ilia, >> >> I'm running Arch Linux, R 3.4.0. >> >> Here's my test.pdf from your minimal example: https://ptpb.pw/HxsA.pdf >> >> It doesn't look pixelated to me... >> >> Here's a post that I wrote when I solved my last font problem in R, >> almost 2 years ago: >> >> https://stackoverflow.com/a/40940331/5087283 >> >> I had to install some Microsoft font packages, which is sad, because >> there are some perfectly good free fonts that R could be using >> instead. It could be considered a bug that R requires Microsoft fonts, >> at least by default. However, does this even fix your problem? I.e. if >> you install the corresponding Debian Microsoft font packages, does the >> text appear anti-aliased? >> >> Frederick >> >>> On Fri, Jul 07, 2017 at 10:30:46AM +0200, Ilia Kats wrote: >>> [cross-post from R-help] >>> >>> Hi all, >>> >>> I have the following problem: Since R 3.4.0, italic fonts rendered on Cairo >>> devices appear pixelated. Here's a minimal example: >>> cairo_pdf('test.pdf') >>> plot(1:10, ylab=expression(italic(test))) >>> dev.off() >>> >>> The same problem occurs with bolditalic, but not bold. I am using Debian >>> Stretch. Several friends tried the same on their machines, another Debian >>> machine has the same problem. On MacOSX the output was not pixelated, but it >>> wasn't italic either. Ubuntu 16.04.2 xenial works fine. My impression is >>> that R somehow can't find the proper font to use and falls back to something >>> weird. Ideas? >>> >>> Note that I'm not subscribed to the list, so please CC me in replies. >>> >>> Cheers, Ilia >>> >>> ______________________________________________ >>> R-devel at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-devel >>> >> >> >> >> ------------------------------ >> >> Message: 7 >> Date: Fri, 7 Jul 2017 10:28:44 -0700 >> From: frederik at ofb.net >> To: Ilia Kats <ilia-kats at gmx.net> >> Cc: r-devel at r-project.org, r-help at r-project.org >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: <20170707172844.GE833 at ofb.net> >> Content-Type: text/plain; charset=us-ascii >> >>> On Fri, Jul 07, 2017 at 07:08:52PM +0200, Ilia Kats wrote: >>> Interesting. I did not have the package installed, but I did at some point >>> extract Helvetica from some MacOSX font files and R was using that just fine >>> until 3.3. This is how the plot looks in 3.4 (still using Helvetica): >>> https://ptpb.pw/HikX.pdf . After removing Helvetica, installing the >>> ttf-mscorefonts-installer package, and running fc-cache --force the plot >>> looks like this: https://ptpb.pw/CM8A.pdf >> >> The second plot looks worse, in other words, and the Microsoft fonts >> didn't help. >> >> Maybe the Cairo device should be giving better warning messages. >> >> Anyway it sounds like you are describing a regression so maybe someone >> can track down the commit that created this problem. >> >> Thanks, >> >> Frederick >> >> >>> Also note that the standard pdf device works fine: https://ptpb.pw/3Ml1.pdf >>> , it's just the cairo devices (both pdf and svg) that have the issue. >>> Unfortunately I need to use cairo_pdf due to unicode characters in axis >>> labels. >>> >>> Cheers, Ilia >>> >>> >>> -------- Original Message -------- >>> Subject: Re: [Rd] italic font on cairo devices in R 3.4 >>> Date: 2017-07-07 18:17:34 +0200 >>> From: frederik >>> To: Ilia Kats >>> CC: r-devel, r-help >>>> Hi Ilia, >>>> >>>> I'm running Arch Linux, R 3.4.0. >>>> >>>> Here's my test.pdf from your minimal example: https://ptpb.pw/HxsA.pdf >>>> >>>> It doesn't look pixelated to me... >>>> >>>> Here's a post that I wrote when I solved my last font problem in R, >>>> almost 2 years ago: >>>> >>>> https://stackoverflow.com/a/40940331/5087283 >>>> >>>> I had to install some Microsoft font packages, which is sad, because >>>> there are some perfectly good free fonts that R could be using >>>> instead. It could be considered a bug that R requires Microsoft fonts, >>>> at least by default. However, does this even fix your problem? I.e. if >>>> you install the corresponding Debian Microsoft font packages, does the >>>> text appear anti-aliased? >>>> >>>> Frederick >>>> >>>>> On Fri, Jul 07, 2017 at 10:30:46AM +0200, Ilia Kats wrote: >>>>> [cross-post from R-help] >>>>> >>>>> Hi all, >>>>> >>>>> I have the following problem: Since R 3.4.0, italic fonts rendered on Cairo >>>>> devices appear pixelated. Here's a minimal example: >>>>> cairo_pdf('test.pdf') >>>>> plot(1:10, ylab=expression(italic(test))) >>>>> dev.off() >>>>> >>>>> The same problem occurs with bolditalic, but not bold. I am using Debian >>>>> Stretch. Several friends tried the same on their machines, another Debian >>>>> machine has the same problem. On MacOSX the output was not pixelated, but it >>>>> wasn't italic either. Ubuntu 16.04.2 xenial works fine. My impression is >>>>> that R somehow can't find the proper font to use and falls back to something >>>>> weird. Ideas? >>>>> >>>>> Note that I'm not subscribed to the list, so please CC me in replies. >>>>> >>>>> Cheers, Ilia >>>>> >>>>> ______________________________________________ >>>>> R-devel at r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-devel >>>>> >>> >>> -- >>> The first is to ensure your partner understands that nature has root >>> privileges - nature doesn't have to make sense. >>> -- Telsa Gwynne >>> >> >> >> >> ------------------------------ >> >> Message: 8 >> Date: Fri, 7 Jul 2017 16:52:34 +0000 >> From: Martina Hule?ov? <mhulesova at gmail.com> >> To: "r-help at r-project.org" <r-help at r-project.org> >> Subject: [R] Beginner s quwry about cfa in lavaan >> Message-ID: >> <HE1PR09MB044320C242C964B3ADB51037BDAA0 at HE1PR09MB0443.eurprd09.prod.outlook.com> >> >> Content-Type: text/plain; charset="UTF-8" >> >> Dear all, >> I am trying to learn about R. As a Phd student, I would like to use R for Krippendorff s alpha and later for a series of CFA. Is there any good introduction to these kind of analyses, or could you recommend me some tutorials on youtube, for example? I am new to R, so I need something basic , starting from opening the R environment?. >> Thank you . >> Martina Hulesova >> >> Odesl?no z m?ho Windows Phone >> >> [[alternative HTML version deleted]] >> >> >> ------------------------------ >> >> Message: 9 >> Date: Fri, 7 Jul 2017 19:08:52 +0200 >> From: Ilia Kats <ilia-kats at gmx.net> >> To: frederik at ofb.net >> Cc: r-devel at r-project.org, r-help at r-project.org >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: <815d1e56-2fb9-1f7c-aa32-b15769cc72c8 at gmx.net> >> Content-Type: text/plain; charset=utf-8; format=flowed >> >> Interesting. I did not have the package installed, but I did at some >> point extract Helvetica from some MacOSX font files and R was using that >> just fine until 3.3. This is how the plot looks in 3.4 (still using >> Helvetica): https://ptpb.pw/HikX.pdf . After removing Helvetica, >> installing the ttf-mscorefonts-installer package, and running fc-cache >> --force the plot looks like this: https://ptpb.pw/CM8A.pdf >> >> Also note that the standard pdf device works fine: >> https://ptpb.pw/3Ml1.pdf , it's just the cairo devices (both pdf and >> svg) that have the issue. Unfortunately I need to use cairo_pdf due to >> unicode characters in axis labels. >> >> Cheers, Ilia >> >> >> -------- Original Message -------- >> Subject: Re: [Rd] italic font on cairo devices in R 3.4 >> Date: 2017-07-07 18:17:34 +0200 >> From: frederik >> To: Ilia Kats >> CC: r-devel, r-help >>> Hi Ilia, >>> >>> I'm running Arch Linux, R 3.4.0. >>> >>> Here's my test.pdf from your minimal example: https://ptpb.pw/HxsA.pdf >>> >>> It doesn't look pixelated to me... >>> >>> Here's a post that I wrote when I solved my last font problem in R, >>> almost 2 years ago: >>> >>> https://stackoverflow.com/a/40940331/5087283 >>> >>> I had to install some Microsoft font packages, which is sad, because >>> there are some perfectly good free fonts that R could be using >>> instead. It could be considered a bug that R requires Microsoft fonts, >>> at least by default. However, does this even fix your problem? I.e. if >>> you install the corresponding Debian Microsoft font packages, does the >>> text appear anti-aliased? >>> >>> Frederick >>> >>>> On Fri, Jul 07, 2017 at 10:30:46AM +0200, Ilia Kats wrote: >>>> [cross-post from R-help] >>>> >>>> Hi all, >>>> >>>> I have the following problem: Since R 3.4.0, italic fonts rendered on Cairo >>>> devices appear pixelated. Here's a minimal example: >>>> cairo_pdf('test.pdf') >>>> plot(1:10, ylab=expression(italic(test))) >>>> dev.off() >>>> >>>> The same problem occurs with bolditalic, but not bold. I am using Debian >>>> Stretch. Several friends tried the same on their machines, another Debian >>>> machine has the same problem. On MacOSX the output was not pixelated, but it >>>> wasn't italic either. Ubuntu 16.04.2 xenial works fine. My impression is >>>> that R somehow can't find the proper font to use and falls back to something >>>> weird. Ideas? >>>> >>>> Note that I'm not subscribed to the list, so please CC me in replies. >>>> >>>> Cheers, Ilia >>>> >>>> ______________________________________________ >>>> R-devel at r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-devel >>>> >> >> -- >> The first is to ensure your partner understands that nature has root >> privileges - nature doesn't have to make sense. >> -- Telsa Gwynne >> >> >> >> ------------------------------ >> >> Message: 10 >> Date: Fri, 7 Jul 2017 16:43:12 -0700 >> From: Bert Gunter <bgunter.4567 at gmail.com> >> To: Martina Hule?ov? <mhulesova at gmail.com> >> Cc: r-help at r-project.org >> Subject: Re: [R] Beginner s quwry about cfa in lavaan >> Message-ID: >> <CAGxFJbQ3CgCFXLBGsz9e8y=VLw=9gQKTw7CsoDjy6Feu4=HBLA at mail.gmail.com> >> Content-Type: text/plain; charset="UTF-8" >> >> Google is your friend. >> >> Also rseek.org >> >> Bert >> >> >> >>> On Jul 7, 2017 3:48 PM, "Martina Hule?ov?" <mhulesova at gmail.com> wrote: >>> >>> Dear all, >>> I am trying to learn about R. As a Phd student, I would like to use R for >>> Krippendorff s alpha and later for a series of CFA. Is there any good >>> introduction to these kind of analyses, or could you recommend me some >>> tutorials on youtube, for example? I am new to R, so I need something basic >>> , starting from opening the R environment?. >>> Thank you . >>> Martina Hulesova >>> >>> Odesl?no z m?ho Windows Phone >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at 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]] >> >> >> >> ------------------------------ >> >> Message: 11 >> Date: Fri, 7 Jul 2017 21:25:42 -0500 >> From: Marc Schwartz <marc_schwartz at me.com> >> To: John Kane <jrkrideau at yahoo.ca> >> Cc: R R-help <r-help at stat.math.ethz.ch> >> Subject: Re: [R] Factor vs character in a data.frame vs vector >> Message-ID: <28B1CAA7-85EA-41A2-9373-172F52773C81 at me.com> >> Content-Type: text/plain; charset="us-ascii" >> >> >>> On Jul 7, 2017, at 7:03 PM, John Kane <jrkrideau at yahoo.ca> wrote: >>> >>> Thanks Marc. >>> It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame. I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. >> >> >> Welcome John. >> >> Going back to the old NEWS files, the 'stringsAsFactors' argument for data.frame() appears in version 2.4.0, which was released on 2006-10-03. >> >> It is possible that somewhere along the way, you set options(stringsAsFactors = FALSE) in your .Rprofile, which would change the default behavior. I know that some folks do that, as they do not like the default coercion to factors, both for data.frame() and for the read.table() family. >> >> Other alternatives would be to use the 'colClasses' argument to explicitly set such vectors to character, or to use I(...) to create AsIs class columns. >> >> Regards, >> >> Marc >> >> >>> >>> >>> >>> On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <marc_schwartz at me.com> wrote: >>> >>> >>> >>>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <r-help at r-project.org> wrote: >>>> >>>> This is not serious problem but I just wonder if someone can explain what is happening. >>>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character. It's probably something simple that I have read and forgotten but I thought I'd ask. >>>> Thanks >>>> >>>> #===============================================>>>> dat1 <- data.frame(aa = letters[1:10]) >>>> str(dat1) >>>> data.frame': 10 obs. of 1 variable: >>>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>>> bb = letters[1:10] >>>> str(bb) >>>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>>> #=============================================================>>>> >>> >>> >>> See the 'stringsAsFactors' argument in ?data.frame. >>> >>> dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE) >>> >>> >>>> str(dat1) >>> 'data.frame': 10 obs. of 1 variable: >>> >>> $ aa: chr "a" "b" "c" "d" ... >>> >>> >>> Regards, >>> >>> Marc Schwartz >>> >> >> >> >> ------------------------------ >> >> Message: 12 >> Date: Sat, 8 Jul 2017 00:03:19 +0000 >> From: John Kane <jrkrideau at yahoo.ca> >> To: Marc Schwartz <marc_schwartz at me.com> >> Cc: R R-help <r-help at stat.math.ethz.ch> >> Subject: Re: [R] Factor vs character in a data.frame vs vector >> Message-ID: <595896971.1101053.1499472199840 at mail.yahoo.com> >> Content-Type: text/plain; charset="UTF-8" >> >> Thanks Marc. It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame.? I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. >> >> >> On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <marc_schwartz at me.com> wrote: >> >> >>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <r-help at r-project.org> wrote: >>> >>> This is not? serious problem but I just wonder if someone can explain what is happening. >>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. >>> Thanks >>> >>> #===============================================>>> dat1 <- data.frame(aa = letters[1:10]) >>> str(dat1) >>> data.frame':? ? 10 obs. of? 1 variable: >>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>> bb = letters[1:10] >>> str(bb) >>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>> #=============================================================>>> >> >> >> See the 'stringsAsFactors' argument in ?data.frame. >> >> dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE) >> >>> str(dat1) >> 'data.frame':??? 10 obs. of? 1 variable: >> $ aa: chr? "a" "b" "c" "d" ... >> >> >> Regards, >> >> Marc Schwartz >> >> [[alternative HTML version deleted]] >> >> >> >> ------------------------------ >> >> Message: 13 >> Date: Sat, 8 Jul 2017 01:11:10 -0400 >> From: Yixuan Qiu <yixuan.qiu at cos.name> >> To: ilia-kats at gmx.net >> Cc: frederik at ofb.net, r-help <r-help at r-project.org> >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: >> <CAFr_7yFTMPers4D9P_vaPW5=R-qvRq0+_LDb56d3TewC7H4uLg at mail.gmail.com> >> Content-Type: text/plain; charset="UTF-8" >> >> Hi Ilia, >> >> You may want to have a try of the showtext package >> (https://github.com/yixuan/showtext). Below is a quick example: >> >> library(showtext) >> showtext.auto() >> >> pdf("test.pdf") >> ## Use the "sans" font family provided by the showtext package >> ## font == 3 means italic font face >> plot(1, xlab = "Unicode characters: \u00C0 \u00C6 \u00D8", >> family = "sans", font.lab = 3) >> dev.off() >> >> ## Same for SVG >> svg("test.svg") >> plot(1, xlab = "Unicode characters: \u00C0 \u00C6 \u00D8", >> family = "sans", font.lab = 3) >> dev.off() >> >> >> Best, >> Yixuan >> >> >> 2017-07-07 13:08 GMT-04:00 Ilia Kats <ilia-kats at gmx.net>: >>> Interesting. I did not have the package installed, but I did at some point >>> extract Helvetica from some MacOSX font files and R was using that just fine >>> until 3.3. This is how the plot looks in 3.4 (still using Helvetica): >>> https://ptpb.pw/HikX.pdf . After removing Helvetica, installing the >>> ttf-mscorefonts-installer package, and running fc-cache --force the plot >>> looks like this: https://ptpb.pw/CM8A.pdf >>> >>> Also note that the standard pdf device works fine: https://ptpb.pw/3Ml1.pdf >>> , it's just the cairo devices (both pdf and svg) that have the issue. >>> Unfortunately I need to use cairo_pdf due to unicode characters in axis >>> labels. >>> >>> Cheers, Ilia >>> >> >> >> >> >> -- >> Yixuan Qiu <yixuan.qiu at cos.name> >> Department of Statistics, >> Purdue University >> >> >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> ------------------------------ >> >> End of R-help Digest, Vol 173, Issue 8 >> **************************************[[alternative HTML version deleted]]
Tony, I?m not sure what exactly you?re trying to do, but you're not really taking advantage of vectorization in your R code. I've tried to clean it up a little. The clamped lognormal is almost always 0 or L? That seems a little odd. You seem to be using the inverse cdf method of drawing samples. That's not necessary in R for standard probability distributions. You may want to do a little more investigating of basic programming tasks in R before you dig into a complex simulation. scale <- 15.08707 shape <- 0.8592507 lambda.risk <- 1.75 L <- 7.5e5 R <- 2.5e6 # Generate n random poisson with rate = lambda.risk frequency <- function(n) rpois(n,lambda.risk) # clamp a numeric to 0, L clamp <- function(x, min, max) pmin(max, pmax(min, x)) # Generate lognormal shifted by R severity <- function(n) rlnorm(n,scale,shape)-R clamp(severity(100), 0, L) # Lognormal shifted left by R, and then clamped between 0 and L? Almost always equal to 0 or L sim <- function(breaks = 7){ freq <- frequency(1) i <- freq > 1:7 sev <- clamp(severity(sum(i)), 0, L) claims <- rep(0, 7) claims[i] <- sev min(22.5e6,sum(claims)) } hist(iterations <- replicate(10000, sim()), breaks = 20) From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of HUL-Anthony Egerton Sent: Friday, July 14, 2017 7:45 PM To: r-help at r-project.org Subject: Re: [R] One Dimensional Monte Carlo Simulation Further to my email below, I have just realised that I forgot to include the specification of L and R. Hence, the code needs to include the following additional lines at the start;- L<-7.5e6 R<-2.5e6 Apologies for any confusion caused! Best regards, Tony> On 12 Jul 2017, at 10:03 AM, HUL-Anthony Egerton <mailto:aegerton at huntingtonunderwriting.com> wrote: > > I am trying to code a basic Monte Carlo Simulation in R where a Poisson distribution generates a frequency output that is then input into a Lognormal distribution, which produces a different, independent severity for each incidence. The individual incidences are then summed to produce an aggregate amount per period/iteration. > > Here is the code;- > > scale<-15.08707 > shape<-0.8592507 > lambda.risk<-1.75 > L<-7.5e5 > R<-2.5e6 > iterations<-replicate(10000,{ >? claims1<-0 >? claims2<-0 >? claims3<-0 >? claims4<-0 >? claims5<-0 > claims6<-0 >? claims7<-0 >? claims<-c(claims1,claims2,claims3,claims4,claims5,claims6,claims7) >? freq<-(qpois(runif(1),lambda.risk)) >? sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >? if(freq>=1){claims1<-sev} >? sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >? if(freq>=2){claims2<-sev} >? sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >? if (freq>=3) {claims3<-sev} >? sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >? if (freq>=4) {claims4<-sev} >? sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >? if (freq>=5) {claims5<-sev} >? sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >? if (freq>=6) {claims6<-sev} >? sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >? if (freq>=7) {claims7<-sev} >? claims<-c(claims1,claims2,claims3,claims4,claims5,claims6,claims7) >? min(22.5e6,sum(claims)) > }) > > I am new to R, but am sure that there must be a simpler way to code this process. > > Furthermore, as the Poisson lambda increases, there is a need to include provision for potentially more incidences, which will require a manual expansion of the code to claims8, claims9 etc. > > Can you assist, please? > > Best regards, > > Anthony A H Egerton MA MBA ACII > ????? > HUNTINGTON UNDERWRITING LIMITED > Labuan FT, Malaysia > > > > CONFIDENTIALITY NOTE: >? > The information contained in this email message may be legally privileged and contain confidential information and is intended only for the use of the individual or entity to whom it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copy of this message is strictly prohibited. If you have received this email in error, please immediately delete this message. > > Begin forwarded message: > >> From: mailto:r-help-request at r-project.org >> Date: 8 July 2017 at 6:00:02 PM SGT >> To: mailto:r-help at r-project.org >> Subject: R-help Digest, Vol 173, Issue 8 >> Reply-To: mailto:r-help at r-project.org >> >> Send R-help mailing list submissions to >>??? mailto:r-help at r-project.org >> >> To subscribe or unsubscribe via the World Wide Web, visit >>??? https://stat.ethz.ch/mailman/listinfo/r-help >> or, via email, send a message with subject or body 'help' to >>??? mailto:r-help-request at r-project.org >> >> You can reach the person managing the list at >>??? mailto:r-help-owner at r-project.org >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of R-help digest..." >> >> >> Today's Topics: >> >>?? 1. R loop function in Tableau (Dai, Shengyu) >>?? 2. Factor vs character in a data.frame vs vector (John Kane) >>?? 3. Re: Factor vs character in a data.frame vs vector (Marc Schwartz) >>?? 4. Re: Scoring and Ranking Methods (David Winsemius) >>?? 5. Re: R loop function in Tableau (David Winsemius) >>?? 6. Re: [Rd] italic font on cairo devices in R 3.4 (mailto:frederik at ofb.net) >>?? 7. Re: [Rd] italic font on cairo devices in R 3.4 (mailto:frederik at ofb.net) >>?? 8. Beginner s quwry about cfa in lavaan (Martina Hule?ov?) >>?? 9. Re: [Rd] italic font on cairo devices in R 3.4 (Ilia Kats) >>? 10. Re: Beginner s quwry about cfa in lavaan (Bert Gunter) >>? 11. Re: Factor vs character in a data.frame vs vector (Marc Schwartz) >>? 12. Re: Factor vs character in a data.frame vs vector (John Kane) >>? 13. Re: [Rd] italic font on cairo devices in R 3.4 (Yixuan Qiu) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Thu, 06 Jul 2017 17:19:47 -0400 >> From: "Dai, Shengyu" <mailto:dais2 at rpi.edu> >> To: <mailto:r-help at r-project.org> >> Subject: [R] R loop function in Tableau >> Message-ID: <mailto:15947CD3-CD7B-4BB6-A994-D49D514DF0DE at rpi.edu> >> Content-Type: text/plain;??? charset="UTF-8" >> >> Hi R helpers, >> >> >> >> I hope this email finds you well. >> >> >> >> I am having trouble with R loop function in Tableau. Please see the attachment of a simple dataset. The problem is to test whether the value of columns is match. >> >> >> >> Because Tableau do not have iteration function, I coded ?if statement? in Tableau to realize the function, which is slow if having huge amount of data. I wonder to integrate Tableau with R studio to realize this functionality. >> >> >> >> I did not find too much useful information online and I am asking helps for any examples of related low-level data calculation. >> >> >> >> Thank you very much. Your helps and supports are really appreciated! >> >> >> >> Best, >> >> >> >> -- >> >> >> >> Shengyu (Freddy) Dai >> >> Master of Science in Business Analytics >> >> Lally School of Management >> >> Rensselaer Polytechnic Institute >> >> Mobile: (513)328-5659 >> >> >> >> >> >> ------------------------------ >> >> Message: 2 >> Date: Fri, 7 Jul 2017 11:03:51 +0000 >> From: John Kane <mailto:jrkrideau at yahoo.ca> >> To: R R-help <mailto:r-help at stat.math.ethz.ch> >> Subject: [R] Factor vs character in a data.frame vs vector >> Message-ID: <mailto:184884580.507511.1499425431478 at mail.yahoo.com> >> Content-Type: text/plain; charset="UTF-8" >> >> This is not? serious problem but I just wonder if someone can explain what is happening. >> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. >> Thanks >> >> #===============================================>> dat1 <- data.frame(aa = letters[1:10]) >> str(dat1) >> data.frame':????10 obs. of??1 variable: >> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>> bb = letters[1:10] >> str(bb) >> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >> #=============================================================>> >> >>??? [[alternative HTML version deleted]] >> >> >> >> ------------------------------ >> >> Message: 3 >> Date: Fri, 7 Jul 2017 09:37:12 -0500 >> From: Marc Schwartz <mailto:marc_schwartz at me.com> >> To: John Kane <mailto:jrkrideau at yahoo.ca> >> Cc: R R-help <mailto:r-help at stat.math.ethz.ch> >> Subject: Re: [R] Factor vs character in a data.frame vs vector >> Message-ID: <mailto:36A7CFEC-57B6-4652-BC93-AB9E0EED14AF at me.com> >> Content-Type: text/plain; charset="us-ascii" >> >> >>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <mailto:r-help at r-project.org> wrote: >>> >>> This is not? serious problem but I just wonder if someone can explain what is happening. >>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. >>> Thanks >>> >>> #===============================================>>> dat1 <- data.frame(aa = letters[1:10]) >>> str(dat1) >>> data.frame':??? 10 obs. of? 1 variable: >>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>> bb = letters[1:10] >>> str(bb) >>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>> #=============================================================>>> >> >> >> See the 'stringsAsFactors' argument in ?data.frame. >> >> dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE) >> >>> str(dat1) >> 'data.frame':??? 10 obs. of? 1 variable: >> $ aa: chr? "a" "b" "c" "d" ... >> >> >> Regards, >> >> Marc Schwartz >> >> >> >> ------------------------------ >> >> Message: 4 >> Date: Fri, 7 Jul 2017 08:47:57 -0700 >> From: David Winsemius <mailto:dwinsemius at comcast.net> >> To: Dhivya Narayanasamy <mailto:dhiv.shreya at gmail.com> >> Cc: r-help mailing list <mailto:r-help at r-project.org> >> Subject: Re: [R] Scoring and Ranking Methods >> Message-ID: <mailto:B6A35831-5E7D-407A-BB82-504F33E0F488 at comcast.net> >> Content-Type: text/plain; charset=us-ascii >> >> >>> On Jul 7, 2017, at 2:29 AM, Dhivya Narayanasamy <mailto:dhiv.shreya at gmail.com> wrote: >>> >>> Hi, >>> >>> I am doing predictive modelling of Multivariate Time series Data of a Motor >>> in R using various models such as Arima, H2O.Randomforest, glmnet, lm and >>> few other models. >>> >>> I created a function to select a model of our choice and do prediction. >>> >>> Model1 <- function(){ >>> .. >>> return() >>> } >> >> That looks like a prescription for serious disappointment. I seriously doubt that you have done any testing using similar code. You would have created a function that returns NULL. I get the sense that you need to study and work through the examples in the "Introduction to R" document. >> >> >> >>> Model2 <- function(){ >>> ... >>> return() >>> } >>> Model3 <- function(){ >>> ... >>> return() >>> } >>> main <- function(n){ >>> if(n == 1) { >>>? Model1() >>> } >>> else if(n == 2){ >>>?? Model2() >>> } >>> else if(n == 3){ >>>?? Model3() >>> }} >>> Now I am supposed to automate these models which gives RMSE and MAPE of >>> each model. I would like to provide scores (eg. out of 5) for each model >>> based on the performance. For example, if Arima gives a low RMSE than other >>> models, it will be scored high and the second lowest RMSE model will score >>> a less than Arima and so on. >>> >>> And every time i run those models with different input Data [motor2, motor3 >>> ..], it must give the mean score of a model. what I mean to say is, >>> >>> 1. for motor1 it will give scores of each model, let's say *s1*. >>> 2. for motor2 run it give scores of each model, and let's call it *s2*. >>> And i want a mean score of that model every time i run it with different >>> input. It is more like scoring and ranking method. >>> >>> Are there any methods or packages in R that can give a glimpse of how it is >>> done? or any examples? Any suggestions would be very helpful. >> >> The 'switch'-function can dispatch to different functions on the basis of the value of an indicator variable. >> >> >>> >>> Thank you. >>> Dhivya >>> >>>??? [[alternative HTML version deleted]] >> >> Please read the Posting Guide. Rhelp is a plain text mailing list. >>> >>> ______________________________________________ >>> mailto:R-help at 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. >> >> David Winsemius >> Alameda, CA, USA >> >> >> >> ------------------------------ >> >> Message: 5 >> Date: Fri, 7 Jul 2017 08:57:50 -0700 >> From: David Winsemius <mailto:dwinsemius at comcast.net> >> To: "Dai, Shengyu" <mailto:dais2 at rpi.edu> >> Cc: mailto:r-help at r-project.org >> Subject: Re: [R] R loop function in Tableau >> Message-ID: <mailto:5B17A446-46C5-4371-94D3-A5C9A7CA6E7B at comcast.net> >> Content-Type: text/plain; charset=utf-8 >> >> >>> On Jul 6, 2017, at 2:19 PM, Dai, Shengyu <mailto:dais2 at rpi.edu> wrote: >>> >>> Hi R helpers, >>> >>> >>> >>> I hope this email finds you well. >>> >>> >>> >>> I am having trouble with R loop function in Tableau. >>> >> >> There is no "R loop function". (There is an R `for`-function.) If you are having trouble with code then it should be provided. If the problem is with the Tableau code then this is the wrong place. Tableau is not either free or open source. You would in that case need to contact Tableau or get assistance from your academic institution. >> >>> Please see the attachment of a simple dataset. >> >> No data attached. Probably scrubbed by the mail server. Any data needs to be a .txt file. >> >>> The problem is to test whether the value of columns is match. >> >> There is a `match` function. It's vectorized, so may not need to be wrapped with a function that would provide looping. >> >>> >>> Because Tableau do not have iteration function, I coded ?if statement? in Tableau to realize the function, which is slow if having huge amount of data. I wonder to integrate Tableau with R studio to realize this functionality. >>> >>> >>> >>> I did not find too much useful information online and I am asking helps for any examples of related low-level data calculation. >> >> That is then the fault of Tableau (if true), since there is a huge amount of online documentation for R. The Rhelp Archives and StackOverflow have thousands of worked examples of "low-level data calculation". I suspect with estimated probability approaching unity that StackOverflow will have questions tagged jointly with [r] and [tableau]. >> >> >>> >>> Thank you very much. Your helps and supports are really appreciated! >>> >>> >>> >>> Best, >>> >>> >>> >>> -- >>> >>> >>> >>> Shengyu (Freddy) Dai >>> >>> Master of Science in Business Analytics >>> >>> Lally School of Management >>> >>> Rensselaer Polytechnic Institute >>> >>> Mobile: (513)328-5659 >>> >>> >>> >>> ______________________________________________ >>> mailto:R-help at 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. >> >> David Winsemius >> Alameda, CA, USA >> >> >> >> ------------------------------ >> >> Message: 6 >> Date: Fri, 7 Jul 2017 09:17:34 -0700 >> From: mailto:frederik at ofb.net >> To: Ilia Kats <mailto:ilia-kats at gmx.net> >> Cc: mailto:r-devel at r-project.org, mailto:r-help at r-project.org >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: <mailto:20170707161734.GA833 at ofb.net> >> Content-Type: text/plain; charset=us-ascii >> >> Hi Ilia, >> >> I'm running Arch Linux, R 3.4.0. >> >> Here's my test.pdf from your minimal example: https://ptpb.pw/HxsA.pdf >> >> It doesn't look pixelated to me... >> >> Here's a post that I wrote when I solved my last font problem in R, >> almost 2 years ago: >> >> https://stackoverflow.com/a/40940331/5087283 >> >> I had to install some Microsoft font packages, which is sad, because >> there are some perfectly good free fonts that R could be using >> instead. It could be considered a bug that R requires Microsoft fonts, >> at least by default. However, does this even fix your problem? I.e. if >> you install the corresponding Debian Microsoft font packages, does the >> text appear anti-aliased? >> >> Frederick >> >>> On Fri, Jul 07, 2017 at 10:30:46AM +0200, Ilia Kats wrote: >>> [cross-post from R-help] >>> >>> Hi all, >>> >>> I have the following problem: Since R 3.4.0, italic fonts rendered on Cairo >>> devices appear pixelated. Here's a minimal example: >>> cairo_pdf('test.pdf') >>> plot(1:10, ylab=expression(italic(test))) >>> dev.off() >>> >>> The same problem occurs with bolditalic, but not bold. I am using Debian >>> Stretch. Several friends tried the same on their machines, another Debian >>> machine has the same problem. On MacOSX the output was not pixelated, but it >>> wasn't italic either. Ubuntu 16.04.2 xenial works fine. My impression is >>> that R somehow can't find the proper font to use and falls back to something >>> weird. Ideas? >>> >>> Note that I'm not subscribed to the list, so please CC me in replies. >>> >>> Cheers, Ilia >>> >>> ______________________________________________ >>> mailto:R-devel at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-devel >>> >> >> >> >> ------------------------------ >> >> Message: 7 >> Date: Fri, 7 Jul 2017 10:28:44 -0700 >> From: mailto:frederik at ofb.net >> To: Ilia Kats <mailto:ilia-kats at gmx.net> >> Cc: mailto:r-devel at r-project.org, mailto:r-help at r-project.org >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: <mailto:20170707172844.GE833 at ofb.net> >> Content-Type: text/plain; charset=us-ascii >> >>> On Fri, Jul 07, 2017 at 07:08:52PM +0200, Ilia Kats wrote: >>> Interesting. I did not have the package installed, but I did at some point >>> extract Helvetica from some MacOSX font files and R was using that just fine >>> until 3.3. This is how the plot looks in 3.4 (still using Helvetica): >>> https://ptpb.pw/HikX.pdf . After removing Helvetica, installing the >>> ttf-mscorefonts-installer package, and running fc-cache --force? the plot >>> looks like this: https://ptpb.pw/CM8A.pdf >> >> The second plot looks worse, in other words, and the Microsoft fonts >> didn't help. >> >> Maybe the Cairo device should be giving better warning messages. >> >> Anyway it sounds like you are describing a regression so maybe someone >> can track down the commit that created this problem. >> >> Thanks, >> >> Frederick >> >> >>> Also note that the standard pdf device works fine: https://ptpb.pw/3Ml1.pdf >>> , it's just the cairo devices (both pdf and svg) that have the issue. >>> Unfortunately I need to use cairo_pdf due to unicode characters in axis >>> labels. >>> >>> Cheers, Ilia >>> >>> >>> -------- Original Message -------- >>> Subject: Re: [Rd] italic font on cairo devices in R 3.4 >>> Date: 2017-07-07 18:17:34 +0200 >>> From: frederik >>> To: Ilia Kats >>> CC: r-devel, r-help >>>> Hi Ilia, >>>> >>>> I'm running Arch Linux, R 3.4.0. >>>> >>>> Here's my test.pdf from your minimal example: https://ptpb.pw/HxsA.pdf >>>> >>>> It doesn't look pixelated to me... >>>> >>>> Here's a post that I wrote when I solved my last font problem in R, >>>> almost 2 years ago: >>>> >>>> https://stackoverflow.com/a/40940331/5087283 >>>> >>>> I had to install some Microsoft font packages, which is sad, because >>>> there are some perfectly good free fonts that R could be using >>>> instead. It could be considered a bug that R requires Microsoft fonts, >>>> at least by default. However, does this even fix your problem? I.e. if >>>> you install the corresponding Debian Microsoft font packages, does the >>>> text appear anti-aliased? >>>> >>>> Frederick >>>> >>>>> On Fri, Jul 07, 2017 at 10:30:46AM +0200, Ilia Kats wrote: >>>>> [cross-post from R-help] >>>>> >>>>> Hi all, >>>>> >>>>> I have the following problem: Since R 3.4.0, italic fonts rendered on Cairo >>>>> devices appear pixelated. Here's a minimal example: >>>>> cairo_pdf('test.pdf') >>>>> plot(1:10, ylab=expression(italic(test))) >>>>> dev.off() >>>>> >>>>> The same problem occurs with bolditalic, but not bold. I am using Debian >>>>> Stretch. Several friends tried the same on their machines, another Debian >>>>> machine has the same problem. On MacOSX the output was not pixelated, but it >>>>> wasn't italic either. Ubuntu 16.04.2 xenial works fine. My impression is >>>>> that R somehow can't find the proper font to use and falls back to something >>>>> weird. Ideas? >>>>> >>>>> Note that I'm not subscribed to the list, so please CC me in replies. >>>>> >>>>> Cheers, Ilia >>>>> >>>>> ______________________________________________ >>>>> mailto:R-devel at r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-devel >>>>> >>> >>> -- >>> The first is to ensure your partner understands that nature has root >>> privileges - nature doesn't have to make sense. >>> -- Telsa Gwynne >>> >> >> >> >> ------------------------------ >> >> Message: 8 >> Date: Fri, 7 Jul 2017 16:52:34 +0000 >> From: Martina Hule?ov? <mailto:mhulesova at gmail.com> >> To: "mailto:r-help at r-project.org" <mailto:r-help at r-project.org> >> Subject: [R] Beginner s quwry about cfa in lavaan >> Message-ID: >>??? <mailto:HE1PR09MB044320C242C964B3ADB51037BDAA0 at HE1PR09MB0443.eurprd09.prod.outlook.com> >>??? >> Content-Type: text/plain; charset="UTF-8" >> >> Dear all, >> I am trying to learn about R. As a Phd student, I would like to use R for Krippendorff s alpha and later for a series of CFA. Is there any good introduction to these kind of analyses, or could you recommend me some tutorials on youtube, for example? I am new to R, so I need something basic , starting from opening the R environment?. >> Thank you . >> Martina Hulesova >> >> Odesl?no z m?ho Windows Phone >> >>??? [[alternative HTML version deleted]] >> >> >> ------------------------------ >> >> Message: 9 >> Date: Fri, 7 Jul 2017 19:08:52 +0200 >> From: Ilia Kats <mailto:ilia-kats at gmx.net> >> To: mailto:frederik at ofb.net >> Cc: mailto:r-devel at r-project.org, mailto:r-help at r-project.org >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: <mailto:815d1e56-2fb9-1f7c-aa32-b15769cc72c8 at gmx.net> >> Content-Type: text/plain; charset=utf-8; format=flowed >> >> Interesting. I did not have the package installed, but I did at some >> point extract Helvetica from some MacOSX font files and R was using that >> just fine until 3.3. This is how the plot looks in 3.4 (still using >> Helvetica): https://ptpb.pw/HikX.pdf . After removing Helvetica, >> installing the ttf-mscorefonts-installer package, and running fc-cache >> --force? the plot looks like this: https://ptpb.pw/CM8A.pdf >> >> Also note that the standard pdf device works fine: >> https://ptpb.pw/3Ml1.pdf , it's just the cairo devices (both pdf and >> svg) that have the issue. Unfortunately I need to use cairo_pdf due to >> unicode characters in axis labels. >> >> Cheers, Ilia >> >> >> -------- Original Message -------- >> Subject: Re: [Rd] italic font on cairo devices in R 3.4 >> Date: 2017-07-07 18:17:34 +0200 >> From: frederik >> To: Ilia Kats >> CC: r-devel, r-help >>> Hi Ilia, >>> >>> I'm running Arch Linux, R 3.4.0. >>> >>> Here's my test.pdf from your minimal example: https://ptpb.pw/HxsA.pdf >>> >>> It doesn't look pixelated to me... >>> >>> Here's a post that I wrote when I solved my last font problem in R, >>> almost 2 years ago: >>> >>> https://stackoverflow.com/a/40940331/5087283 >>> >>> I had to install some Microsoft font packages, which is sad, because >>> there are some perfectly good free fonts that R could be using >>> instead. It could be considered a bug that R requires Microsoft fonts, >>> at least by default. However, does this even fix your problem? I.e. if >>> you install the corresponding Debian Microsoft font packages, does the >>> text appear anti-aliased? >>> >>> Frederick >>> >>>> On Fri, Jul 07, 2017 at 10:30:46AM +0200, Ilia Kats wrote: >>>> [cross-post from R-help] >>>> >>>> Hi all, >>>> >>>> I have the following problem: Since R 3.4.0, italic fonts rendered on Cairo >>>> devices appear pixelated. Here's a minimal example: >>>> cairo_pdf('test.pdf') >>>> plot(1:10, ylab=expression(italic(test))) >>>> dev.off() >>>> >>>> The same problem occurs with bolditalic, but not bold. I am using Debian >>>> Stretch. Several friends tried the same on their machines, another Debian >>>> machine has the same problem. On MacOSX the output was not pixelated, but it >>>> wasn't italic either. Ubuntu 16.04.2 xenial works fine. My impression is >>>> that R somehow can't find the proper font to use and falls back to something >>>> weird. Ideas? >>>> >>>> Note that I'm not subscribed to the list, so please CC me in replies. >>>> >>>> Cheers, Ilia >>>> >>>> ______________________________________________ >>>> mailto:R-devel at r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-devel >>>> >> >> -- >> The first is to ensure your partner understands that nature has root >> privileges - nature doesn't have to make sense. >> -- Telsa Gwynne >> >> >> >> ------------------------------ >> >> Message: 10 >> Date: Fri, 7 Jul 2017 16:43:12 -0700 >> From: Bert Gunter <mailto:bgunter.4567 at gmail.com> >> To: Martina Hule?ov? <mailto:mhulesova at gmail.com> >> Cc: mailto:r-help at r-project.org >> Subject: Re: [R] Beginner s quwry about cfa in lavaan >> Message-ID: >>??? <mailto:CAGxFJbQ3CgCFXLBGsz9e8y=VLw=9gQKTw7CsoDjy6Feu4=HBLA at mail.gmail.com> >> Content-Type: text/plain; charset="UTF-8" >> >> Google is your friend. >> >> Also rseek.org >> >> Bert >> >> >> >>> On Jul 7, 2017 3:48 PM, "Martina Hule?ov?" <mailto:mhulesova at gmail.com> wrote: >>> >>> Dear all, >>> I am trying to learn about R. As a Phd student, I would like to use R for >>> Krippendorff s alpha and later for a series of CFA. Is there any good >>> introduction to these kind of analyses, or could you recommend me some >>> tutorials on youtube, for example? I am new to R, so I need something basic >>> , starting from opening the R environment?. >>> Thank you . >>> Martina Hulesova >>> >>> Odesl?no z m?ho Windows Phone >>> >>>??????? [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> mailto:R-help at 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]] >> >> >> >> ------------------------------ >> >> Message: 11 >> Date: Fri, 7 Jul 2017 21:25:42 -0500 >> From: Marc Schwartz <mailto:marc_schwartz at me.com> >> To: John Kane <mailto:jrkrideau at yahoo.ca> >> Cc: R R-help <mailto:r-help at stat.math.ethz.ch> >> Subject: Re: [R] Factor vs character in a data.frame vs vector >> Message-ID: <mailto:28B1CAA7-85EA-41A2-9373-172F52773C81 at me.com> >> Content-Type: text/plain; charset="us-ascii" >> >> >>> On Jul 7, 2017, at 7:03 PM, John Kane <mailto:jrkrideau at yahoo.ca> wrote: >>> >>> Thanks Marc. >>> It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame.? I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. >> >> >> Welcome John. >> >> Going back to the old NEWS files, the 'stringsAsFactors' argument for data.frame() appears in version 2.4.0, which was released on 2006-10-03. >> >> It is possible that somewhere along the way, you set options(stringsAsFactors = FALSE) in your .Rprofile, which would change the default behavior. I know that some folks do that, as they do not like the default coercion to factors, both for data.frame() and for the read.table() family. >> >> Other alternatives would be to use the 'colClasses' argument to explicitly set such vectors to character, or to use I(...) to create AsIs class columns. >> >> Regards, >> >> Marc >> >> >>> >>> >>> >>> On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <mailto:marc_schwartz at me.com> wrote: >>> >>> >>> >>>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <mailto:r-help at r-project.org> wrote: >>>> >>>> This is not? serious problem but I just wonder if someone can explain what is happening. >>>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. >>>> Thanks >>>> >>>> #===============================================>>>> dat1 <- data.frame(aa = letters[1:10]) >>>> str(dat1) >>>> data.frame':??? 10 obs. of? 1 variable: >>>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>>> bb = letters[1:10] >>>> str(bb) >>>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>>> #=============================================================>>>> >>> >>> >>> See the 'stringsAsFactors' argument in ?data.frame. >>> >>> dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE) >>> >>> >>>> str(dat1) >>> 'data.frame':??? 10 obs. of? 1 variable: >>> >>> $ aa: chr? "a" "b" "c" "d" ... >>> >>> >>> Regards, >>> >>> Marc Schwartz >>> >> >> >> >> ------------------------------ >> >> Message: 12 >> Date: Sat, 8 Jul 2017 00:03:19 +0000 >> From: John Kane <mailto:jrkrideau at yahoo.ca> >> To: Marc Schwartz <mailto:marc_schwartz at me.com> >> Cc: R R-help <mailto:r-help at stat.math.ethz.ch> >> Subject: Re: [R] Factor vs character in a data.frame vs vector >> Message-ID: <mailto:595896971.1101053.1499472199840 at mail.yahoo.com> >> Content-Type: text/plain; charset="UTF-8" >> >> Thanks Marc. It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame.? I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. >> >> >> On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <mailto:marc_schwartz at me.com> wrote: >> >> >>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <mailto:r-help at r-project.org> wrote: >>> >>> This is not? serious problem but I just wonder if someone can explain what is happening. >>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. >>> Thanks >>> >>> #===============================================>>> dat1 <- data.frame(aa = letters[1:10]) >>> str(dat1) >>> data.frame':? ? 10 obs. of? 1 variable: >>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>> bb = letters[1:10] >>> str(bb) >>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>> #=============================================================>>> >> >> >> See the 'stringsAsFactors' argument in ?data.frame. >> >> dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE) >> >>> str(dat1) >> 'data.frame':??? 10 obs. of? 1 variable: >> $ aa: chr? "a" "b" "c" "d" ... >> >> >> Regards, >> >> Marc Schwartz >> >>??? [[alternative HTML version deleted]] >> >> >> >> ------------------------------ >> >> Message: 13 >> Date: Sat, 8 Jul 2017 01:11:10 -0400 >> From: Yixuan Qiu <mailto:yixuan.qiu at cos.name> >> To: mailto:ilia-kats at gmx.net >> Cc: mailto:frederik at ofb.net, r-help <mailto:r-help at r-project.org> >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: >>??? <mailto:CAFr_7yFTMPers4D9P_vaPW5=R-qvRq0+_LDb56d3TewC7H4uLg at mail.gmail.com> >> Content-Type: text/plain; charset="UTF-8" >> >> Hi Ilia, >> >> You may want to have a try of the showtext package >> (https://github.com/yixuan/showtext). Below is a quick example: >> >> library(showtext) >> showtext.auto() >> >> pdf("test.pdf") >> ## Use the "sans" font family provided by the showtext package >> ## font == 3 means italic font face >> plot(1, xlab = "Unicode characters: \u00C0 \u00C6 \u00D8", >>??? family = "sans", font.lab = 3) >> dev.off() >> >> ## Same for SVG >> svg("test.svg") >> plot(1, xlab = "Unicode characters: \u00C0 \u00C6 \u00D8", >>??? family = "sans", font.lab = 3) >> dev.off() >> >> >> Best, >> Yixuan >> >> >> 2017-07-07 13:08 GMT-04:00 Ilia Kats <mailto:ilia-kats at gmx.net>: >>> Interesting. I did not have the package installed, but I did at some point >>> extract Helvetica from some MacOSX font files and R was using that just fine >>> until 3.3. This is how the plot looks in 3.4 (still using Helvetica): >>> https://ptpb.pw/HikX.pdf . After removing Helvetica, installing the >>> ttf-mscorefonts-installer package, and running fc-cache --force? the plot >>> looks like this: https://ptpb.pw/CM8A.pdf >>> >>> Also note that the standard pdf device works fine: https://ptpb.pw/3Ml1.pdf >>> , it's just the cairo devices (both pdf and svg) that have the issue. >>> Unfortunately I need to use cairo_pdf due to unicode characters in axis >>> labels. >>> >>> Cheers, Ilia >>> >> >> >> >> >> -- >> Yixuan Qiu <mailto:yixuan.qiu at cos.name> >> Department of Statistics, >> Purdue University >> >> >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> mailto:R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> ------------------------------ >> >> End of R-help Digest, Vol 173, Issue 8 >> **************************************??????? [[alternative HTML version deleted]] ______________________________________________ mailto:R-help at 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.
Jason, Many thanks for your email and the kind assistance provided. This is very beautiful code that it is a joy to work through, especially so for a beginner like me. I have a couple of quick comments/questions as follows;- - I made a mistake in specifying L, it should be 7.5e6, which makes far more sense - do you use 7 in the sim function as it is a more than adequate limit given the level of lambda.risk here, please? - shouldn't the i<-freq>1:7 line actually be i<-freq>=1:7? - excuse my ignorance, but how does the breaks=7 argument impact the sim function? I had made some progress with my own version, which now incorporates a second Poisson distribution for catastrophe losses, as follows;- L<-c(2.5e6,7.5e6,22.5e6) ln<-c(15.08707, 0.8592507) lambda<-c(2,0.4) iterations<-replicate(10000,{ freq<-(qpois(runif(2),lambda)) i<-1 temp<-0 while (i<=freq[1]){ sev<-pmin(L[2],pmax(0,(qlnorm(runif(1),ln[1],ln[2])-L[1]))) temp<-temp+sev i<-i+1} min(L[3],(temp+(freq[2]*L[2])))}) However, your approach is much simpler and more elegant. Thank you again for the insights. Best regards, Tony Anthony A H Egerton MA MBA ACII ??? HUNTINGTON UNDERWRITING LIMITED Labuan FT, Malaysia CONFIDENTIALITY NOTE: The information contained in this email message may be legally privileged and contain confidential information and is intended only for the use of the individual or entity to whom it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copy of this message is strictly prohibited. If you have received this email in error, please immediately delete this message.> On 2 Aug 2017, at 5:13 AM, Law, Jason <Jason.Law at portlandoregon.gov> wrote: > > Tony, > > I?m not sure what exactly you?re trying to do, but you're not really taking advantage of vectorization in your R code. I've tried to clean it up a little. The clamped lognormal is almost always 0 or L? That seems a little odd. You seem to be using the inverse cdf method of drawing samples. That's not necessary in R for standard probability distributions. You may want to do a little more investigating of basic programming tasks in R before you dig into a complex simulation. > > scale <- 15.08707 > shape <- 0.8592507 > lambda.risk <- 1.75 > L <- 7.5e5 > R <- 2.5e6 > > # Generate n random poisson with rate = lambda.risk > frequency <- function(n) rpois(n,lambda.risk) > > # clamp a numeric to 0, L > clamp <- function(x, min, max) pmin(max, pmax(min, x)) > > # Generate lognormal shifted by R > severity <- function(n) rlnorm(n,scale,shape)-R > > clamp(severity(100), 0, L) # Lognormal shifted left by R, and then clamped between 0 and L? Almost always equal to 0 or L > > sim <- function(breaks = 7){ > freq <- frequency(1) > i <- freq > 1:7 > sev <- clamp(severity(sum(i)), 0, L) > claims <- rep(0, 7) > claims[i] <- sev > min(22.5e6,sum(claims)) > } > > hist(iterations <- replicate(10000, sim()), breaks = 20) > > > > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of HUL-Anthony Egerton > Sent: Friday, July 14, 2017 7:45 PM > To: r-help at r-project.org > Subject: Re: [R] One Dimensional Monte Carlo Simulation > > Further to my email below, I have just realised that I forgot to include the specification of L and R. > > Hence, the code needs to include the following additional lines at the start;- > > L<-7.5e6 > R<-2.5e6 > > Apologies for any confusion caused! > > Best regards, > > Tony > > >> On 12 Jul 2017, at 10:03 AM, HUL-Anthony Egerton <mailto:aegerton at huntingtonunderwriting.com> wrote: >> >> I am trying to code a basic Monte Carlo Simulation in R where a Poisson distribution generates a frequency output that is then input into a Lognormal distribution, which produces a different, independent severity for each incidence. The individual incidences are then summed to produce an aggregate amount per period/iteration. >> >> Here is the code;- >> >> scale<-15.08707 >> shape<-0.8592507 >> lambda.risk<-1.75 >> L<-7.5e5 >> R<-2.5e6 >> iterations<-replicate(10000,{ >> claims1<-0 >> claims2<-0 >> claims3<-0 >> claims4<-0 >> claims5<-0 >> claims6<-0 >> claims7<-0 >> claims<-c(claims1,claims2,claims3,claims4,claims5,claims6,claims7) >> freq<-(qpois(runif(1),lambda.risk)) >> sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >> if(freq>=1){claims1<-sev} >> sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >> if(freq>=2){claims2<-sev} >> sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >> if (freq>=3) {claims3<-sev} >> sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >> if (freq>=4) {claims4<-sev} >> sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >> if (freq>=5) {claims5<-sev} >> sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >> if (freq>=6) {claims6<-sev} >> sev<-pmin(L,pmax(0,(qlnorm(runif(1),scale,shape)-R))) >> if (freq>=7) {claims7<-sev} >> claims<-c(claims1,claims2,claims3,claims4,claims5,claims6,claims7) >> min(22.5e6,sum(claims)) >> }) >> >> I am new to R, but am sure that there must be a simpler way to code this process. >> >> Furthermore, as the Poisson lambda increases, there is a need to include provision for potentially more incidences, which will require a manual expansion of the code to claims8, claims9 etc. >> >> Can you assist, please? >> >> Best regards, >> >> Anthony A H Egerton MA MBA ACII >> ????? >> HUNTINGTON UNDERWRITING LIMITED >> Labuan FT, Malaysia >> >> >> >> CONFIDENTIALITY NOTE: >> >> The information contained in this email message may be legally privileged and contain confidential information and is intended only for the use of the individual or entity to whom it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copy of this message is strictly prohibited. If you have received this email in error, please immediately delete this message. >> >> Begin forwarded message: >> >>> From: mailto:r-help-request at r-project.org >>> Date: 8 July 2017 at 6:00:02 PM SGT >>> To: mailto:r-help at r-project.org >>> Subject: R-help Digest, Vol 173, Issue 8 >>> Reply-To: mailto:r-help at r-project.org >>> >>> Send R-help mailing list submissions to >>> mailto:r-help at r-project.org >>> >>> To subscribe or unsubscribe via the World Wide Web, visit >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> or, via email, send a message with subject or body 'help' to >>> mailto:r-help-request at r-project.org >>> >>> You can reach the person managing the list at >>> mailto:r-help-owner at r-project.org >>> >>> When replying, please edit your Subject line so it is more specific >>> than "Re: Contents of R-help digest..." >>> >>> >>> Today's Topics: >>> >>> 1. R loop function in Tableau (Dai, Shengyu) >>> 2. Factor vs character in a data.frame vs vector (John Kane) >>> 3. Re: Factor vs character in a data.frame vs vector (Marc Schwartz) >>> 4. Re: Scoring and Ranking Methods (David Winsemius) >>> 5. Re: R loop function in Tableau (David Winsemius) >>> 6. Re: [Rd] italic font on cairo devices in R 3.4 (mailto:frederik at ofb.net) >>> 7. Re: [Rd] italic font on cairo devices in R 3.4 (mailto:frederik at ofb.net) >>> 8. Beginner s quwry about cfa in lavaan (Martina Hule?ov?) >>> 9. Re: [Rd] italic font on cairo devices in R 3.4 (Ilia Kats) >>> 10. Re: Beginner s quwry about cfa in lavaan (Bert Gunter) >>> 11. Re: Factor vs character in a data.frame vs vector (Marc Schwartz) >>> 12. Re: Factor vs character in a data.frame vs vector (John Kane) >>> 13. Re: [Rd] italic font on cairo devices in R 3.4 (Yixuan Qiu) >>> >>> >>> ---------------------------------------------------------------------- >>> >>> Message: 1 >>> Date: Thu, 06 Jul 2017 17:19:47 -0400 >>> From: "Dai, Shengyu" <mailto:dais2 at rpi.edu> >>> To: <mailto:r-help at r-project.org> >>> Subject: [R] R loop function in Tableau >>> Message-ID: <mailto:15947CD3-CD7B-4BB6-A994-D49D514DF0DE at rpi.edu> >>> Content-Type: text/plain; charset="UTF-8" >>> >>> Hi R helpers, >>> >>> >>> >>> I hope this email finds you well. >>> >>> >>> >>> I am having trouble with R loop function in Tableau. Please see the attachment of a simple dataset. The problem is to test whether the value of columns is match. >>> >>> >>> >>> Because Tableau do not have iteration function, I coded ?if statement? in Tableau to realize the function, which is slow if having huge amount of data. I wonder to integrate Tableau with R studio to realize this functionality. >>> >>> >>> >>> I did not find too much useful information online and I am asking helps for any examples of related low-level data calculation. >>> >>> >>> >>> Thank you very much. Your helps and supports are really appreciated! >>> >>> >>> >>> Best, >>> >>> >>> >>> -- >>> >>> >>> >>> Shengyu (Freddy) Dai >>> >>> Master of Science in Business Analytics >>> >>> Lally School of Management >>> >>> Rensselaer Polytechnic Institute >>> >>> Mobile: (513)328-5659 >>> >>> >>> >>> >>> >>> ------------------------------ >>> >>> Message: 2 >>> Date: Fri, 7 Jul 2017 11:03:51 +0000 >>> From: John Kane <mailto:jrkrideau at yahoo.ca> >>> To: R R-help <mailto:r-help at stat.math.ethz.ch> >>> Subject: [R] Factor vs character in a data.frame vs vector >>> Message-ID: <mailto:184884580.507511.1499425431478 at mail.yahoo.com> >>> Content-Type: text/plain; charset="UTF-8" >>> >>> This is not? serious problem but I just wonder if someone can explain what is happening. >>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. >>> Thanks >>> >>> #===============================================>>> dat1 <- data.frame(aa = letters[1:10]) >>> str(dat1) >>> data.frame':????10 obs. of??1 variable: >>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>> bb = letters[1:10] >>> str(bb) >>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>> #=============================================================>>> >>> >>> [[alternative HTML version deleted]] >>> >>> >>> >>> ------------------------------ >>> >>> Message: 3 >>> Date: Fri, 7 Jul 2017 09:37:12 -0500 >>> From: Marc Schwartz <mailto:marc_schwartz at me.com> >>> To: John Kane <mailto:jrkrideau at yahoo.ca> >>> Cc: R R-help <mailto:r-help at stat.math.ethz.ch> >>> Subject: Re: [R] Factor vs character in a data.frame vs vector >>> Message-ID: <mailto:36A7CFEC-57B6-4652-BC93-AB9E0EED14AF at me.com> >>> Content-Type: text/plain; charset="us-ascii" >>> >>> >>>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <mailto:r-help at r-project.org> wrote: >>>> >>>> This is not serious problem but I just wonder if someone can explain what is happening. >>>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character. It's probably something simple that I have read and forgotten but I thought I'd ask. >>>> Thanks >>>> >>>> #===============================================>>>> dat1 <- data.frame(aa = letters[1:10]) >>>> str(dat1) >>>> data.frame': 10 obs. of 1 variable: >>>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>>> bb = letters[1:10] >>>> str(bb) >>>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>>> #=============================================================>>>> >>> >>> >>> See the 'stringsAsFactors' argument in ?data.frame. >>> >>> dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE) >>> >>>> str(dat1) >>> 'data.frame': 10 obs. of 1 variable: >>> $ aa: chr "a" "b" "c" "d" ... >>> >>> >>> Regards, >>> >>> Marc Schwartz >>> >>> >>> >>> ------------------------------ >>> >>> Message: 4 >>> Date: Fri, 7 Jul 2017 08:47:57 -0700 >>> From: David Winsemius <mailto:dwinsemius at comcast.net> >>> To: Dhivya Narayanasamy <mailto:dhiv.shreya at gmail.com> >>> Cc: r-help mailing list <mailto:r-help at r-project.org> >>> Subject: Re: [R] Scoring and Ranking Methods >>> Message-ID: <mailto:B6A35831-5E7D-407A-BB82-504F33E0F488 at comcast.net> >>> Content-Type: text/plain; charset=us-ascii >>> >>> >>>> On Jul 7, 2017, at 2:29 AM, Dhivya Narayanasamy <mailto:dhiv.shreya at gmail.com> wrote: >>>> >>>> Hi, >>>> >>>> I am doing predictive modelling of Multivariate Time series Data of a Motor >>>> in R using various models such as Arima, H2O.Randomforest, glmnet, lm and >>>> few other models. >>>> >>>> I created a function to select a model of our choice and do prediction. >>>> >>>> Model1 <- function(){ >>>> .. >>>> return() >>>> } >>> >>> That looks like a prescription for serious disappointment. I seriously doubt that you have done any testing using similar code. You would have created a function that returns NULL. I get the sense that you need to study and work through the examples in the "Introduction to R" document. >>> >>> >>> >>>> Model2 <- function(){ >>>> ... >>>> return() >>>> } >>>> Model3 <- function(){ >>>> ... >>>> return() >>>> } >>>> main <- function(n){ >>>> if(n == 1) { >>>> Model1() >>>> } >>>> else if(n == 2){ >>>> Model2() >>>> } >>>> else if(n == 3){ >>>> Model3() >>>> }} >>>> Now I am supposed to automate these models which gives RMSE and MAPE of >>>> each model. I would like to provide scores (eg. out of 5) for each model >>>> based on the performance. For example, if Arima gives a low RMSE than other >>>> models, it will be scored high and the second lowest RMSE model will score >>>> a less than Arima and so on. >>>> >>>> And every time i run those models with different input Data [motor2, motor3 >>>> ..], it must give the mean score of a model. what I mean to say is, >>>> >>>> 1. for motor1 it will give scores of each model, let's say *s1*. >>>> 2. for motor2 run it give scores of each model, and let's call it *s2*. >>>> And i want a mean score of that model every time i run it with different >>>> input. It is more like scoring and ranking method. >>>> >>>> Are there any methods or packages in R that can give a glimpse of how it is >>>> done? or any examples? Any suggestions would be very helpful. >>> >>> The 'switch'-function can dispatch to different functions on the basis of the value of an indicator variable. >>> >>> >>>> >>>> Thank you. >>>> Dhivya >>>> >>>> [[alternative HTML version deleted]] >>> >>> Please read the Posting Guide. Rhelp is a plain text mailing list. >>>> >>>> ______________________________________________ >>>> mailto:R-help at 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. >>> >>> David Winsemius >>> Alameda, CA, USA >>> >>> >>> >>> ------------------------------ >>> >>> Message: 5 >>> Date: Fri, 7 Jul 2017 08:57:50 -0700 >>> From: David Winsemius <mailto:dwinsemius at comcast.net> >>> To: "Dai, Shengyu" <mailto:dais2 at rpi.edu> >>> Cc: mailto:r-help at r-project.org >>> Subject: Re: [R] R loop function in Tableau >>> Message-ID: <mailto:5B17A446-46C5-4371-94D3-A5C9A7CA6E7B at comcast.net> >>> Content-Type: text/plain; charset=utf-8 >>> >>> >>>> On Jul 6, 2017, at 2:19 PM, Dai, Shengyu <mailto:dais2 at rpi.edu> wrote: >>>> >>>> Hi R helpers, >>>> >>>> >>>> >>>> I hope this email finds you well. >>>> >>>> >>>> >>>> I am having trouble with R loop function in Tableau. >>>> >>> >>> There is no "R loop function". (There is an R `for`-function.) If you are having trouble with code then it should be provided. If the problem is with the Tableau code then this is the wrong place. Tableau is not either free or open source. You would in that case need to contact Tableau or get assistance from your academic institution. >>> >>>> Please see the attachment of a simple dataset. >>> >>> No data attached. Probably scrubbed by the mail server. Any data needs to be a .txt file. >>> >>>> The problem is to test whether the value of columns is match. >>> >>> There is a `match` function. It's vectorized, so may not need to be wrapped with a function that would provide looping. >>> >>>> >>>> Because Tableau do not have iteration function, I coded ?if statement? in Tableau to realize the function, which is slow if having huge amount of data. I wonder to integrate Tableau with R studio to realize this functionality. >>>> >>>> >>>> >>>> I did not find too much useful information online and I am asking helps for any examples of related low-level data calculation. >>> >>> That is then the fault of Tableau (if true), since there is a huge amount of online documentation for R. The Rhelp Archives and StackOverflow have thousands of worked examples of "low-level data calculation". I suspect with estimated probability approaching unity that StackOverflow will have questions tagged jointly with [r] and [tableau]. >>> >>> >>>> >>>> Thank you very much. Your helps and supports are really appreciated! >>>> >>>> >>>> >>>> Best, >>>> >>>> >>>> >>>> -- >>>> >>>> >>>> >>>> Shengyu (Freddy) Dai >>>> >>>> Master of Science in Business Analytics >>>> >>>> Lally School of Management >>>> >>>> Rensselaer Polytechnic Institute >>>> >>>> Mobile: (513)328-5659 >>>> >>>> >>>> >>>> ______________________________________________ >>>> mailto:R-help at 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. >>> >>> David Winsemius >>> Alameda, CA, USA >>> >>> >>> >>> ------------------------------ >>> >>> Message: 6 >>> Date: Fri, 7 Jul 2017 09:17:34 -0700 >>> From: mailto:frederik at ofb.net >>> To: Ilia Kats <mailto:ilia-kats at gmx.net> >>> Cc: mailto:r-devel at r-project.org, mailto:r-help at r-project.org >>> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >>> Message-ID: <mailto:20170707161734.GA833 at ofb.net> >>> Content-Type: text/plain; charset=us-ascii >>> >>> Hi Ilia, >>> >>> I'm running Arch Linux, R 3.4.0. >>> >>> Here's my test.pdf from your minimal example: https://ptpb.pw/HxsA.pdf >>> >>> It doesn't look pixelated to me... >>> >>> Here's a post that I wrote when I solved my last font problem in R, >>> almost 2 years ago: >>> >>> https://stackoverflow.com/a/40940331/5087283 >>> >>> I had to install some Microsoft font packages, which is sad, because >>> there are some perfectly good free fonts that R could be using >>> instead. It could be considered a bug that R requires Microsoft fonts, >>> at least by default. However, does this even fix your problem? I.e. if >>> you install the corresponding Debian Microsoft font packages, does the >>> text appear anti-aliased? >>> >>> Frederick >>> >>>> On Fri, Jul 07, 2017 at 10:30:46AM +0200, Ilia Kats wrote: >>>> [cross-post from R-help] >>>> >>>> Hi all, >>>> >>>> I have the following problem: Since R 3.4.0, italic fonts rendered on Cairo >>>> devices appear pixelated. Here's a minimal example: >>>> cairo_pdf('test.pdf') >>>> plot(1:10, ylab=expression(italic(test))) >>>> dev.off() >>>> >>>> The same problem occurs with bolditalic, but not bold. I am using Debian >>>> Stretch. Several friends tried the same on their machines, another Debian >>>> machine has the same problem. On MacOSX the output was not pixelated, but it >>>> wasn't italic either. Ubuntu 16.04.2 xenial works fine. My impression is >>>> that R somehow can't find the proper font to use and falls back to something >>>> weird. Ideas? >>>> >>>> Note that I'm not subscribed to the list, so please CC me in replies. >>>> >>>> Cheers, Ilia >>>> >>>> ______________________________________________ >>>> mailto:R-devel at r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-devel >>>> >>> >>> >>> >>> ------------------------------ >>> >>> Message: 7 >>> Date: Fri, 7 Jul 2017 10:28:44 -0700 >>> From: mailto:frederik at ofb.net >>> To: Ilia Kats <mailto:ilia-kats at gmx.net> >>> Cc: mailto:r-devel at r-project.org, mailto:r-help at r-project.org >>> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >>> Message-ID: <mailto:20170707172844.GE833 at ofb.net> >>> Content-Type: text/plain; charset=us-ascii >>> >>>> On Fri, Jul 07, 2017 at 07:08:52PM +0200, Ilia Kats wrote: >>>> Interesting. I did not have the package installed, but I did at some point >>>> extract Helvetica from some MacOSX font files and R was using that just fine >>>> until 3.3. This is how the plot looks in 3.4 (still using Helvetica): >>>> https://ptpb.pw/HikX.pdf . After removing Helvetica, installing the >>>> ttf-mscorefonts-installer package, and running fc-cache --force the plot >>>> looks like this: https://ptpb.pw/CM8A.pdf >>> >>> The second plot looks worse, in other words, and the Microsoft fonts >>> didn't help. >>> >>> Maybe the Cairo device should be giving better warning messages. >>> >>> Anyway it sounds like you are describing a regression so maybe someone >>> can track down the commit that created this problem. >>> >>> Thanks, >>> >>> Frederick >>> >>> >>>> Also note that the standard pdf device works fine: https://ptpb.pw/3Ml1.pdf >>>> , it's just the cairo devices (both pdf and svg) that have the issue. >>>> Unfortunately I need to use cairo_pdf due to unicode characters in axis >>>> labels. >>>> >>>> Cheers, Ilia >>>> >>>> >>>> -------- Original Message -------- >>>> Subject: Re: [Rd] italic font on cairo devices in R 3.4 >>>> Date: 2017-07-07 18:17:34 +0200 >>>> From: frederik >>>> To: Ilia Kats >>>> CC: r-devel, r-help >>>>> Hi Ilia, >>>>> >>>>> I'm running Arch Linux, R 3.4.0. >>>>> >>>>> Here's my test.pdf from your minimal example: https://ptpb.pw/HxsA.pdf >>>>> >>>>> It doesn't look pixelated to me... >>>>> >>>>> Here's a post that I wrote when I solved my last font problem in R, >>>>> almost 2 years ago: >>>>> >>>>> https://stackoverflow.com/a/40940331/5087283 >>>>> >>>>> I had to install some Microsoft font packages, which is sad, because >>>>> there are some perfectly good free fonts that R could be using >>>>> instead. It could be considered a bug that R requires Microsoft fonts, >>>>> at least by default. However, does this even fix your problem? I.e. if >>>>> you install the corresponding Debian Microsoft font packages, does the >>>>> text appear anti-aliased? >>>>> >>>>> Frederick >>>>> >>>>>> On Fri, Jul 07, 2017 at 10:30:46AM +0200, Ilia Kats wrote: >>>>>> [cross-post from R-help] >>>>>> >>>>>> Hi all, >>>>>> >>>>>> I have the following problem: Since R 3.4.0, italic fonts rendered on Cairo >>>>>> devices appear pixelated. Here's a minimal example: >>>>>> cairo_pdf('test.pdf') >>>>>> plot(1:10, ylab=expression(italic(test))) >>>>>> dev.off() >>>>>> >>>>>> The same problem occurs with bolditalic, but not bold. I am using Debian >>>>>> Stretch. Several friends tried the same on their machines, another Debian >>>>>> machine has the same problem. On MacOSX the output was not pixelated, but it >>>>>> wasn't italic either. Ubuntu 16.04.2 xenial works fine. My impression is >>>>>> that R somehow can't find the proper font to use and falls back to something >>>>>> weird. Ideas? >>>>>> >>>>>> Note that I'm not subscribed to the list, so please CC me in replies. >>>>>> >>>>>> Cheers, Ilia >>>>>> >>>>>> ______________________________________________ >>>>>> mailto:R-devel at r-project.org mailing list >>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel >>>>>> >>>> >>>> -- >>>> The first is to ensure your partner understands that nature has root >>>> privileges - nature doesn't have to make sense. >>>> -- Telsa Gwynne >>>> >>> >>> >>> >>> ------------------------------ >>> >>> Message: 8 >>> Date: Fri, 7 Jul 2017 16:52:34 +0000 >>> From: Martina Hule?ov? <mailto:mhulesova at gmail.com> >>> To: "mailto:r-help at r-project.org" <mailto:r-help at r-project.org> >>> Subject: [R] Beginner s quwry about cfa in lavaan >>> Message-ID: >>> <mailto:HE1PR09MB044320C242C964B3ADB51037BDAA0 at HE1PR09MB0443.eurprd09.prod.outlook.com> >>> >>> Content-Type: text/plain; charset="UTF-8" >>> >>> Dear all, >>> I am trying to learn about R. As a Phd student, I would like to use R for Krippendorff s alpha and later for a series of CFA. Is there any good introduction to these kind of analyses, or could you recommend me some tutorials on youtube, for example? I am new to R, so I need something basic , starting from opening the R environment?. >>> Thank you . >>> Martina Hulesova >>> >>> Odesl?no z m?ho Windows Phone >>> >>> [[alternative HTML version deleted]] >>> >>> >>> ------------------------------ >>> >>> Message: 9 >>> Date: Fri, 7 Jul 2017 19:08:52 +0200 >>> From: Ilia Kats <mailto:ilia-kats at gmx.net> >>> To: mailto:frederik at ofb.net >>> Cc: mailto:r-devel at r-project.org, mailto:r-help at r-project.org >>> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >>> Message-ID: <mailto:815d1e56-2fb9-1f7c-aa32-b15769cc72c8 at gmx.net> >>> Content-Type: text/plain; charset=utf-8; format=flowed >>> >>> Interesting. I did not have the package installed, but I did at some >>> point extract Helvetica from some MacOSX font files and R was using that >>> just fine until 3.3. This is how the plot looks in 3.4 (still using >>> Helvetica): https://ptpb.pw/HikX.pdf . After removing Helvetica, >>> installing the ttf-mscorefonts-installer package, and running fc-cache >>> --force the plot looks like this: https://ptpb.pw/CM8A.pdf >>> >>> Also note that the standard pdf device works fine: >>> https://ptpb.pw/3Ml1.pdf , it's just the cairo devices (both pdf and >>> svg) that have the issue. Unfortunately I need to use cairo_pdf due to >>> unicode characters in axis labels. >>> >>> Cheers, Ilia >>> >>> >>> -------- Original Message -------- >>> Subject: Re: [Rd] italic font on cairo devices in R 3.4 >>> Date: 2017-07-07 18:17:34 +0200 >>> From: frederik >>> To: Ilia Kats >>> CC: r-devel, r-help >>>> Hi Ilia, >>>> >>>> I'm running Arch Linux, R 3.4.0. >>>> >>>> Here's my test.pdf from your minimal example: https://ptpb.pw/HxsA.pdf >>>> >>>> It doesn't look pixelated to me... >>>> >>>> Here's a post that I wrote when I solved my last font problem in R, >>>> almost 2 years ago: >>>> >>>> https://stackoverflow.com/a/40940331/5087283 >>>> >>>> I had to install some Microsoft font packages, which is sad, because >>>> there are some perfectly good free fonts that R could be using >>>> instead. It could be considered a bug that R requires Microsoft fonts, >>>> at least by default. However, does this even fix your problem? I.e. if >>>> you install the corresponding Debian Microsoft font packages, does the >>>> text appear anti-aliased? >>>> >>>> Frederick >>>> >>>>> On Fri, Jul 07, 2017 at 10:30:46AM +0200, Ilia Kats wrote: >>>>> [cross-post from R-help] >>>>> >>>>> Hi all, >>>>> >>>>> I have the following problem: Since R 3.4.0, italic fonts rendered on Cairo >>>>> devices appear pixelated. Here's a minimal example: >>>>> cairo_pdf('test.pdf') >>>>> plot(1:10, ylab=expression(italic(test))) >>>>> dev.off() >>>>> >>>>> The same problem occurs with bolditalic, but not bold. I am using Debian >>>>> Stretch. Several friends tried the same on their machines, another Debian >>>>> machine has the same problem. On MacOSX the output was not pixelated, but it >>>>> wasn't italic either. Ubuntu 16.04.2 xenial works fine. My impression is >>>>> that R somehow can't find the proper font to use and falls back to something >>>>> weird. Ideas? >>>>> >>>>> Note that I'm not subscribed to the list, so please CC me in replies. >>>>> >>>>> Cheers, Ilia >>>>> >>>>> ______________________________________________ >>>>> mailto:R-devel at r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-devel >>>>> >>> >>> -- >>> The first is to ensure your partner understands that nature has root >>> privileges - nature doesn't have to make sense. >>> -- Telsa Gwynne >>> >>> >>> >>> ------------------------------ >>> >>> Message: 10 >>> Date: Fri, 7 Jul 2017 16:43:12 -0700 >>> From: Bert Gunter <mailto:bgunter.4567 at gmail.com> >>> To: Martina Hule?ov? <mailto:mhulesova at gmail.com> >>> Cc: mailto:r-help at r-project.org >>> Subject: Re: [R] Beginner s quwry about cfa in lavaan >>> Message-ID: >>> <mailto:CAGxFJbQ3CgCFXLBGsz9e8y=VLw=9gQKTw7CsoDjy6Feu4=HBLA at mail.gmail.com> >>> Content-Type: text/plain; charset="UTF-8" >>> >>> Google is your friend. >>> >>> Also rseek.org >>> >>> Bert >>> >>> >>> >>>> On Jul 7, 2017 3:48 PM, "Martina Hule?ov?" <mailto:mhulesova at gmail.com> wrote: >>>> >>>> Dear all, >>>> I am trying to learn about R. As a Phd student, I would like to use R for >>>> Krippendorff s alpha and later for a series of CFA. Is there any good >>>> introduction to these kind of analyses, or could you recommend me some >>>> tutorials on youtube, for example? I am new to R, so I need something basic >>>> , starting from opening the R environment?. >>>> Thank you . >>>> Martina Hulesova >>>> >>>> Odesl?no z m?ho Windows Phone >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> ______________________________________________ >>>> mailto:R-help at 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]] >>> >>> >>> >>> ------------------------------ >>> >>> Message: 11 >>> Date: Fri, 7 Jul 2017 21:25:42 -0500 >>> From: Marc Schwartz <mailto:marc_schwartz at me.com> >>> To: John Kane <mailto:jrkrideau at yahoo.ca> >>> Cc: R R-help <mailto:r-help at stat.math.ethz.ch> >>> Subject: Re: [R] Factor vs character in a data.frame vs vector >>> Message-ID: <mailto:28B1CAA7-85EA-41A2-9373-172F52773C81 at me.com> >>> Content-Type: text/plain; charset="us-ascii" >>> >>> >>>> On Jul 7, 2017, at 7:03 PM, John Kane <mailto:jrkrideau at yahoo.ca> wrote: >>>> >>>> Thanks Marc. >>>> It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame. I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. >>> >>> >>> Welcome John. >>> >>> Going back to the old NEWS files, the 'stringsAsFactors' argument for data.frame() appears in version 2.4.0, which was released on 2006-10-03. >>> >>> It is possible that somewhere along the way, you set options(stringsAsFactors = FALSE) in your .Rprofile, which would change the default behavior. I know that some folks do that, as they do not like the default coercion to factors, both for data.frame() and for the read.table() family. >>> >>> Other alternatives would be to use the 'colClasses' argument to explicitly set such vectors to character, or to use I(...) to create AsIs class columns. >>> >>> Regards, >>> >>> Marc >>> >>> >>>> >>>> >>>> >>>> On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <mailto:marc_schwartz at me.com> wrote: >>>> >>>> >>>> >>>>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <mailto:r-help at r-project.org> wrote: >>>>> >>>>> This is not serious problem but I just wonder if someone can explain what is happening. >>>>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character. It's probably something simple that I have read and forgotten but I thought I'd ask. >>>>> Thanks >>>>> >>>>> #===============================================>>>>> dat1 <- data.frame(aa = letters[1:10]) >>>>> str(dat1) >>>>> data.frame': 10 obs. of 1 variable: >>>>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>>>> bb = letters[1:10] >>>>> str(bb) >>>>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>>>> #=============================================================>>>>> >>>> >>>> >>>> See the 'stringsAsFactors' argument in ?data.frame. >>>> >>>> dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE) >>>> >>>> >>>>> str(dat1) >>>> 'data.frame': 10 obs. of 1 variable: >>>> >>>> $ aa: chr "a" "b" "c" "d" ... >>>> >>>> >>>> Regards, >>>> >>>> Marc Schwartz >>>> >>> >>> >>> >>> ------------------------------ >>> >>> Message: 12 >>> Date: Sat, 8 Jul 2017 00:03:19 +0000 >>> From: John Kane <mailto:jrkrideau at yahoo.ca> >>> To: Marc Schwartz <mailto:marc_schwartz at me.com> >>> Cc: R R-help <mailto:r-help at stat.math.ethz.ch> >>> Subject: Re: [R] Factor vs character in a data.frame vs vector >>> Message-ID: <mailto:595896971.1101053.1499472199840 at mail.yahoo.com> >>> Content-Type: text/plain; charset="UTF-8" >>> >>> Thanks Marc. It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame.? I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. >>> >>> >>> On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <mailto:marc_schwartz at me.com> wrote: >>> >>> >>>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <mailto:r-help at r-project.org> wrote: >>>> >>>> This is not? serious problem but I just wonder if someone can explain what is happening. >>>> The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. >>>> Thanks >>>> >>>> #===============================================>>>> dat1 <- data.frame(aa = letters[1:10]) >>>> str(dat1) >>>> data.frame':? ? 10 obs. of? 1 variable: >>>> $ aa....letters.1.10.: Factor w/ 10 levels "a","b","c","d",..: 1 2 3 4 5 6 7 8 9 10#============================================================>>>> bb = letters[1:10] >>>> str(bb) >>>> chr [1:10] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" >>>> #=============================================================>>>> >>> >>> >>> See the 'stringsAsFactors' argument in ?data.frame. >>> >>> dat1 <- data.frame(aa = letters[1:10], stringsAsFactors = FALSE) >>> >>>> str(dat1) >>> 'data.frame':??? 10 obs. of? 1 variable: >>> $ aa: chr? "a" "b" "c" "d" ... >>> >>> >>> Regards, >>> >>> Marc Schwartz >>> >>> [[alternative HTML version deleted]] >>> >>> >>> >>> ------------------------------ >>> >>> Message: 13 >>> Date: Sat, 8 Jul 2017 01:11:10 -0400 >>> From: Yixuan Qiu <mailto:yixuan.qiu at cos.name> >>> To: mailto:ilia-kats at gmx.net >>> Cc: mailto:frederik at ofb.net, r-help <mailto:r-help at r-project.org> >>> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >>> Message-ID: >>> <mailto:CAFr_7yFTMPers4D9P_vaPW5=R-qvRq0+_LDb56d3TewC7H4uLg at mail.gmail.com> >>> Content-Type: text/plain; charset="UTF-8" >>> >>> Hi Ilia, >>> >>> You may want to have a try of the showtext package >>> (https://github.com/yixuan/showtext). Below is a quick example: >>> >>> library(showtext) >>> showtext.auto() >>> >>> pdf("test.pdf") >>> ## Use the "sans" font family provided by the showtext package >>> ## font == 3 means italic font face >>> plot(1, xlab = "Unicode characters: \u00C0 \u00C6 \u00D8", >>> family = "sans", font.lab = 3) >>> dev.off() >>> >>> ## Same for SVG >>> svg("test.svg") >>> plot(1, xlab = "Unicode characters: \u00C0 \u00C6 \u00D8", >>> family = "sans", font.lab = 3) >>> dev.off() >>> >>> >>> Best, >>> Yixuan >>> >>> >>> 2017-07-07 13:08 GMT-04:00 Ilia Kats <mailto:ilia-kats at gmx.net>: >>>> Interesting. I did not have the package installed, but I did at some point >>>> extract Helvetica from some MacOSX font files and R was using that just fine >>>> until 3.3. This is how the plot looks in 3.4 (still using Helvetica): >>>> https://ptpb.pw/HikX.pdf . After removing Helvetica, installing the >>>> ttf-mscorefonts-installer package, and running fc-cache --force the plot >>>> looks like this: https://ptpb.pw/CM8A.pdf >>>> >>>> Also note that the standard pdf device works fine: https://ptpb.pw/3Ml1.pdf >>>> , it's just the cairo devices (both pdf and svg) that have the issue. >>>> Unfortunately I need to use cairo_pdf due to unicode characters in axis >>>> labels. >>>> >>>> Cheers, Ilia >>>> >>> >>> >>> >>> >>> -- >>> Yixuan Qiu <mailto:yixuan.qiu at cos.name> >>> Department of Statistics, >>> Purdue University >>> >>> >>> >>> ------------------------------ >>> >>> Subject: Digest Footer >>> >>> _______________________________________________ >>> mailto:R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> ------------------------------ >>> >>> End of R-help Digest, Vol 173, Issue 8 >>> ************************************** > > [[alternative HTML version deleted]] > ______________________________________________ > mailto:R-help at 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]]