search for: yfit

Displaying 20 results from an estimated 21 matches for "yfit".

Did you mean: fit
2009 Oct 09
1
Substituting the extracted coefficients into the formula, exctracted from the result of nls()
...come with another stupid question. Suppose I want to use nls() to fit a series of data (here modelled by generated points), then plot the points and the fitting curve. I figured out some way of doing it: x <- runif(1:20, 0, 10) y <- 0.1*x^2 - rep(3, length(x)) + rnorm(length(x), sd = 0.5) yfit <- nls(y ~ a*x^2 + b*x + c, start = list(a = 1, b = 1, c = 1), trace = TRUE) plot(x, y) curve(coef(yfit)[1]*x^2 + coef(yfit)[2]*x + coef(yfit)[3], 0, 10, add = TRUE) However, this code is rather fortranesque, and most likely there exists a much more elegant way in...
2010 Nov 10
1
par mfrow in "function" problem
Hi all, I defined the following ############################# myhist=function(x){ hist(x,xlab="",main="") h=hist(x) xfit=seq(min(x),max(x),length=100) yfit=dnorm(xfit,mean(x),sd=sd(x)) yfit=yfit*diff(h$mids[1:2])*length(x) lines(xfit, yfit, col="blue", lwd=2) } ############################# individually, it worked fine however, if I used par(mfrow=c(2,2)) each time i run myhist it produces TWO plots, one without the 'lines',...
2009 Jun 21
2
Help on qpcR package
I am using R on a Windows XP professional platform. The following code is part of a bigger one CODE press=function(y,x){ library(qpcR) models.press=numeric(0) cat("\n") dep=y print(dep) indep=log(x) print(indep) yfit=dep-PRESS(lm(dep~indep))[[2]] cat("\n yfit\n") print(yfit) yfit.orig=yfit presid=y-yfit.orig press=sum(presid^2) cat("\n") cat("PRESS =",press,"\n") } On the command R window I define - Ignored: > x=c(12,24,13,11,23,10,9,17,11,...
2009 Sep 02
2
Howto fit normal curve into histogram using GGPLOT2
Currently, I am doing it this way. x <- mtcars$mpg h<-hist(x, breaks=10, col="red", xlab="Miles Per Gallon", main="Histogram with Normal Curve") xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) yfit <- yfit*diff(h$mids[1:2])*length(x) lines(xfit, yfit, col="blue", lwd=2) But since, ggplot2 has more appealing graphics, I wonder how can it be done. -G.V.
2006 Jul 03
0
Questions concerning function 'svm' in e1071 package
...have the following problem (illustrating R-code at bottom of mail): Given a training sample with binary outcomes (-1/+1), I train a linear Support Vector Machine to separate them. Afterwards, I compute the weight vector w in the usual way, and obtain the fitted values as w'x + b > 0 ==> yfitted = 1, otherwise -1. However, upon verifying with the 'predict' method, the outcomes do not match up as they should. I've already tried to find information concerning this issue on the R-help board, but to no avail. Can any of you point me in the right direction? Signed, Johan Van K...
2011 Oct 21
2
Arima Models - Error and jump error
...ls result from some parĂ¢meters combination. My data test have one year and daily level. A part of routine is: for ( d in 0:1 ) { for ( p in 0:3 ) { for ( q in 0:3 ) { for ( sd in 0:1 ) { for ( sp in 0:3 ) { for ( sq in 0:3 ) { Yfit=arima(Yst[,2],order=c(p,d,q),seasonal=list(order=c(sp,sd,sq),period=7),include.mean=TRUE,xreg=DU0) }}}}}} Until the step 187 it´s run normally, but in the step 187 return a error and stop the program. > Yfit=arima(Yst[,2],order=c(1,0,1),seasonal=list(order=c(2,1,2),period=...
2005 Oct 14
1
lattice with predicted values
...ws the right predictions if the relation is the same for all factor levels, but I can't figure out how to have the same slopes but different intercepts. # Function to draw predictions in xyplot panel.predfinal <- function(mod, x, y) { xfit <- seq(min(x), max(x), length=21) yfit <- predict(mod, newdata=data.frame(COV=xfit)) llines(xfit,yfit,lty=1) } xyplot(Y ~ COV | FACT, panel=function(x,y,groups,subscripts){ panel.xyplot(x,y) panel.predfinal(mod,x,y) } I would be very grateful for pointers (books, chapters, pages, archiv...
2010 Feb 19
1
"Legend" question
...line and point types.My code is as following: hist(CDR3,xlab="",ylab="",main=NULL, xlim=c(min(CDR3),max(CDR3)),freq=FALSE,col="lightgrey") # draw the overlaying normal curve and kernel curve, draw mean and median on X-axis xfit<-seq(min(CDR3),max(CDR3),length=100) yfit<-dnorm(xfit,mean=mean(CDR3),sd=sd(CDR3)) lines(xfit, yfit, col="red",lty=1,lwd=1) lines(density(CDR3,from=min(CDR3),to=max(CDR3)),col="blue",lty=1,lwd=1) mean(CDR3) median(CDR3) points(x=mean(CDR3),y=0,pch=19,col="red",cex=1) points(x=median(CDR3),y=0,pch=19,col=&q...
2001 Oct 13
2
hist and normal curve
Dear R people: I would like to superimpose a normal curve on a histogram. I've seen this example in a book, somewhere. I know that you draw the hist, get the mean and sd of the data set, but then I'm stuck. Could you help, please? Thanks! Erin hodgess at uhddx01.dt.uh.edu -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read
2012 Aug 24
0
A question about GRAMMAR calculations in the FAM_MDR algorithm
...llelic(k) } SNPS = as.data.frame(SNPS) SNPS[SNPS==-1] = NA # GRAMMAR calculations # here one has to include main effect and/or covariate adjustments in the polygenic model statement pkin = kinship(pedigree[,2],pedigree[,3],pedigree[,4]) maineff1 = as.factor(SNPS[,1]) maineff2 = as.factor(SNPS[,2]) Yfit = polygenic(trait~maineff1+maineff2,pkin,simulation.GenABEL,trait.type="gaussian") resi = Yfit$pgresidualY When I calculated the GRAMMAR and ran the command, "*Yfit = polygenic(trait~maineff1+maineff2,pkin,simulation.GenABEL,trait.type="gaussian") *", the software...
2005 Sep 25
4
hist(x, ...) with normal distribution curve
. I am looking for a histogram or box plot with the adding normal distribution curve I think that must be possible, but I am not able to find out how to do. Regards Knut
2004 Aug 24
0
additional examples for R-intro.texi (PR#7195)
...[,2] +[1,] 11.94725 -7661.319 +[2,] -7661.31875 8039421.153 + +$code +[1] 3 + +$iterations +[1] 26 +@end example + + To obtain the approximate standard errors (SE) of the estimates we do: @example @@ -5032,7 +5057,7 @@ @example > plot(x, y) > xfit <- seq(.02, 1.1, .05) -> yfit <- 212.68384222 * xfit/(0.06412146 + xfit) +> yfit <- out$estimate[1] * xfit/(out$estimate[2] + xfit) > lines(spline(xfit, yfit)) @end example --- R-intro.texi~ Tue Aug 24 11:21:38 2004 +++ R-intro.texi Tue Aug 24 11:21:38 2004 @@ -3307,8 +3307,8 @@ @R{} is an expression language i...
2007 Jun 07
2
Nonlinear Regression
Hello I followed the example in page 59, chapter 11 of the 'Introduction to R' manual. I entered my own x,y data. I used the least squares. My function has 5 parameters: p[1], p[2], p[3], p[4], p[5]. I plotted the x-y data. Then I used lines(spline(xfit,yfit)) to overlay best curves on the data while changing the parameters. My question is how do I calculate the residual sum of squares. In the example they have the following: df <- data.frame( x=x, y=y) fit <- nls(y ~SSmicmen(s, Vm, K), df) fit In the second line how would I input my functio...
2012 Oct 31
0
pseudo R-squared for model generated with spgm (splm)
...ssible to compute a R2, eg the ratio of variation explained by a given model. My model is : bivmod<-spgm(logIKA~NBLITRE0+NBLITRE1,data=mydatap,listw=comsKnn.nbW,spatial.error=TRUE) I know that we can calculate the R^2 as the variance of the fitted values from the reduced form of the model (Yfitted) over the variance of y (here logIKA). Since I am using the option lag = FALSE; the fitted value for an error model are Yfitted = X\beta. If I well understood : *1) We can get X* (NT * k matrix of observations on the non-stochastic regressors. with N: spatial units , T: time unit et k : num...
2007 Aug 23
0
weighted nls and confidence intervals
for unweighted fits using `nls' I compute confidence intervals for the fitted model function by using: #------------------- se.fit <- sqrt(apply(rr$m$gradient(), 1, function(x) sum(vcov(rr)*outer(x,x)))) luconf <- yfit + outer(se.fit, qnorm(c(probex, 1 - probex))) #------------------- where `rr' contains an `nls' object, `x' is the independent variable vector, `yfit' the corresponding model prediction (`fitted(rr)'), `se.fit' the corresponding standard error and `luconf' the lower and...
2007 Aug 31
0
non-linear fitting (nls) and confidence limits
...ny remarks appreciated. greetings joerg original post: -------------- for unweighted fits using `nls' I compute confidence intervals for the fitted model function by using: #------------------- se.fit <- sqrt(apply(rr$m$gradient(), 1, function(x) sum(vcov(rr)*outer(x,x)))) luconf <- yfit + outer(se.fit, qnorm(c(probex, 1 - probex))) #------------------- where `rr' contains an `nls' object, `x' is the independent variable vector, `yfit' the corresponding model prediction (`fitted(rr)'), `se.fit' the corresponding standard error and `luconf' the lower and...
1999 Dec 09
1
nlm() problem or MLE problem?
...("r/rt/data2/triam1.dat") rt<-sort(rt) plot(rt,ppoints(rt)) a<-9 b<-.27 fn<-function(p) -sum( log(dweibull(rt,p[1],p[2])) ) cat("starting -log like=",fn(c(a,b)),"\n") out<-nlm(fn,p=c(a,b), hessian=TRUE) xfit<-seq(min(rt),max(rt),(max(rt)-min(rt))/100) yfit<-pweibull(xfit,out$estimate[1], out$estimate[2]) lines(xfit,yfit,lty=2) yfit2<-pweibull(xfit,a, b) lines(xfit,yfit2) list(out=out) } I got the starting values a=9, b=.27 from fitting the Weibull CDF by eye to a quantile plot of the data. The final values fitted by nlm() are a= 4.8299357, b=...
2007 Sep 25
0
non-linear fitting (nls) and confidence limits
...uot; motivation for posting here, hoping for some clarifications...): for _unweighted_ fits using `nls' one can compute confidence intervals for the fitted model function via #------------------- se.fit <- sqrt(apply(res$m$gradient(), 1, function(x) sum(vcov(res)*outer(x,x)))) luconf <- yfit + outer(se.fit, qnorm(c(probex, 1 - probex))) #------------------- where `res' contains an `nls' object, `x' is the independent variable vector, `yfit' the corresponding model prediction (`fitted(res)'), `se.fit' the corresponding standard error and `luconf' the lower a...
2000 Nov 09
2
simple mixture
Dear All, I am trying to do some simple mixture analyses. For instance, I have a sample of n observations and I suspect they come from two different exponential distributions with parameters rate1 and rate2, respectively. So, I want to estimate rate1, rate2, and the proportions of both kinds of individuals in the sample. I had a look at the packages mda and mclust, but they do not seem to do this
2005 Oct 14
2
Help with lattice, regressions and respective lines
# Dear R list, # # I'm needing help with lattice, regression and respective lines. # My data is below: bra = gl(2, 24, label = c('c', 's')) em = rep(gl(3, 8, label = c('po', 'pov', 'ce')), 2) tem = rep(c(0, 0, 30, 30, 60, 60, 90, 90), 6) tem2 = tem^2 r = rep(1:2, 24) y = c(40.58, 44.85, 32.55, 35.68, 64.86, 51.95, 42.52, 52.21,