Survival analysis [closed] - r

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I get the following error when I run the code below
Error in as.numeric(time) : cannot coerce type 'closure' to vector of type 'double'
Code:
mod <- survreg((Surv(as.numeric(time), event=status)) ~ prison+dose+clinic,
data = meth,
dist = "lognormal")
Hope someone can help with this.
Sandeep

This should solve your problem:
mod <- survreg((Surv(as.numeric(Time), event=Status)) ~ Prison+Dose+Clinic,
data = meth,
dist = "lognormal")
as you reported to me that:
names(meth)
# [1] "ID" "Clinic" "Status" "Time" "Prison" "Dose"
Note, it is Time, not time; Also, it is Status, not status. In fact, all variables names start with a capital letter!

Related

Why if_else function does not work in other data set [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
I am running an if_else function to create a new outcome vectors from 4 columns of data.
The command is as follows:
payment_amt <- if_else( interest_rate>0,
(balance-(balance*amortisation_factor)/(1+(interest_rate/12))^tenor)*((interest_rate/12)/(1-((1+(interest_rate/12))^(-1*tenor)))),
0 )
This command work well in 1 of my data
But does not work in other data
I tried my best to google but could not understand why the command did not work for the second set of data.
Very much appreciate if anyone can help!
Here I attach here my code & the data_work and data_not_work sets for your reference
# Data Work _ test
tenor = data_work[,"ECL_TENOR"]
interest_rate = data_work[,"INTEREST_RATE"]
amortisation_factor = data_work[,"AMORTISATION_FACTOR"]
balance = data_work[,"ECL_BALANCE"]
payment_amt <- if_else( interest_rate>0,
(balance-(balance*amortisation_factor)/(1+(interest_rate/12))^tenor)*((interest_rate/12)/(1-((1+(interest_rate/12))^(-1*tenor)))),
0 )
payment_amt
#####################################################
# Data Not work _ Test
tenor = data_not_work[,"ECL_TENOR"]
interest_rate = data_not_work[,"INTEREST_RATE"]
amortisation_factor = data_not_work[,"AMORTISATION_FACTOR"]
balance = data_not_work[,"ECL_BALANCE"]
payment_amt <- if_else( interest_rate>0,
(balance-(balance*amortisation_factor)/(1+(interest_rate/12))^tenor)*((interest_rate/12)/(1-((1+(interest_rate/12))^(-1*tenor)))),
0 )
Here is data
After posting this question, I found out that during the merging process, the data_not_work set has been hiddenly converted to tible, that why if_else does not work. When I convert it back to data frame, then if_else work.

R basics and questions [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
I have assigned a value for a variable but still am getting an error message. Kindly help me rectify
Code:
n <- 1000
x <- seq(1,n)
sum(x)
Error: object 'x' not found
You either need to use a new line for each command or end each command with semicolon (";")
n <- 1000
x <- seq(1,n)
sum(x)
Or:
n <- 1000; x <- seq(1,n); sum(x)

In my CSV file, it shows I have 1 column when I actually have 15 columns [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
> df <- read.csv("DATA ONLY.csv", header = TRUE, sep = ";")
> dim(df)
[1] 439 1
This is the code I use and this is the CSV
https://docs.google.com/spreadsheets/d/1SOqDKXZ7BAMW5LdqBcBIvQE9_PnFcNIHDfYDty3cTto/edit?usp=sharing
I am 99% sure that you have defined the field separator wrong. data.table::fread is really good at sniffing the correct format of csv's, and I quite often use fread even if I just convert the resulting data.table back to vanilla data frame, i.e.
library(data.table)
df <- fread("DATA ONLY.csv")
as.data.frame(df) -> df

string detection in dplyr filter results in evaluation error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am using R and the dplyr library to perform string search for a character data.frame that consists of one column. Performing an AND operation on two strings for conditional test to location data. I have an error in dplyr::filter evaluation.
str(dec2013.data)
'data.frame': 10481 obs. of 1 variable:
$ Routing.SYSID: chr "L839ITSRLX001TGU3" "L839SMARLX001TGU3"
"L839CRJRLX001TGU3" "L839BUARLX001TGU3"
dec2013.data.route1 <- data.frame()
dec2013.data.route1 <- dec2013.data %>%
filter(str_detect(Routing.SYSID,"L839" &
str_detect(Routing.SYSID,"TGU3")))
dput()
"L839CHHFNL626TGU3", "L839HPHFNL626TGU3", "L839NHBFNL626TGU3",
"L839BMQFNL626TGU3", "L839JUCFNL626TGU3", "L839KJYFNL626TGU3",
"L839KPPFNL626TGU3", "L839IWHFNL626TGU3", "L839NOFFNL626TGU3",
"L839DXQFNL626TGU3", "L839TMUFNL626TGU3", "L839RGCFNL626TGU3"
Error in filter_impl(.data, quo) : Evaluation error: operations are
possible only for numeric, logical or complex types.
you just have wrong parenthesis. This should work:
dec2013.data %>%
filter(str_detect(Routing.SYSID,"L839"), str_detect(Routing.SYSID,"TGU3"))

Composing two functions in R gives different result than a new function enclosing both [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I tried to look at the logistic map
logMap <- function(x){
r <- 0.5
4*r*x*(1-x)}
and its compositions such as:
logMap2_a <- function(x){
logMap(logMap(x))}
Of course, you can also directly write a new function that composes logMap with itself:
logMap2 <- function(x){
r <- 0.5
16*r*r*x*(1-x)*(1-16*r*r*x*(1-x))}
Now, plotting the two things does not show the same curve:
curve(logMap2, from=0, to=1)
curve(logMap2_a, from=0, to=1)
The first figure shows the result of logMap2, the second that of logMap2_a.
My first idea was that the problem arises due to the precision of returned data, but I cannot imagine that this is a problem with this reasonably large numbers. Any idea what is going on?
logMap2 <- function(x){
r <- 0.5
16*r*r*x*(1-x)*(1-4*r*x*(1-x))}

Resources