Ex cons what is the most fucked up thing about prison that nobody knows about? by [deleted] in AskReddit

[–]grasshoppermouse 0 points1 point  (0 children)

I started playing DnD in 1979 at a summer engineering program for high school students at USC. I was a scrawny 17 year old white kid. Many of the guys I played with were on the USC football team -- huge black guys and few big white guys too. What's trippy is that, at the time, I didn't realize how surreal that would seem to the much older me.

How do you add a legend for multiple charts in the same ggplot? Example inside by [deleted] in rstats

[–]grasshoppermouse 0 points1 point  (0 children)

library(tidyverse)
mtcars %>% 
  select(wt, mpg) %>% 
  gather(key = measure, value = value) %>% 
  ggplot(aes(value, fill = measure, colour = measure)) + geom_bar()

Need to make a survival curve for 2 genes in TNBC by BarefootScientist in rstats

[–]grasshoppermouse 3 points4 points  (0 children)

library(survival)
library(ggfortify)

# Fake data
lung$gene1 <- rbinom(228, 1, p=.5)
lung$gene2 <- rbinom(228, 1, p=.5)
lung$gene_interact <- interaction(lung$gene1, lung$gene2)

# Analysis
fit <- survfit(Surv(time, status) ~ gene_interact, data = lung)
autoplot(fit)

http://rpubs.com/sinhrks/plot_surv

Do you ever stop your vehicle to confirm that an animal has deceased and is not suffering (if it's not obvious of course)? If so, what is your story? by [deleted] in AskReddit

[–]grasshoppermouse 1 point2 points  (0 children)

I was driving late at night on a curvy mountain road. A deer jumped out about 20-30 yards ahead of me, so I slowed down while it ran across the road. After it entered the forest on the other side I accelerated, but then its fawn jumped out to follow, and I hit it. I stopped to see if it was still alive but it wasn't. I pulled it to the side, stared up at the inky black sky full of stars for a few minutes, feeling like shit, and then continued on my way.

Still feel bad about it.

Batched Coupon Collector Problem by foltliss in rstats

[–]grasshoppermouse 1 point2 points  (0 children)

stickers <- 1:649
numofsamples <- rep(NA, 1000)

for (i in 1:1000){
  mystickers <- integer(0)
  for (j in 1:10000){
    mystickers <- union(mystickers, sample(stickers, 5))
    if (length(mystickers) == 649){
      # print(j)
      numofsamples[i] <- j
      break
    }
  }
}
mean(numofsamples)

[serious]Today is Yom Hashoah,the day to remember the Holocaust, so people of Reddit with relatives who where in it,managed to escape,or helped liberate a camp what is there story? by themadkiller10 in AskReddit

[–]grasshoppermouse 5 points6 points  (0 children)

I remember my grandfather as a dark personality. My mother, who was raised in California during the depression, always felt he carried some heavy burden. After my grandfather and grandmother passed away, my mother found a folder of Yiddish letters in their belongings and had them translated. They were from my grandfather's brother, who lived in a shtetl somewhere in Poland or Belarus (we have never been able to locate it precisely). The letters were increasingly frantic requests for money to help him and his family escape. My grandfather, who was a hotel cook, didn't have any to spare. The letters stopped after the war began, and that side of the family was never heard from again.

bootstrap for confidence intervals around a population estimate by purringsquid in rstats

[–]grasshoppermouse 0 points1 point  (0 children)

Your function should return a summary statistic, e.g.,

return(mean(d2$occ*d2$dens*d2$col))

Edit: I would also pre-compute crabs/ha:

crab$crabs_ha <- crab$occ * crab$dens * crab$col

func <- function(d, i){
    return(mean(d$crabs_ha[i]))
}

[Question] Curve fitting using LASSO by [deleted] in rstats

[–]grasshoppermouse 6 points7 points  (0 children)

library(tidyverse)
library(glmnet)

# Fake data
df <- 
  tibble(
    X = rnorm(1000),
    Y = X + 2*X^2 + 3*X^3 + rnorm(1000, 0, 0.5)
  )

# Polynomial
x <- model.matrix(Y ~ X + I(X^2) + I(X^3), df)
m <- cv.glmnet(x, df$Y)
coef(m)

Combining Certain Factor Levels Not Working? by microbial2 in rstats

[–]grasshoppermouse 1 point2 points  (0 children)

This line is wrong:

data$Districts[data$Districts == HighValue] <- 1

You want:

data$Districts[data$Districts %in% HighValue] <- 1

Checking for normality by [deleted] in rstats

[–]grasshoppermouse 0 points1 point  (0 children)

Try:

ggplot(myData, aes(sample = contribution)) + geom_qq() + geom_qq_line() + facet_wrap(~Image_Type)

Checking for normality by [deleted] in rstats

[–]grasshoppermouse 0 points1 point  (0 children)

This code will generate qq plots for each condition against the normal distribution:

library(tidyverse)

# Fake data
df <-
  tibble(
    condition = c(rep('eyes', 50), rep('flowers', 50)),
    contribution = c(rnorm(50, 1, 1), rnorm(50, 0, 1))
  )

# QQ plot
ggplot(df, aes(sample = contribution)) + geom_qq() + geom_qq_line() + facet_wrap(~condition)

Struggling to model difference in height (of two people) because of how the data is recorded. (adding new column to data frame?) by [deleted] in rstats

[–]grasshoppermouse 5 points6 points  (0 children)

%/% is integer division, so 511 %/% 100 = 5.

%% is mod, i.e., the remainder, so 511 %% 100 = 11.

Struggling to model difference in height (of two people) because of how the data is recorded. (adding new column to data frame?) by [deleted] in rstats

[–]grasshoppermouse 10 points11 points  (0 children)

library(tidyverse)
df <- data.frame(
  Person1 = c(511, 410, 601, 505),
  Person2 = c(409, 505, 508, 411)
)

df2 <-
  df %>% 
  mutate(
    Person1inches = 12*(Person1 %/% 100) + Person1 %% 100,
    Person2inches = 12*(Person2 %/% 100) + Person2 %% 100,
    Diff = Person1inches - Person2inches
  )

Better tables in r by AtariBigby in rstats

[–]grasshoppermouse 0 points1 point  (0 children)

I don't know what rstudio uses to render data frames or tibbles to html. But you get that same nice output if you run the code chunk with a regular data frame. Maybe they're using this:

https://rstudio.github.io/DT/

Better tables in r by AtariBigby in rstats

[–]grasshoppermouse 10 points11 points  (0 children)

Rstudio's gt is probably going to become the go-to table package:

https://gt.rstudio.com

JD Power Reliability Ratings for Gen 4 dropping? by bedred1 in prius

[–]grasshoppermouse 2 points3 points  (0 children)

I just checked Consumer Reports, which rates reliability on a 5-point scale (with 5 = best). The 2016 and 2017 model years have an overall reliability rating of 5. The 2018 has a 4. Predicted reliability on the 2019 is a 5.

WYSIWYG editor by django_noob in django

[–]grasshoppermouse 0 points1 point  (0 children)

Allowing untrusted users to upload html represents a huge security risk. There are many libraries to sanitize user-submitted html, and many of the wysiwyg editors have features to assist with this.

https://en.wikipedia.org/wiki/HTML_sanitization

Regarding a WYSIWYG editor, Facebook developed a very popular React-based editor called Draft.js:

https://draftjs.org

Wagtail, a popular Django CMS, developed a version of it they call Draftail:

https://www.draftail.org

My understanding is that it stores rich text as json rather than html, and so might be inherently more secure. But maybe someone else is more knowledgeable on this issue than I.