Displaying 20 results from an estimated 45 matches for "nsampl".
Did you mean:
nsamp
2011 May 16
1
Matrix manipulation in for loop
Hi all,
I have a problem with getting my code to do what I want!
This is the code I have:
create.means.one.size<-function(nsample,var,nboot){
mat.x<-matrix(0,nrow=nboot,ncol=nsample)
for(i in 1:nboot){
mat.x[i,]<-sample(var,nsample,replace=T)
}
mean.mat<-rep(0,nboot)
for(i in 1:nboot){
mean.mat[i]<-mean(mat.x[i,])
}
sd.mean<-sd(mean.mat)
return(mean.mat)
}
where nsample here is a scalar.
Then this is w...
2008 Oct 22
2
Help with functions
Hi there,
I have a the following function which takes a name(fname), total number of
rows (Total), number of times to make a sample(nSample), number of
records/rows to be included in each sample(nPatient). then it generates
required samples and calculates the mean and standard deviation of the
columns for each sample and finally in calculates the grand mean and
standard deviation.
The problem is if I run each line of the code separa...
2004 Oct 29
1
fitting linear mixed model for incomplete block design
Dear R developers and users:
I have the following data, x is the response vaiable, nsample(individual) nested within trt, and subsample nested within nsample, I want to fit trt as fixed effect, and block, nsample(trt) as random effects using lme, is the following coding correct?
dat$vgrp <- getGroups(dat, form = ~ 1|trt/nsample, level = 2)
ge.lme1 <- lme(fixed=x~trt, data=dat, r...
2016 Apr 22
0
R2BayesX help
...When the number
of interaction terms exceed 20, the code stops working. Here is a piece of
toy code.
rm(list=ls())
library(BayesX)
library(R2BayesX)
#data generating model
f2<-function(x1,x2,x3,x4)
{
y<-2*sin(pi*x1)*1.5+exp(2*x2)/3+2 * sin(4 * pi * (x3 - 0.2) *(x4 - 0.7))
}
#the dataset
nsample<-40 #sample size
x1.tot<-runif(nsample,0,1)
x2.tot<-runif(nsample,0,1)
x3.tot<-runif(nsample,0,1)
x4.tot<-runif(nsample,0,1)
x5.tot<-runif(nsample,0,1)
x6.tot<-runif(nsample,0,1)
x7.tot<-runif(nsample,0,1)
pnoise<-0.2
eta<-f2(x1.tot,x2.tot,x3.tot,x4.tot)
y.tot<-e...
2012 Mar 16
2
Elegant Code
Hi,
Can anyone help to write a more elegant version of my code? I am sure
this can be put into a loop but I am having trouble creating the
objects b1,b2,b3,...,etc.
b1 <- rigamma(50,1,1)
theta1 <- rgamma(50,0.5,(1/b1))
sim1 <- rpois(50,theta1)
b2 <- rigamma(50,1,1)
theta2 <- rgamma(50,0.5,(1/b2))
sim2 <- rpois(50,theta2)
b3 <- rigamma(50,1,1)
theta3 <-
2009 May 21
1
Need help on ploting Histograms
this is the command i made for a normal distribution, but when i try to plot
the histograms, i dont know why the bars don't stick on the line...
nsamples<-1000
sampsize<-15
Samples<-matrix(rnorm(nsamples*sampsize,0,1),nrow=nsamples)
a<-apply(Samples,1,var)
NC14<-a*14
x<-0:40
plot(x,dchisq(x,14),type='h')
hist(NC14,freq=F,add=T)
--
View this message in context: http://www.nabble.com/Need-help-on-ploting-Histograms-tp236...
1997 Oct 28
1
R-beta: Assigning column names in a data frame
...cause the QR
decomposition of the model matrix is stored with the fitted model.
So far, so good. Then I got fancy and returned the result as a
data frame.
"bsCoefSample" <-
## Construct a bootstrap sample of coefficients from a
## fitted regression model
function(fittedModel, Nsampl)
{
value <-
as.data.frame(t(coef(fittedModel) +
qr.coef(fittedModel$qr,
matrix(sample(resid(fittedModel),
length(resid(fittedModel)) * Nsampl,
repl = T),
ncol = Nsampl))))
names(value) <- names(coef(fittedModel))
value
}
Later I thought I could cut...
1997 Oct 17
1
R-beta: more model.matrix
...ably effective ways of doing the resampling.
The following is a function I wrote to create bootstrap samples of
coefficients from a fitted linear regression model.
bsCoefSample <-
## Construct a bootstrap sample of coefficients from a
## fitted regression model
function(fittedModel, Nsampl, ...)
{
coef(fittedModel) +
qr.coef(qr(model.matrix(fittedModel)),
matrix(sample(resid(fittedModel),
length(resid(fittedModel)) * Nsampl,
repl = T),
ncol = Nsampl))
}
It works ok with S-PLUS but the R version of model.matrix encounters
difficulties.
R> fm1 &...
2011 Feb 03
1
problem with parLapply from snow
...emoteErrors(val) :
2 nodes produced errors; first error: no applicable method for 'lapply' applied to an object of class "list"
".
Where this is the problem line of code "yusum <- parLapply(cl, yu, sum)"
The function is
CallSnow <- function (Nnodes = 2, Nsamples = Nnodes)
{
require(Rmpi)
require(snow)
cat("Using snow package, asking for ", Nnodes, "nodes \n")
cl <- makeCluster(Nnodes, type="MPI")
on.exit(stopCluster(cl))
#print(do.call("rbind", clusterCall(cl, function(cl) Sys.info()["nodename"...
2012 Nov 24
6
IMPORTANT!!!! PLEASE HELP ME
Hi,
I want to generate 10000 samples from normal distribution with replacement
case and every sample size is 50. What should I do ?
--
View this message in context: http://r.789695.n4.nabble.com/IMPORTANT-PLEASE-HELP-ME-tp4650676.html
Sent from the R help mailing list archive at Nabble.com.
2007 Jan 22
0
Recursive-SVM (R-SVM)
...ursive elimination of least important genes
### author: Dr. Xin Lu, Research Scientist
### Biostatistics Department, Harvard School of Public Health
library(e1071)
## read in SVM formated data in filename
## the format following the defination of SVMTorch
## the first line contains 2 integer: nSample nFeature+1
## followed by a matrix, each row for one sample, with the last column being +/1 1 for class label
ReadSVMdata <- function(filename)
{
dd <- read.table( filename, header=F, skip=1)
x <- as.matrix( dd[, 1:(ncol(dd)-1)] )
y <- factor( dd[, ncol(dd)] )
ret <- list(x...
2009 May 13
2
Problems with randomly generating samples
Dear R users,
Can anyone please tell me how to generate a large number of samples in R, given certain distribution and size.
For example, if I want to generate 1000 samples of size n=100, with a N(0,1) distribution, how should I proceed?
(Since I dont want to do "rnorm(100,0,1)" in R for 1000 times)
Thanks for help
Debbie
2007 Dec 19
0
leaps
...ning or may I run "regsubsets" on the original model
bringing in all possible frequencies (88 in all as sums of sinuoids) ?
Thank you so much.
Kind regards,
Maura
********************************************************************
T <- xx$timestamp[end] - xx$timestamp[start]
nsamples <- end +1 - start
nfr <- ceiling(nsamples/2)
yy <- xx[start:end,"amplitude"]
tt <- xx[start:end,"timestamp"]
cosmat <- matrix(nrow=nsamples,ncol=nfr)
coscol <- NULL
sinmat <- matrix(nrow=nsamples,ncol=nfr)
sincol <- NULL
for(i in...
2008 Oct 23
3
Fuctions help!
Hi everyone,
I have a question about functions. I have two functions:
Sampling=function(fname,Total,nSample,nPatient){......return(list(Gmean,Gsd))}
Power=function(alfa,m1,m2,s1,s2,n1,n2){....return(powe)}
I want to use "Gmean" and "Gsd" which are the returned values from
"Sampling" function, in "Power" function.
i.e. when I call "power" I want to be a...
2001 Jul 24
0
bug in residuals.rpart?
...[[3]]
[1] "residuals.rpart(tr, \"deviance\")"
[[4]]
[1] "residuals(tr, \"deviance\")"
The problem is that tr$frame does not contain a field called 'yprob'.
I created the dat matrix above as follows
set.seed(123)
Nvars <- 4;
Nsamples <- 1000;
N <- Nvars*Nsamples;
dat <- matrix(sample(1:2, N, c(0.5,0.5), replace=TRUE), Nsamples, Nvars)
#dat <- sample.bnet(bnet, 30)
dat <- as.data.frame(dat)
for (i in 1:Nvars) {
dat[,i]<- factor(dat[,i], 1:2)
}
names(dat) <- c(paste("X", 1:3, sep=""),...
2009 Feb 24
0
any help with pyogg and pyvorbis?
...hannels()
vd = ogg.vorbis.VorbisInfo(channels = channels,
rate = inwav.getframerate(),
quality = 0.2).analysis_init()
os = ogg.OggStreamState(5)
map(os.packetin, vd.headerout())
og = os.flush()
while og:
og.writeout(fout)
og = os.flush()
nsamples = 1024
eos = 0
total = 0
while not eos:
data = inwav.readframes(nsamples)
total = total + nsamples
if not data:
vd.write(None)
break
vd.write_wav(data)
#print 100.0 * total / inwav.getnframes()
vb = vd.blockout()
while vb:
vb.analysis()...
2001 Jul 20
1
frames and formulas
...3)
CPD$tr <- tree(V4 ~ ., fam.vals)
else
stop(paste("too many parents for tree CPD", CPD$id))
end
list(CPD = CPD, dev = deviance(CPD$tr), score = dev)
}
Thanks for your help!
Kevin
P.S. You can reproduce the above problem using the following script
Nvars <- 4;
Nsamples <- 10;
N <- Nvars*Nsamples;
dat <- matrix(sample(1:2, N, c(0.5,0.5), replace=TRUE), Nsamples, Nvars)
#dat <- sample.bnet(bnet, 10)
dat <- as.data.frame(dat)
for (i in 1:Nvars) {
dat[,i]<- factor(dat[,i], 1:2)
}
tr <- tree(V4 ~ ., dat)
#deviance(tr)
foo <- function(dumm...
2010 Nov 15
5
Sampling problem
Hey,
I am hoping someone can help me with a sampling question.
I have a data frame of 8 variables (the first column is the subjects' id):
SubID CSE1 CSE2 CSE3 CSE4 WSE1 WSE2 WSE3 WSE4
1 6 5 6 2 6 2 2 4
2 6 4 7 2 6 6 2 3
3 5 5 5 5 5 5
2024 Aug 11
1
Printing
...??? "\nCovariance matrix:",vb.method,
??? "\nWeighted =",??????? weighted,
??? "\nAt means =",??????? mean,
??? "\nProb x 100 =",????? times100,
??? "\ntesting ="????? ,?? testing,
??? "\nuse_bb_and_vbb = ",use_bb_and_vbb,
??? "\nsample size =",???? length(y1),"\n")
if (!resampling) cat("\nSEs by delta method","\n")
if? (resampling) cat("\nSEs K-R resampling with",ndraws,"draws\n")
return(out)
} else {
invisible(list("ei"=ap,"vi"=vap))
2012 Aug 01
3
repeating a function across a data frame
Hello everyone. Like others on this list, I'm new to R, and really not much
of a programmer, so please excuse any obtuse questions! I'm trying to
repeat a function across all possible combinations of vectors in a data
frame. I'd hugely appreciate any advice!
Here's what I'm doing:
I have some data: 40 samples, ~460 000 different readings between 1 and 0
for each sample. I