Dear Wiza[R]ds,

I am very grateful to Duncan Murdoch for his assistance with this problem.
His help was invaluable. However, the problem has become a little more
complicated for me. Now, in each plot, I need to plot the observed and
fitted values of a supine and upright posture experiment. Here is what I
have and how far I got.

# tritiated (3H)-Norepinephrine(NE) disappearance from plasma
# concentrations supine and upright
# supine
datasu <- data.frame(
time=c(0,1,2,4,6,8,10,15,20),
concsu=c(385.61,265.88,173.87,99.47,66.7,55.27,48.29,39.85,40.66)
)
# upright
dataup <- data.frame(
time=c(0,1,2,4,6,8,10,15,20),
concup=c(767.27,529.03,328.13,225.94,164,151.1,132.02,121.15,70.88)
)

# fit supine
wt.su<- function(resp, time,A1,a1,A2,a2)
{
    pred <- A1*exp(-a1*time)+A2*exp(-a2*time)
    (resp - pred) / sqrt(pred)
}

fit.wt.su <- nls( ~ wt.su(concsu, time,A1,a1,A2,a2), data=datasu,
              start=list(A1=500,a1=1,A2=100,a2=0.2),
              trace = TRUE)

summary(fit.wt.su)

# fit upright
wt.up<- function(resp, time,B1,b1,B2,b2)
{
    pred <- B1*exp(-b1*time)+B2*exp(-b2*time)
    (resp - pred) / sqrt(pred)
}

fit.wt.up <- nls( ~ wt.up(concup, time,B1,b1,B2,b2), data=dataup,
              start=list(B1=500,b1=1,B2=100,b2=0.1),
              trace = TRUE)

summary(fit.wt.up)

# Function that returns predicted values and graphics
# by Duncan Murdoch

predictionssu <- function(fit, time) {
  params <- summary(fit)$coefficients[, 1]
  A1 <- params["A1"]
  a1 <- params["a1"]
  A2 <- params["A2"]
  a2 <- params["a2"]

  A1*exp(-a1*time)+A2*exp(-a2*time)
}

predictionsup <- function(fit, time) {
  params <- summary(fit)$coefficients[, 1]
  B1 <- params["B1"]
  b1 <- params["b1"]
  B2 <- params["B2"]
  b2 <- params["b2"]

  B1*exp(-b1*time)+B2*exp(-b2*time)
}

# plot observed and predicted values supine and upright in
# each plot type (linear and smi-log)

# this does supine
times <- seq(0,20, len=100)
par(mfrow=c(2,1))
plot(concsu ~ time, data=datasu)
lines(times, predictionssu(fit.wt.su, times))
plot(concsu ~ time, data=datasu, log="y")
lines(times, predictionssu(fit.wt.su, times))

# Need upright in same plots (e.g., dashed line)


Many thanks in advance...
-- 
Oscar
Oscar A. Linares, MD
Translational Medicine Unit
LaPlaisance Bay, Bolles Harbor
Monroe, Michigan 48161

Department of Medicine,
University of Toledo College of Medicine
Toledo, OH 43606-3390

Department of Internal Medicine,
The Detroit Medical Center (DMC)
Harper University Hospital
Wayne State University School of Medicine
Detroit, Michigan 48201

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to