search for: npts

Displaying 20 results from an estimated 20 matches for "npts".

Did you mean: nptl
2010 Oct 11
1
MATLAB vrs. R
...earch-related project. I was able to find the area under the trapezoid in MATLAB using the code: function [int] = myquadrature(f,a,b) % user-defined quadrature function % integrate data f from x=a to x=b assuming f is equally spaced over the interval % use type % determine number of data points npts = prod(size(f)); nint = npts -1; %number of intervals if(npts <=1) error('need at least two points to integrate') end; % set the grid spacing if(b <=a) error('something wrong with the interval, b should be greater than a') else dx = b/real(nint); end; npts = prod(size(f)...
2013 Jan 26
2
confidence / prediction ellipse
Hi, I'm using the R library(car) to draw confidence/prediction ellipses in a scatterplot. >From what i understood the ellipse() function return an ellipse based parameters: shape, center, radius . If i read dataEllipse() function i can see how these parameters are calculated for a confidence ellipse. ibrary(car) a=c(12,12,4,5,63,63,23) b=c(13,15,7,10,73,83,43) v <-
2005 Jan 12
4
Finding seasonal peaks in a time series....
I have a seasonal time series. I want to calculate the annual mean value of the time series at its peak (say the mean of the three values before the peak, the peak, and the three values after the peak). The peak of the time series might change cycle slightly from year to year. # E.g., nPts <- 254 foo <- sin((2 * pi * 1/24) * 1:nPts) foo <- foo + rnorm(nPts, 0, 0.05) bar <- ts(foo, start = c(1980,3), frequency = 24) plot(bar) start(bar) end(bar) # I want to find the peak value from each year, and then get the mean of the values on either side. # So, if the peak value in t...
2006 Jan 08
1
confint/nls
...Ben Bolker code that tests various combinations of numbers of parameters and algorithms: ----------- resmat = array(dim=c(3,2,3), dimnames=list(npar=1:3,c("fit","confint"),c("default","plinear","port"))) resmat.fix <- resmat ## sim. values npts=1000 set.seed(1001) x = runif(npts) b = 0.7 y = x^b+rnorm(npts,sd=0.05) a =0.5 y2 = a*x^b+rnorm(npts,sd=0.05) c = 1.0 y3 = a*(x+c)^b+rnorm(npts,sd=0.05) d = 0.5 y4 = a*(x^d+c)^b+rnorm(npts,sd=0.05) testfit <- function(model,start,alg) { tryfit <- try(fit <- nls(model,start=start,algor...
2006 Jan 23
1
too-large notches in boxplot (PR #7690)
PR #7690 points out that if the confidence intervals (+/-1.58 IQR/sqrt(n)) in a boxplot with notch=TRUE are larger than the hinges -- which is most likely to happen for small n and asymmetric distributions -- the resulting plot is ugly, e.g.: set.seed(1001) npts <- 5 X <- rnorm(2*npts,rep(3:4,each=npts),sd=1) f <- factor(rep(1:2,each=npts)) boxplot(X~f) boxplot(X~f,notch=TRUE) I can imagine debate about what should be done in this case -- you could just say "don't do that", since the notches are based on an asymptotic argument .....
2005 Jun 25
2
optimization problem in R ... can this be done?
Im trying to ascertain whether or not the facilities of R are sufficient for solving an optimization problem I've come accross. Because of my limited experience with R, I would greatly appreciate some feedback from more frequent users. The problem can be delineated as such: A utility function, we shall call g is a function of x, n ... g(x,n). g has the properties: n > 0, x lies on the
2006 Jan 19
1
nls profiling with algorithm="port" may violate bounds (PR#8508)
...defining my function with some workarounds to make the fit quadratically "bad" (but well-defined) when the parameters are negative ... As always, please don't hesitate to correct me if I'm being an idiot ... cheers Ben Bolker ----------------------- rm(list=ls()) npts=10 set.seed(1001) a =2 b =0.5 x= runif(npts) y = a*x/(1+a*b*x)+rnorm(npts,sd=0.2) gfun <- function(a,b,x) { if (a<0 || b<0) stop("bounds violated") a*x/(1+a*b*x) } m1 = nls(y~gfun(a,b,x),algorithm="port", lower=c(0,0),start=c(a=1,b=1)) try(confint(m1)) -...
2010 Oct 08
1
Trapezoid Rule
...the sum code for the trapezoid rule to estimate the area under the curve: Here is the code provided: myquadrature = function(f,a,b) { # user-defined quadrature function # integrate data f from x=a to x=b assuming f is equally spaced over the interval # use type # determine number of data points npts = length(f) nint = npts -1 #number of intervals if(npts <=1) error('need at least two points to integrate') end; # set the grid spacing if(b <=a) error('something wrong with the interval, b should be greater than a') else dx = b/real(nint) end; # trapezoidal rule #...
2001 Feb 28
2
Automating the job?
Hi! I just started to use R recently, and would like to ask a help about automating the job. I need to use "kmeans" function with my own 300 data files, and wonder if it's possible to do it automatically. For example, > library (mva) > mydata <- read.table ("data1") > cl <- kmeans(mydata, 5, 20) and I just need to save "cl" info (i.e. the center
2006 Oct 05
1
unexpected behavior of boxplot(x, notch=TRUE, log="y")
A function I've been using for a while returned a surprising [to me, given the data] error recently: Error in plot.window(xlim, ylim, log, asp, ...) : Logarithmic axis must have positive limits After some digging I realized what was going on: x <- c(10460.97, 10808.67, 29499.98, 1, 35818.62, 48535.59, 1, 1, 42512.1, 1627.39, 1, 7571.06, 21479.69, 25, 1, 16143.85, 12736.96,
2012 Feb 13
1
comment lines sometimes removed from a function on exit from internal R editor
...h previous versions of R. Any suggestions on how to preserve the comment lines would be greatly appreciated. Many apologies if this is a stupid question. Cleridy ## this function has comments at the top: > mapsp.sqrtcpd.f function (input.frm, cpd.numerator, cpd.denominator, basis.dim, npts, nyrs.unq, prop.ctch) { # here are some comments # and more # year.min<- 1975 ...... ## copy function to a dummy function: > tmp.f<-mapsp.sqrtcpd.f ## now edit it with fix and remove a ) so that it complains: > fix(tmp.f) Error in edit(name, file, title, editor) :...
2006 Oct 09
1
boxplot, notches, etc.
...ment ... the diff below just truncates > the notches to the hinges, but produces a warning saying that the > notches have been truncated. The interaction with log="y" is new to me, though, and my old patch didn't catch it. Here's my reproducible version: set.seed(1001) npts <- 7 X <- rnorm(2*npts,rep(c(3,4.5),each=npts),sd=1) f <- factor(rep(1:2,each=npts)) par(mfrow=c(1,2)) boxplot(X~f,notch=TRUE) A possible fix is to truncate the notches (and issue a warning) when this happens, in src/library/grDevices/R/calc.R: [WATCH OUT FOR LINE WRAPPING BELOW!] ***...
2006 Jan 17
0
nls profile with port/constraints
...redefining my function with some workarounds to make the fit quadratically "bad" (but well-defined) when the parameters are negative ... As always, please don't hesitate to correct me if I'm being an idiot ... cheers Ben Bolker ----------------------- rm(list=ls()) npts=10 set.seed(1001) a =2 b =0.5 x= runif(npts) y = a*x/(1+a*b*x)+rnorm(npts,sd=0.2) gfun <- function(a,b,x) { if (a<0 || b<0) stop("bounds violated") a*x/(1+a*b*x) } m1 = nls(y~gfun(a,b,x),algorithm="port", lower=c(0,0),start=c(a=1,b=1)) try(confint(m1)) ----...
2011 Jul 13
3
Colors in R
...ting the logratio for up to 60 samples and want a different color for each sample. Here is the code I''m using now.. Any help is greatly appreciated.. Best LT data <- read.table("data.csv", header=T, sep=",", stringsAsFactors= F) data$Pt <-as.numeric(data$Pt) npts <- unique(data$Pt) xrange = c(min(data$Coordinate), max(data$Coordinate)) yrange = c(min(data$Log2Ratio), max(data$Log2Ratio)) colors <-c("red","blue","green","darkmagenta","darkgreen","darkorange","darkred","gold...
2002 Apr 26
4
Memory "leak" in readChar (PR#1483)
Full_Name: Hugh C. Pumphrey Version: 1.4.1 OS: Linux (Debian Woody) Submission from: (NULL) (129.215.133.170) The function readChar() appears to have some type of problem with memory allocation. I don't know if "memory leak" is the correct term but if one uses readChar() many times, the R binary grows in size until it eats all your memory and swap space. The code enclosed below
2009 Jan 20
2
plotting points with two colors
Dear Miss R, I am trying to plot a scatterplot in which the points (round) should have two colors: half red and half blue (if you want: two half solid circles put together. Can you please help me to realize this efficiently? Thank you, Best regards, Georg. *************************************** Georg Ehret Geneva University Hospital Geneva, Switzerland [[alternative HTML version deleted]]
2007 Jun 24
2
matlab/gauss code in R
...t; > The following code creates a dummy dataset which has the same similar as > my usual datasets. I did not try to implement the changes proposed by > Hadley, hoping that a solution can be found using the original dataset. > > ######### My code > > # Creating dataset > > nPts<-10 # number of time points > nInd<-6 # number of individuals > nModel<-3 # number of models > > TimePts<-rep(1:nPts,nInd*nModel) # > creates the "Time" column > Coef<-rep(rnorm(6,0.1,0.01)...
2007 Aug 30
3
piecewise linear approximation
Dear list, I have a series of data points which I want to approximate with exactly two linear functions. I would like to choose the intervals so that the total deviation from my fitted lines is minimal. How do I best do this? Thanks! Kamila The information transmitted in this electronic communication...{{dropped}}
2002 Dec 29
3
lowess + turnpoints = doubling integers?
Happy New Year, r-helpers! I am using lowess to smooth a scatter plot, xx<-lowess(xinput,f=.04) #defaults for other args followed by turnpoints(xx$y) #defaults for other args I plot the smoothed result as well as turnpoints (using yy$tppos) on top of raw data plot. Result is exactly as expected, graphically. For another purpose, I calcuate the difference between turnpoints (representing
2010 Jul 07
0
HELP - four.nines.cartesian.probability.grid
...uot;, X.start, X.end) { probs <- c(0.0001, 0.0003, 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.98, 0.99, 0.995, 0.998, 0.999, 0.9997, 0.9999) z.vals <- qnorm(probs) y.min <- z.vals[1] y.max <- z.vals[length(z.vals)] npts <- length(X.data) X.mean <- mean(X.data) X.sd <- sd(X.data) X.001 <<- X.mean + X.sd * qnorm(0.001) X.999 <<- X.mean + X.sd * qnorm(0.999) plot(NA, axes = FALSE, xlim = c(X.start, X.end), ylim = c(qnorm(0.0001), qnorm(0.9999)), xlab = "", yl...