search for: linmod

Displaying 14 results from an estimated 14 matches for "linmod".

2011 Oct 18
1
cygwing warming when creating a package in windows
...m a beginner creating R packages. I followed the Leisch (2009) tutorial and the document ?Writing R Extensions? to write an example. I installed R 2.12.2 (I also tried R2.13.2), the last version of Rtools and the recommended packages in a PC with Windows 7 Home Premium. I can run R CMD INSTALL linmod in the command prompt and the R CMD check linmod. The following outputs are obtained: * installing *source* package 'linmod' ... ** R ** preparing package for lazy loading ** help *** installing help indices ** building package indices ... ** testing if installed package can be loaded * D...
2013 Mar 12
1
Cook's distance
Dear useRs, I have some trouble with the calculation of Cook's distance in R. The formula for Cook's distance can be found for example here: http://en.wikipedia.org/wiki/Cook%27s_distance I tried to apply it in R: > y <- (1:400)^2 > x <- 1:100 > lm(y~x) -> linmod # just for the sake of a simple example > linmod$residuals[1]^2/(2*mean(linmod$residuals^2))*(hatvalues(linmod)[1]/(1-hatvalues(linmod)[1])^2) 1 0.02503195 > cooks.distance(linmod)[1] 1 0.02490679 Why differ the two results? Thanks a lot if somebody have some instructio...
2009 Oct 26
2
What is the most efficient practice to develop an R package?
...ject.org/doc/contrib/Leisch-CreatingPackages.pdf It seems that I have to do the following two steps in order to make an R package. But when I am testing these package, these two steps will run many times, which may take a lot of time. So when I still develop the package, shall I always source('linmod.R') to test it. Once the code in linmod.R is finalized, then I run the following two steps? I'm wondering what people usually do when developing packages. 1. Run the following command in R to create the package package.skeleton(name="linmod", code_files="linmod.R") 2...
2010 Apr 27
3
Problem calculating multiple regressions on a data frame.
...age) I have also tried to follow the approach suggested by Charles Sharpsteen (http://www.mail-archive.com/r-help@r-project.org/msg74759.html) with similar results. The code is as follows: theModels <- by( theTestLineal, list( theTestLineal$ids, zongTestLineal$variable), function( dataSlice ){ linMod <- lm( value ~ seqMonth, data = dataSlice ) # Slope and intercept may be recovered from the output of the coef() function: intercept <- coef( linMod )[1] slope <- coef( linMod )[2] # The R-Squared value is returned by the summary() function: rsq <- summary( linMod )[[ ''r.squa...
2010 Jun 21
2
How to predict the mean and variance of the dependent variable after regression
Hi, folks, As seen in the following codes: x1=rlnorm(10) x2=rlnorm(10,mean=2) y=rlnorm(10,mean=10)### Fake dataset linmod=lm(log(y)~log(x1)+log(x2)) After the regression, I would like to know the mean of y. Since log(y) is normal and y is lognormal, I need to know the mean and variance of log(y) first. I tried mean (y) and mean(linmod), but either one is what I want. Any tips? Thanks in advance! [[alternative HT...
2006 Jan 11
1
updating formula inside function
Dear R-Helpers Given a function like foo <- function(data,var1,var2,var3) { f <- formula(paste(var1,'~',paste(var2,var3,sep='+'),sep='')) linmod <- lm(f) return(linmod) } By typing foo(mydata,'a','b','c') I get the result of the linear model a~b+c. How can I rewrite the function so that the formula can be updated inside the function, i.e. foo <- function(data,var1,var2,var3,var4) { f <- formula(paste(var1...
2009 Sep 14
3
Eliminate cases in a subset of a dataframe
Hi folks, I created a subset of a dataframe (i.e., selected only men): subdata <- subset(data,data$gender==1) After a residual diagnostic of a regression analysis, I detected three outliers: linmod <- lm(y ~ x, data=subdata) plot(linmod) Say, the cases 11,22, and 33 were outliers. Here comes the problem: When I want to exclude these three cases in a further regression analysis, - for instance with linmod2 <- lm(y[-c(11,22,33)] ~ x[-c(11,22,33)], data=subdata) - it does not work. I g...
2010 Jun 18
1
How to calculate the robust standard error of the dependent variable
Hi, folks linmod=y~x+z summary(linmod) The summary of linmod shows the standard error of the coefficients. How can we get the sd of y and the robust standard errors in R? Thanks! [[alternative HTML version deleted]]
2009 Nov 05
2
Using a by() function to process several regression (lm()) functions
Hello, Thank you very much for looking at this. I have a "seasonal" user for R. I teach my undergrads and graduates students statistics using R and often find myself trying to solve problems to process student collected data in an efficient way. In this case, I have a data.frame with multiple observations. These are gas concentrations in a chamber and are used to measure into rates,
2012 May 29
2
setting parameters equal in lm
...("-1" somewhere after the tilde). But how about setting parameters equal? I have used the car package to set up linear hypotheses: X1 = rnorm(20, 10, 5); X2 = rnorm(20, 10, 5); X3 = rnorm(20, 10, 5) Y = .5*X1 + 3*X2 + .5*X3 + rnorm(20, 0, 15) data.set = data.frame(cbind(X1, X2, X3, Y)) linMod = lm(Y~X1 + X2 + X3, data=data.set) require(car) linearHypothesis(linMod, c("(Intercept)=0", "X1-X3=0")) (forgive the unconventional use of the equal sign....old habit). Unfortunately, the linearHypothesis is always compared to a full model (where the parameters are freely esti...
2008 Mar 10
3
Weighting data when running regressions
...y to run a linear regression on a subset of my data file where WEIGHT is the name of my weighting variable (numeric), e.g.: library(foreign) data1=read.spss("File.sav", use.value.labels = FALSE, to.data.frame = TRUE) summary(data1) ' shows me all the variables OK attach(data1) linmod=lm(Y~X1+X2+X3+X4W, subset=(X5==1 & X6==7), weights==WEIGHT) and I get the following Error message: Error in weights == WEIGHT : comparison (1) is possible only for atomic and list types It works perfectly if I don't use the ", weights==WEIGHT" bit Could you...
2006 Aug 02
0
Trying to use segmented in a function
...simdata<-function (Ns=200,Xmean=20,Xsd=5,SdYerr=0.5,Yint=0,threshold=20,slopebelow=0.5,slo peabove=1) { Xs<-rnorm(Ns,Xmean,Xsd) Yerr<-rnorm(Ns,0,SdYerr) D<-ifelse(Xs<=threshold,0,1) XminusX0<-Xs-threshold Ys<-Yint+slopebelow*Xs+slopeabove*XminusX0*D+Yerr plot(Xs,Ys) linmod<-lm(Ys~Xs) segment<-segmented(linmod,Z=Xs,psi=threshold) segment } This code should simply simulate some "breakpoint" data, with the change in slope at "threshold" and then fit a model with segmented. If I just use the code for simulating the data, and run that,...
2011 Mar 27
1
Sweave: include a multi-page-pdf plot
Hi, I'm just starting out with Sweave, and I can't get a plot(linmod) to display all four plots: << bild >>= x1 <- runif(100) x2 <- rexp(100) y <- 3 + 4*x1 + 5*x2 + rnorm(100) mod <- lm(y~x1+x2) plot(mod) @ Some Text <<fig=TRUE>>= <<bild>> @ This plots only the first image of the four-page plot.lm() result. I don...
2007 Jul 24
0
Fitting the best line to the plot of distance vs. correlation matrix
Hi all, Thanks for your help in generating the matrix of distance vs correlation. I did it using plot(as.vector(as.matrix(cormat)), as.vector(as.matrix(distmat))) Now I want to quantitate the same. May be on linear regression or some other statistical functions. I have tried using linmod for linear regression. But as I have two matrices in the form of the dataframes, I'm wondering if it is the right way to do it in this? Or are there even better options than this available. Can anyone please help me for that. Thanks. Urmi --------------------------------- Once u...