Skip to content

Commit

Permalink
Reset width
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinKipruto committed Nov 13, 2023
1 parent c2b418e commit 6d77185
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions vignettes/mfp2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ knitr::opts_chunk$set(
tidy = TRUE,
fig.pos = "h"
)
oldwidth <- options()$width
options(width = 100)
knitr::opts_chunk$set(tidy.opts=list(width.cutoff=75))
Expand Down Expand Up @@ -174,15 +175,15 @@ funx <- function(x, power){
}
s <- c(-2, -1, -0.5, 0, 0.5, 1, 2, 3)
# transform x using the powers in s
outx = lapply(s, function(s) funx(x = x, power = s))
outx <- lapply(s, function(s) funx(x = x, power = s))
# multiply the first 3 with -1 so that the function increase rather than decrease
# due to negative powers. these are betas i,e y = beta*x^p
k <- c(-1, -1, -1, 1, 1, 1, 1, 1)
datx = matrix(unlist(outx), ncol = length(s))
datax = datx %*% diag(k)
datx <- matrix(unlist(outx), ncol = length(s))
datax <- datx %*% diag(k)
# standardize the data so that y is in the same range
dataxx = apply(datax, 2, function(x) (x - min(x)) / (max(x) - min(x)))
dataxx <- apply(datax, 2, function(x) (x - min(x)) / (max(x) - min(x)))
colnames(dataxx) <- c(paste0("x", 1:length(s)))
dataxx <- as.data.frame(dataxx)
dataxx$x <- x
Expand Down Expand Up @@ -224,7 +225,7 @@ f6 <- function(x) 33 + 19*log(x) - 7*(x^2)
f7 <- function(x) -10 + 10*(x - 1.5) + 10*(x - 1.5)^2
# Create data frames for each function
x = seq(0.1, 3, by = 0.01)
x <- seq(0.1, 3, by = 0.01)
df1 <- data.frame(x = x, y = f1(x))
df2 <- data.frame(x = x, y = f2(x))
df3 <- data.frame(x = x, y = f3(x))
Expand Down Expand Up @@ -1630,8 +1631,8 @@ approach provides a better fit to the data compared to the usual MFP model.


```{r,echo=FALSE,eval=TRUE}
p1 = fracplot(fit1, terms = "x")[[1]] + ggplot2::ylab("y")
p2 = fracplot(fit3, terms = "x")[[1]] + ggplot2::ylab("y")
p1 <- fracplot(fit1, terms = "x")[[1]] + ggplot2::ylab("y")
p2 <- fracplot(fit3, terms = "x")[[1]] + ggplot2::ylab("y")
figurex <- patchwork::wrap_plots(p1, p2,
ncol = 2, nrow = 1,
widths = 8, heights = 2)
Expand Down Expand Up @@ -1714,7 +1715,10 @@ figurex

* Therneau, T.M., Grambsch, P.M., Therneau, T.M. and Grambsch, P.M., (2000). The cox model (pp. 39-77). Springer New York.


```{r, eval=TRUE, echo=FALSE}
# reset width to the original value
options(width=oldwidth)
```



Expand Down

0 comments on commit 6d77185

Please sign in to comment.