I have a stepwise structure of tariffs for treatments. Treatment between 0-33 hrs receive the tariff $96. Treatments between 34 and 96 hours receive 224, etc.
I would like to create graph with treatment hours and tariffs with the hrs on the x-axis and tariff on y-axis. In order to do that I need to create a variable that gives me the corresponding tariff for each treatment hour ('hr'). How do I do this in R?
min <- c(381, 201, 97, 34, 0)
max <- c(NA, 380, 200, 96, 33)
tariff2019 <- c(779, 536, 368, 224, 96)
dat <- data.frame(hr=seq(401))
dat$tariff <-
Related
I'm attempting to estimate survival probabilities using the survfit function from the Survival package. My dataset consists of animals that were captured at various times over the course of ~2 years. Some animals died, some animals were censored after capture and some animals lived beyond the end of the study (I'm guessing this means I have left, right and interval censored data).
I can estimate survival probability using right censors only, but this assumes all animals were captured on the same day and does not account for adding new animals through time. What I would like to do is estimate survival as a function of calendar day and not as a function of time since capture.
Example data:
time1<- c(2, 386, 0, 1, 384, 3, 61, 33, 385, 64)
time2<- c(366, 665, 285, 665, 665, 454, 279, 254, 665, 665)
censor<- c(3,3,3,3,3,3,3,3,3,3)
region <- c(1, 6, 1, 6, 5, 1, 1, 1, 5, 6)
m1<- data.frame(time1, time2, censor, region)
code:
km.2 <- survfit(Surv(m1$time1, m1$time2, m1$censor, type = "interval") ~ m1$region)
Note the above code runs but doesn't estimate what I laid out above. I hope this is an issue of specifying certain arguments in the survfit function but this is where I am lost. Thanks for the help
Not sure if you've figured this out by now since it was nearly a year ago. I'm a bit confused by the experiment you're explaining.
However, one item that pops out immediately is the "time1". I believe you can't have any times start or end at 0. I recommend adding 0.5 or 1 to that specific time observation, and explaining why in your write up. But having a 0 value is a likely culprit for why it's not estimating properly
My non-linear model is the following:
fhw <- data.frame(
time=c(10800, 10810, 10820, 10830, 10840, 10850, 10860, 10870, 10880, 10890),
water=c( 105, 103, 103, 104, 107, 109, 112, 113, 113, 112)
)
nl <- nls(formula = water ~ cbind(1,poly(time,4),sin(omega_1*time+phi_1),
sin(omega_2*time+phi_2),
sin(omega_3*time+phi_3)), data = fhw,
start = list(omega_1=(2*pi)/545, omega_2=(2*pi)/205,
omega_3=(2*pi)/85, phi_1=pi, phi_2=pi, phi_3=pi),
algorithm = "plinear", control = list(maxiter = 1000))
Time is between 10800 and 17220, but I want to predict ahead. Using the function predict like this:
predict(nl,data.frame(time=17220:17520))
gives wrong results, since the first value it returns is complete different than the last value it return when I use predict(nl). I think the problem has something to do with poly, but I'm not sure. Furthermore, predicting at one time point, gives the error: degree' must be less than number of unique points. Can anybody help?
My data consist of two columns: time and cumulative number like below:
time <- c(1:14)
cum.num <- c(20, 45, 99, 195, 301, 407, 501, 582, 679, 753, 790, 861, 1011, 1441)
My non linear function is:
c1*cos(0.6731984259*time)+c2*sin(0.6731984259*time)+c3*(time)^2+c4*time+c5
My objective is to model this function using non linear regression using nls() in R and to compute the confidence interval. I have donr the following:
m1.fit<-nls(cum.vul~c1*cos(0.6731984259*time)+c2*sin(0.6731984259*time)+c3*(time)^2+c4*time+c5,start=list(c1=-50,c2=-60,c3=5,c4=8,c5=100))
I got an error while computing confidence interval, i have tried the following:
confint(m1.fit)
Once i issued this command got the following error:
Waiting for profiling to be done...
Error in prof$getProfile() :
step factor 0.000488281 reduced below 'minFactor' of 0.000976562
Can anyone help me in this regard?
Try package nlstools:
> nlstools::confint2(m1.fit)
2.5 % 97.5 %
c1 -48.556270 54.959689
c2 -175.654079 -45.216965
c3 3.285062 9.529072
c4 -49.254627 46.007629
c5 -34.135835 272.864743`
I have basic knowledge in R, I would like to know how to write a code of an exponential function in R
F(X)=B(1-e^-AX)
where A=lambda parameter, B is a parameter represents the Y data, X represents the X data below.
I need the exponential model to generate the curve to fit the data; for example:
X <- c(22, 44, 69, 94, 119, 145, 172, 199, 227, 255)
PS: this x-axis in numbers (in millions).
Y <- c(1, 7, 8, 12, 12, 14, 14, 18, 19, 22)
This y-axis
any idea of how to write the code and fit this model in the data...?
In R you can write an exponential function with exp(), in your case:
F <- Y*(1-exp(-A*X))
In Maple I have two lists
A:=[seq(i, i=1..10)];
B:=[10, 25, 43, 63, 83, 92, 99, 101, 101, 96];
Is it possible to do polynomial or power regression in Maple?
I want to fit a trend line as a 3rd order polynomium where each point is (A[i], B[i]).
All you need is
Statistics:-LinearFit([1,x,x^2,x^3], A, B, x);