Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteda27be

Browse files
committed
Added rterm() and shuffle()
1 parent1d876aa commiteda27be

File tree

7 files changed

+73
-1
lines changed

7 files changed

+73
-1
lines changed

‎DESCRIPTION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: LSTbook
22
Title: Data and Software for "Lessons in Statistical Thinking"
3-
Version: 0.6.1.9003
3+
Version: 0.6.1.9004
44
Authors@R: c(
55
person(given = "Daniel", family = "Kaplan", email = "dtkaplan@gmail.com", role = c("aut", "cre")),
66
person(given = "Randall", family = "Pruim", email = "rpruim@calvin.edu", role = "aut") )

‎NAMESPACE‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export(random_levels)
3535
export(random_terms)
3636
export(regression_summary)
3737
export(resample)
38+
export(rterm)
39+
export(shuffle)
3840
export(take_sample)
3941
export(trials)
4042
export(zero_one)

‎NEWS.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ won't work in WebR installations.
5151

5252
* Ungrouped Sessions in College_database.rda and removed redundant College_grades.rda
5353

54+
* Added simple`shuffle()` function.
55+
56+
* Added`rterm()` for demonstrations of degrees of freedom.
5457

5558

‎R/rterm.R‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#' Generate a random term in a model.
2+
#'
3+
#' For demonstration purposes, create a model term with
4+
#' `df` degrees of freedom consisting of `df` random vectors.
5+
#'
6+
#' @param df Degrees of freedom of the term: positive integer
7+
#' @param seed An (optional) seed for the random number generator: integer
8+
#' @param rdist The random number generator to use. Default `rdist`.
9+
#' @param args A list of parameters for the function named in `rdist`.
10+
#' @param nrow number of rows in the model term. This is determined automatically
11+
#' when used in a function like `lm()` or `model_train()`.
12+
#'
13+
#' @examples
14+
#' lm(mpg ~ hp + rterm(df=25, seed=29323), data = mtcars) |> R2()
15+
#'
16+
#' @export
17+
rterm<-function (df=1,rdist=rnorm,args=list(),nrow,seed=NULL)
18+
{
19+
if (missing(nrow)) {
20+
nrow<- length(get(ls(envir= parent.frame())[1],envir= parent.frame()))
21+
}
22+
if (!is.null(seed)) {
23+
set.seed(seed)
24+
}
25+
result<-matrix(do.call(rdist,args= c(list(n=df*nrow),
26+
args)),nrow=nrow)
27+
return(result)
28+
}

‎R/take_sample.R‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ take_sample.default <- function(x, n = length(x), replace=FALSE, prob=NULL, .by
102102
resample<-function(...,replace=TRUE) {
103103
take_sample(...,replace=replace)
104104
}
105+
106+
#' A convenience function for shuffling, typically used with
107+
#' within model_train(), but available elsewhere for, e.g. demonstrations
108+
#' @rdname take_sample
109+
#' @export
110+
shuffle<-function(...) {
111+
take_sample(...)
112+
}

‎man/rterm.Rd‎

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎man/take_sample.Rd‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp