[R] help to create a simulated dataset

2020-09-29 Thread Peter Wagey
Hi R User,
I was trying to create a data matrix with four columns: height, locations
(three locations), temperature (three levels) and slope (three classes) and
used the following code, but it did not work.  I basically wanted to have
20 rows for each class (I have a total of 9 classes). Can you help me to
fix the following code so that I can create the data frame?

daT<-data.frame(height=c(5:15))

minHeight=min(daT$height)

maxHeight=max(daT$height)

height.value= minHeight +(0:20)*(maxHeight-minHeight)/20


daT<-data.frame(height=height.value, location=rep(c("SiteA", "SiteB",
"SiteC"), 20), temperature=rep(c(10,20,30)), slope=rep(c("5deg", "10deg",
"15deg")))


Thanks

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] How can we get a predicted value that are used to plot the figure using a plot_model function of sjPlot?

2020-09-19 Thread Peter Wagey
Hi R users,
I was trying to create a figure of three-way-interactions. There is a
function "plot-model" but I was wondering whether we can extract the
predicted value before we run the "plot-model" function.
For example:
in this example,
plot_model(fit, type = "pred", terms = c("c12hour", "barthtot [30,50,70]",
"c161sex"))
How can we see the predicted values that are used to plot the figure? If we
can see the data (predicted values), we could use other functions to create
another type of figures.
Thank you very much for your suggestions.

Thanks,

Peter
#
library(sjPlot)
library(sjmisc)
library(ggplot2)
data(efc)
theme_set(theme_sjplot())

# make categorical
efc$c161sex <- to_factor(efc$c161sex)

# fit model with 3-way-interaction
fit <- lm(neg_c_7 ~ c12hour * barthtot * c161sex, data = efc)

# select only levels 30, 50 and 70 from continuous variable Barthel-Index
plot_model(fit, type = "pred", terms = c("c12hour", "barthtot [30,50,70]",
"c161sex"))

How can we get the predicted value that is used to plot the graph? we would
like to see the predicted value using three groups of barthtot
[30,50,70].Is there any way we can extract the data (predicted value) so
that we can use other graphic functions to create figures?

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] bootstrapping results in table format

2017-10-07 Thread Peter Wagey
Hi R users,
I was struggling to put the results into table format. Would you mind to
show using following data and code how we can put the results into table? I
further would like to have a  confidence interval for each group.


set.seed(1000)
data <- as.data.table(list(x1 = runif(200), x2 = runif(200), group =
runif(200)>0.5))
data.frame(data)
head(data)
stat <- function(x, i) {x[i, c(m1 = mean(x1))]}
A<-data[, list(list(boot(.SD, stat, R = 10))), by = group]$V1

Thanks

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.