Hi, I want to plot the residuals of a least-squares regression. plot(lm(y~x), which=1) does this, but it plots the y-axis of my data on the x-axis of the residuals plot. That is, it plots the residual for each y-value in the data. Can I instead use the x-axis of my data as the x-axis of the residuals plot, showing the residual for a given x? Thanks! Jason Priem University of North Carolina at Chapel Hill School of Information and Library Science
Sunil Suchindran
2009-Sep-20 01:02 UTC
[R] plotting least-squares regression against x-axis
x <- seq(50) y <- 10 + x * 2 + rnorm(50,0,10) plot(y~x) mylm = lm(y~x) # Use str(mylm) to see how to get the residuals plot(x,mylm$residuals) On Sat, Sep 19, 2009 at 8:35 PM, Jason Priem <priem@email.unc.edu> wrote:> Hi, > I want to plot the residuals of a least-squares regression. > > plot(lm(y~x), which=1) > > does this, but it plots the y-axis of my data on the x-axis of the > residuals plot. That is, it plots the residual for each y-value in the > data. Can I instead use the x-axis of my data as the x-axis of the > residuals plot, showing the residual for a given x? > > Thanks! > > Jason Priem > University of North Carolina at Chapel Hill > School of Information and Library Science > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
I have fitted Hyperexponential distribution (HED) and Hypoexponential distribution (HoED) to two different data sets (of size 1000 numeric values each) using a software package called EMpht. I want to use R to perform goodness-of-fit test for the fitted distribution with respect to the empirical CDFs of the data sets using KS test (Kolmogorov-Smirnov test). ks.test() function in R takes the first argument as the data set, and the second argument as the name of the distribution, followed by the distribution parameter values. In case of the CDFs that are already supported by R, this is simple (for example: ks.test(data_set, "pnorm", mean, sd)). 1. Can somebody please suggest whether R has in-built support for Hyperexponential and Hypoexponential CDFs (they do not appear in the list of distribution given in "An Introduction to R"))? 2. If I write an R function to compute HED (or HoED) CDF value, can I use that function name as second argument in ks.test()? For example, if I implement an R function named HED_CDF with parameters <parameters...>, will it be correct to use ks.test() as follows: ks.test(data_set, "HED_CDF", <parameters...>) Will it give correct result? - Manuj Sharma From cricket scores to your friends. Try the Yahoo! India Homepage! http://in.yahoo.com/trynew [[alternative HTML version deleted]]
Manuj Your approach in (2) would work, looking at the source (just type ks.test) your function will be called with a sorted vector of data values, i.e. HED(sort(x), ...) where x is a?a numeric vector of data values and ... is the parameters as passed to ks.test This means your function needs to be able to handle a vector of inputs. Look at sapply if this is an issue. HTH Schalk Heunis On Sun, Sep 20, 2009 at 4:21 AM, Manuj Sharma <smanuj1970 at yahoo.in> wrote:> > I have fitted Hyperexponential distribution (HED) and Hypoexponential distribution (HoED) to two different data sets (of size 1000 numeric values each) using a software package called EMpht. > I want to use R to perform goodness-of-fit test for the fitted distribution with respect to the empirical CDFs of the data sets using KS test (Kolmogorov-Smirnov test). > ks.test() function in R takes the first argument as the data set, > and the second argument as the name of the distribution, followed by the distribution parameter values. In case of the CDFs that are already supported by R, this is simple (for example: ks.test(data_set, "pnorm", mean, sd)). > > 1. Can somebody please suggest whether R has in-built support for Hyperexponential and Hypoexponential CDFs > (they do not appear in the list of distribution given in "An Introduction to R"))? > > 2. If I write an R function to compute HED (or HoED) CDF value, can I use that function name as second argument in ks.test()? For example, if I implement an R function named HED_CDF with parameters <parameters...>, will it be correct to use ks.test() as follows: > ??? ks.test(data_set, "HED_CDF", <parameters...>) > Will it give correct result? > > - Manuj Sharma > > > > ? ? ?From cricket scores to your friends. Try the Yahoo! India Homepage! http://in.yahoo.com/trynew > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >