Added randdir
This commit is contained in:
parent
9553105363
commit
c508e49edb
4 changed files with 42 additions and 13 deletions
|
|
@ -5,6 +5,6 @@ export(calculatePopLogml)
|
|||
export(computeRows)
|
||||
export(learn_simple_partition)
|
||||
export(ownNum2Str)
|
||||
export(randga)
|
||||
export(randdir)
|
||||
export(repmat)
|
||||
importFrom(stats,runif)
|
||||
|
|
|
|||
11
R/admix1.R
11
R/admix1.R
|
|
@ -694,14 +694,3 @@ admix1 <- function(tietue) {
|
|||
# str = ['0.' num2str(prob)];
|
||||
# end;
|
||||
# end;
|
||||
|
||||
# %-------------------------------------------------
|
||||
|
||||
# function svar=randdir(counts,nc)
|
||||
# % Käyttöesim randdir([10;30;60],3)
|
||||
|
||||
# svar=zeros(nc,1);
|
||||
# for i=1:nc
|
||||
# svar(i,1)=randga(counts(i,1),1);
|
||||
# end
|
||||
# svar=svar/sum(svar);
|
||||
15
R/randdir.R
Normal file
15
R/randdir.R
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#' @title Generates random numbers
|
||||
#' @return vector of length `nc` with r.v. realizations from Gamma(rate=1)
|
||||
#' @examples randdir(matrix(c(10, 30, 60), 3), 3)
|
||||
#' @param counts shape parameter
|
||||
#' @param nc number of rows on output
|
||||
#' @seealso randga
|
||||
#' @export
|
||||
randdir <- function (counts, nc) {
|
||||
svar <- zeros(nc, 1)
|
||||
for (i in 1:nc) {
|
||||
svar[i, 1] = randga(counts[i, 1], 1)
|
||||
}
|
||||
svar <- svar / sum(svar)
|
||||
return(svar)
|
||||
}
|
||||
25
man/randdir.Rd
Normal file
25
man/randdir.Rd
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/randdir.R
|
||||
\name{randdir}
|
||||
\alias{randdir}
|
||||
\title{Generates random numbers}
|
||||
\usage{
|
||||
randdir(counts, nc)
|
||||
}
|
||||
\arguments{
|
||||
\item{counts}{shape parameter}
|
||||
|
||||
\item{nc}{number of rows on output}
|
||||
}
|
||||
\value{
|
||||
vector of length `nc` with r.v. realizations from Gamma(rate=1)
|
||||
}
|
||||
\description{
|
||||
Generates random numbers
|
||||
}
|
||||
\examples{
|
||||
randdir(matrix(c(10, 30, 60), 3), 3)
|
||||
}
|
||||
\seealso{
|
||||
randga
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue