Skip to content

Commit dad8556

Browse files
committed
add documentation for generate.eive.data
1 parent 38c2830 commit dad8556

File tree

4 files changed

+72
-29
lines changed

4 files changed

+72
-29
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ importFrom(compiler, cmpfun)
77
export(eive.cga, eivem, cga)
88
export(eive.cga.formula)
99
export(cga_generate_chromosome)
10+
export(generate.eive.data)
1011

1112

R/eive.R

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
library(compiler)
22

3-
# Generates one or two exploratory variables linear model
4-
# with first one is subject to error
3+
#' Generates simulated errors-in-variables regression data
4+
#'
5+
#' @param n Number of observations
6+
#' @param e.sd Standard deviation of error term of regression
7+
#' @param delta.sd Standard deviation of error in exploratory variable
8+
#' @param seed Seed for random number generator. 12345 by default
9+
#' @param useotherx Logical. If TRUE, an additional independent variable is added.
10+
#' @return A matrix of variables.
11+
#' @slot xdelta Errorenous X variable
12+
#' @slot otherx Other X variable
13+
#' @slot y Response variable
14+
#' @export
515
generate.eive.data <- function(n,
616
e.sd,
717
delta.sd,
@@ -12,6 +22,7 @@ generate.eive.data <- function(n,
1222
x <- rnorm(n)
1323
x1 <- NULL
1424
y <- NULL
25+
data <- NULL
1526
if (useotherx) {
1627
x1 <- rnorm(n)
1728
}
@@ -22,7 +33,18 @@ generate.eive.data <- function(n,
2233
} else {
2334
y <- 5 + 5 * x + e
2435
}
25-
data <- cbind(xdelta, x1, y)
36+
if (useotherx) {
37+
data <- data.frame(
38+
xdelta = xdelta,
39+
xother = x1,
40+
y = y
41+
)
42+
}else{
43+
data <- data.frame(
44+
xdelta = xdelta,
45+
y = y
46+
)
47+
}
2648
return(data)
2749
}
2850

man/generate.eive.data.Rd

Lines changed: 23 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
library(testthat)
2+
library(eive)
3+
4+
test_that("eive.cga classical example", {
5+
6+
require("eive")
7+
8+
testdata <- generate.eive.data(
9+
n = 100,
10+
e.sd = 1,
11+
delta.sd = 1,
12+
seed = 12345,
13+
useotherx = TRUE
14+
)
15+
16+
expect_equal(dim(testdata), c(100, 3))
17+
expect_true(
18+
all.equal(
19+
names(testdata),
20+
c("xdelta", "xother", "y")
21+
)
22+
)
23+
})

0 commit comments

Comments
 (0)