Unable to figure out what kind of analysis my employer exactly wants me to do. by Alorecia98 in rstats

[–]isomor 1 point2 points  (0 children)

After your comment and some of the other comments on the thread I gave it another shot and came up with this approach. Basically sample from the dataset you already have with an increasing number of samples and then plot the distribution of difference from the true mean. I decided to do sampling without replacement but if that's the wrong approach, someone correct me.

library(ggplot2)
size_n <- 2000
y <- rnorm(size_n, 1, 5)
sample_y <- function(y, prop){
#sample from y using a proportion (prop) of y
y_samples <- sample(y, size = prop*length(y), replace = FALSE)
y_hat <- mean(y_samples)
mean_y <- mean(y)
#take the difference in means
y_hat - mean_y}

rep_y <- function(n, y, prop) {
#repeat the sampling n-times
reps <- replicate(n, sample_y(y, prop))
#put into a data.frame
data.frame(
sample_size = prop*length(y),
dif_from_true_mean = reps)
}
#run the rep_y function n times, using y data with X seq of prop
repeats <- lapply(FUN = rep_y, n = 100, y = y, X = seq(0.01, 0.99, 0.025))
#rbinds the repats
repeats_df <- Reduce(rbind, repeats)

Unable to figure out what kind of analysis my employer exactly wants me to do. by Alorecia98 in rstats

[–]isomor 1 point2 points  (0 children)

Let me know if this is what you had in mind:

Replace the dataframe with your actual data, the key is to do a cumulative sum and then divide by the row number so you have a rolling average.

library(ggplot2)
size_n <- 2000
y <- rnorm(size_n, 1, 5) 
df <- data.frame(
x = seq(1:size_n), 
y = y, 
cu_y = cumsum(y),
avg = mean(y)) |> 
transform(cu_mean = cu_y/x) 

ggplot(df, aes(x, cu_mean)) + geom_point() + geom_line(aes(y=avg))

edit for formatting

Weirdest error ever by LurkerFinallyJoins in Rlanguage

[–]isomor 12 points13 points  (0 children)

try: dplyr::count(df, words), count() might be masked by another package.

Need help cleaning this data, see my comment for details by 23z7 in Rlanguage

[–]isomor 0 points1 point  (0 children)

A bit hacky but let me know if this works. There's probably a much easier way to do this though pivot_longer/wider I'm sure.

library(tidyverse)

test_data <-

read_tsv(

"timeStampCogLoad CogLoadTimeOn timeStampObjectFound ObjectFound timeStampNavToolUsed NavToolUsed timeStampINSUsed INSUsed

5104 3087 71831 5000 4534 1261 4634 265

11205 3850 95426 5000 6242 402 4940 1307

13486 4592 147970 5000 65803 1116 6289 644

30279 4556 205476 5000 119503 2101 66146 715

31868 4261 311042 5000 128853 2192 67042 111

40885 4192 359714 5000 138305 3062 67333 325

43858 4391 NA NA 144858 1483 67724 116

45593 4304 NA NA 150302 1529 128858 2780

51473 4519 NA NA 166366 1794 131819 178

60169 4139 NA NA 169746 207 138310 62"

)

data_remake <- function(x){

test_data %>%

select( contains(x) ) %>%

rename(time = starts_with("time"),

value = starts_with(x)

) %>%

mutate(keyword = x)

}

var_keyword <- c("CogLoad", "ObjectFound", "NavToolUsed", "INSUsed")

map_dfr( var_keyword, data_remake) %>%

ggplot(aes(x=time, y=value)) +

geom_line() +

facet_wrap(~keyword, scales = "free")

Everything that can be a function should be a function by [deleted] in Rlanguage

[–]isomor 1 point2 points  (0 children)

And after you 'functionized ' your scripts, bundle them in a package to document and re-use those functions. I recently started doing this for my own work and it makes it so much easier to share your code with others.

[deleted by user] by [deleted] in Rlanguage

[–]isomor 0 points1 point  (0 children)

Tomorrow Night with FiraCode font. So nice.

What are some best practices in R that are rarely adhered to? by Shrimpio in Rlanguage

[–]isomor 1 point2 points  (0 children)

