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-boun...@r-project.org] On Behalf Of HUL-Anthony Egerton Sent: Friday, July 14, 2017 7:45 PM To: r-help@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:aeger...@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-requ...@r-project.org >> Date: 8 July 2017 at 6:00:02 PM SGT >> To: mailto:r-help@r-project.org >> Subject: R-help Digest, Vol 173, Issue 8 >> Reply-To: mailto:r-help@r-project.org >> >> Send R-help mailing list submissions to >> mailto:r-help@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-requ...@r-project.org >> >> You can reach the person managing the list at >> mailto:r-help-ow...@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:frede...@ofb.net) >> 7. Re: [Rd] italic font on cairo devices in R 3.4 (mailto:frede...@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:da...@rpi.edu> >> To: <mailto:r-help@r-project.org> >> Subject: [R] R loop function in Tableau >> Message-ID: <mailto:15947cd3-cd7b-4bb6-a994-d49d514df...@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:jrkrid...@yahoo.ca> >> To: R R-help <mailto:r-h...@stat.math.ethz.ch> >> Subject: [R] Factor vs character in a data.frame vs vector >> Message-ID: <mailto:184884580.507511.1499425431...@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_schwa...@me.com> >> To: John Kane <mailto:jrkrid...@yahoo.ca> >> Cc: R R-help <mailto:r-h...@stat.math.ethz.ch> >> Subject: Re: [R] Factor vs character in a data.frame vs vector >> Message-ID: <mailto:36a7cfec-57b6-4652-bc93-ab9e0eed1...@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@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:dwinsem...@comcast.net> >> To: Dhivya Narayanasamy <mailto:dhiv.shr...@gmail.com> >> Cc: r-help mailing list <mailto:r-help@r-project.org> >> Subject: Re: [R] Scoring and Ranking Methods >> Message-ID: <mailto:b6a35831-5e7d-407a-bb82-504f33e0f...@comcast.net> >> Content-Type: text/plain; charset=us-ascii >> >> >>> On Jul 7, 2017, at 2:29 AM, Dhivya Narayanasamy >>> <mailto:dhiv.shr...@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@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:dwinsem...@comcast.net> >> To: "Dai, Shengyu" <mailto:da...@rpi.edu> >> Cc: mailto:r-help@r-project.org >> Subject: Re: [R] R loop function in Tableau >> Message-ID: <mailto:5b17a446-46c5-4371-94d3-a5c9a7ca6...@comcast.net> >> Content-Type: text/plain; charset=utf-8 >> >> >>> On Jul 6, 2017, at 2:19 PM, Dai, Shengyu <mailto:da...@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@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:frede...@ofb.net >> To: Ilia Kats <mailto:ilia-k...@gmx.net> >> Cc: mailto:r-de...@r-project.org, mailto:r-help@r-project.org >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: <mailto:20170707161734.ga...@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-de...@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:frede...@ofb.net >> To: Ilia Kats <mailto:ilia-k...@gmx.net> >> Cc: mailto:r-de...@r-project.org, mailto:r-help@r-project.org >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: <mailto:20170707172844.ge...@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-de...@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:mhules...@gmail.com> >> To: "mailto:r-help@r-project.org" <mailto:r-help@r-project.org> >> Subject: [R] Beginner s quwry about cfa in lavaan >> Message-ID: >> >><mailto:he1pr09mb044320c242c964b3adb51037bd...@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-k...@gmx.net> >> To: mailto:frede...@ofb.net >> Cc: mailto:r-de...@r-project.org, mailto:r-help@r-project.org >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: <mailto:815d1e56-2fb9-1f7c-aa32-b15769cc7...@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-de...@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.4...@gmail.com> >> To: Martina Hule?ov? <mailto:mhules...@gmail.com> >> Cc: mailto:r-help@r-project.org >> Subject: Re: [R] Beginner s quwry about cfa in lavaan >> Message-ID: >> >><mailto:CAGxFJbQ3CgCFXLBGsz9e8y=VLw=9gQKTw7CsoDjy6Feu4=h...@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:mhules...@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@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_schwa...@me.com> >> To: John Kane <mailto:jrkrid...@yahoo.ca> >> Cc: R R-help <mailto:r-h...@stat.math.ethz.ch> >> Subject: Re: [R] Factor vs character in a data.frame vs vector >> Message-ID: <mailto:28b1caa7-85ea-41a2-9373-172f52773...@me.com> >> Content-Type: text/plain; charset="us-ascii" >> >> >>> On Jul 7, 2017, at 7:03 PM, John Kane <mailto:jrkrid...@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_schwa...@me.com> wrote: >>> >>> >>> >>>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help >>>> <mailto:r-help@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:jrkrid...@yahoo.ca> >> To: Marc Schwartz <mailto:marc_schwa...@me.com> >> Cc: R R-help <mailto:r-h...@stat.math.ethz.ch> >> Subject: Re: [R] Factor vs character in a data.frame vs vector >> Message-ID: <mailto:595896971.1101053.1499472199...@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_schwa...@me.com> wrote: >> >> >>> On Jul 7, 2017, at 6:03 AM, John Kane via R-help >>> <mailto:r-help@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....@cos.name> >> To: mailto:ilia-k...@gmx.net >> Cc: mailto:frede...@ofb.net, r-help <mailto:r-help@r-project.org> >> Subject: Re: [R] [Rd] italic font on cairo devices in R 3.4 >> Message-ID: >> >><mailto:CAFr_7yFTMPers4D9P_vaPW5=r-qvrq0+_ldb56d3tewc7h4...@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-k...@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....@cos.name> >> Department of Statistics, >> Purdue University >> >> >> >> ------------------------------ >> >> Subject: Digest Footer >> >> _______________________________________________ >> mailto:R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> ------------------------------ >> >> End of R-help Digest, Vol 173, Issue 8 >> ************************************** [[alternative HTML version deleted]] ______________________________________________ mailto:R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.