u/Bikes_are_amazing

Getting previous value in a group

Hi, I was wondering how i could obtain the value from the previous row in a group.

In the example below i set time_number2 to have the first value in status for each group. This would be what i want if all groups had only 2 rows, but with 3+ rows in a group I instead want the value from the previous row.

Does anyone have ideas to lead me in the right directions? Thanks in advance.

MRE below

library(survival)
library(tidyverse)
lung <- lung
test <- lung %>% 
  arrange(inst,time) %>% 
  mutate(number = 1) %>% 
  mutate(time_number = cumsum(number)) %>% 
  relocate(time_number) %>% 
  group_by(inst) %>% 
  mutate(time_number2 = status[1]) %>% 
  relocate(time_number2)
reddit.com
u/Bikes_are_amazing — 13 days ago

Regression analysis advise

Hi.

I'm tracking some market prices in the game https://2004.lostcity.rs/title which in short is a f2p game based on runescape in 2004 with open source code.

The data I have have 3 columns: price, date and quantity. I currently have added a simply linear regression on top of the data where the quantity does not matter. This regression will make little sence as time goes by since markets priceses don't follow linear patterns over long periods of time.

I guess I looking for tips for regression models where the quantity matters/does not matter.

Added picture below easier visualization of what I've done.

My market analysis with linear regression

reddit.com
u/Bikes_are_amazing — 24 days ago

Lets say I've done Cox regression with the lung dataset and adjusted the model for an age category, and I want to check if the PH assumption holds. If it's an unadjusted model you can do a log minus log plot of the Kaplan-Meier curve, but is this still possible to use the log minus log method to check the PH assumption if the model is adjusted?

Thanks in advance.

Example code below:

library(tidyverse)
library(survival)

lung <- lung %>% 
  mutate(sex = if_else(sex == 1 , "Man" , "Woman")) %>% 
  mutate(age_cat = if_else(age < 60 , "<60", ">=60"))

cox_fit <- coxph(Surv(time,status) ~ sex + age_cat , data = lung)
reddit.com
u/Bikes_are_amazing — 2 months ago