Description Usage Arguments Value Examples
View source: R/gen_response_surface_y.R
gen_response_surf_y: Generate DV under response surface model
1 | gen_response_surf_y(x_data, beta, sigma = NULL, y_name = NULL)
|
x_data |
IV data typically generated by gen_response_surf_x() |
beta |
Vector of regression weights in the order of x_data. If generated by gen_response_surf_x(), this order is X1, X2, X1^2, X2^2, X1*X2. |
sigma |
Error variance of outcome variable (optional). If NULL taken to be 0. |
y_name |
name of y variable (optional). |
data frame with x and y variables given simulation parameters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # Importing for magrittr pipe (%>%)
library(tidyverse)
# Defining Correlation Matrix describing how x1 and x2 are related
# Covarince and variance of x1^2, x2^2, and x1*x2 follow from this matrix
cov_mat<-matrix(c(1, 0,
0, 1), byrow = TRUE, 2, 2)
# Defining betas x1, x2, x1^2, x2^2, and x1*x2
beta<-c(0, 0, -.075, -.075, .15)
# Simulating 10,000 draws of size 1000 assuming the correlation structure and regression weights defined above.
sig_hat <- find_sig(n = 1000, cov_mat = cov_mat, beta = beta, target_var_y = 1)
# Generating data frame for response suface examining leaders and follower agreeableness
simmed_df<-gen_response_surf_x(1000, cov_mat, x_names = c("L_Agree", "F_Agree"))%>%
gen_response_surf_y(beta = beta, sigma = sig_hat, y_name = "Satisfaction")
head(simmed_df)
# Variance of simmed_df approximates target_var_y (defined in find_sig above)
# Population level variance will be even closer
var(simmed_df$Satisfaction)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.