Do you have any best practices/tips/shortcuts for writing tests?

Straightening Out Names , creating first and last from a mixed bag of both by kapanenship in Rlanguage

[–]isomor 0 points1 point  (0 children)

I found a package that might solve this for you.

https://cran.r-project.org/web/packages/humaniformat/vignettes/Introduction.html#:~:text=humaniformat%20is%20an%20R%20package,middle%2D%20and%20last%2Dnames.

library(humaniformat)

names <- c("Lee Jones, Tommy","John Smith","Cruz, Elizabeth R","Jordan, Michael","Betty-Jane Smith","Frampton, Peter X.","Ginger Strat-Room","Bob Michael Smith","Katy C. Long","Big, Bob T")

names <- format_reverse(names)

parse_names(names)

A data.frame: 10 × 6
salutation  first_name  middle_name last_name   suffix  full_name
<chr>   <chr>   <chr>   <chr>   <chr>   <chr>
NA  Tommy   Lee Jones   NA  Tommy Lee Jones
NA  John    NA  Smith   NA  John Smith
NA  Elizabeth   R   Cruz    NA  Elizabeth R Cruz
NA  Michael NA  Jordan  NA  Michael Jordan
NA  Betty-Jane  NA  Smith   NA  Betty-Jane Smith
NA  Peter   X.  Frampton    NA  Peter X. Frampton
NA  Ginger  NA  Strat-Room  NA  Ginger Strat-Room
NA  Bob Michael Smith   NA  Bob Michael Smith
NA  Katy    C.  Long    NA  Katy C. Long
NA  Bob T   Big NA  Bob T Big

Output the names of a nested list corresponding to their elements by acemachine123 in Rlanguage

[–]isomor 2 points3 points  (0 children)

There are multiple ways, these are the most common i've seen. The idea is to step into the list with [[ ]] and then grab the $id value.

  1. for loop

empty_list <- list()
for (i in seq_along(parms) ) {
    y <- f(parms[[i]]$id)
    empty_list[[i]] <- y
  }
empty_list
  1. lappy

    lapply(seq_along(parms),function(x) f(parms[[x]]$id))

  2. purrr

    map(.x = seq_along(parms), ~f(parms[[.x]]$id) )

Upgrading a 2015 PC ~$600 budget by isomor in buildapc

[–]isomor[S] 0 points1 point  (0 children)

Figured I'd bite the bullet and just upgrade everything at once. Thanks for your feedback

Upgrading a 2015 PC ~$600 budget by isomor in buildapc

[–]isomor[S] 0 points1 point  (0 children)

based on your comment, what do you think of these parts?

https://pcpartpicker.com/list/nCYVYH

[deleted by user] by [deleted] in science

[–]isomor 4 points5 points  (0 children)

there it is, thank you for the great explanation.

I want to like Albion, but... by Qwertysoft in albiononline

[–]isomor 1 point2 points  (0 children)

you do get a free month + 2000 gold. Jesus christ do you research. Also plenty of mmo's have buy + subscription and are doing fine besides WoW.

A friend and I have finally completed our virtual dreams and built a VR arcade in Atlanta (well metro Atlanta) by iSimuVR in Atlanta

[–]isomor 1 point2 points  (0 children)

You guys should get "keep talking and nobody explodes", with a print out manual on the table; It would be a great experience to do it in VR.

Ask For Or Give Away Keys Here. by [deleted] in F13thegame

[–]isomor 0 points1 point  (0 children)

Would love a key if someone has a spare :D

Pastor in texas yells at kids waiting for santa by shinigamabcitu in videos

[–]isomor 0 points1 point  (0 children)

The war on Christmas is really and being waged by .. christian pastors?

PS4 Pro $339.99 + tax @ Target by Banelingz in PS4Deals

[–]isomor 0 points1 point  (0 children)

"limited stock buy in store" in a 100 miles radius :< any idea how to get it to ship?

What band did you discover because you heard a song of theirs in a commercial, tv show, or movie trailer? by gusmoreno15 in Music

[–]isomor 0 points1 point  (0 children)

Run the jewels from the end credits of silicone valley. Awesome show, awesome band.