search for: lm1

Displaying 20 results from an estimated 143 matches for "lm1".

Did you mean: l1
2013 Mar 18
1
try/tryCatch
...e", "spec_se") k=1 for(ii in 1:dim(mydata)[3]){ tmp<-mydata[,,ii] tmp1<-as.data.frame(tmp) names(tmp1)=c("persons", "d1", "tp", "fn", "fp", "fn", "detect", "d0", "outcome") lm1<-try(lmer(outcome~0+d1+d0+(0+d1+d0 | persons), family=binomial, data=tmp1, nAGQ=3), silent=T) if(class(lm1)[1]!='try-error'){ a[ii,1]=lm1@fixef[1] a[ii,2]=lm1@fixef[2] a[ii,3]=vcov(lm1)[1,2]/prod(sqrt(diag(vcov(lm1)))) a[ii,4:5]=sqrt(diag(vcov(lm1)))...
2003 Jul 30
2
Comparing two regression slopes
...oncerned, because when I test it on simulated data with different sample sizes and variances, the function seems to be extremely sensitive both of these. I am wondering if I've missed something in my function? I'd be very grateful for any tips. Thanks! Martin TwoSlope <-function(lm1, lm2) { ## lm1 and lm2 are two linear models on independent data sets coef1 <-summary(lm1)$coef coef2 <-summary(lm2)$coef sigma <-(sum(lm1$residuals^2)+sum(lm2$residuals^2))/(lm1$df.residual + lm2$df.residual-4) SSall <-sum(lm1$model[,2]^2) + sum(lm2$model[,2]^2) SSprod <-sum(lm1...
2005 Mar 09
1
multiple comparisons for lme using multcomp
...Al800 q 1.0 69 Al800 r 0.8 70 Al800 r 0.9 71 Al800 r 0.9 72 Al800 r 0.6 73 Al800 s 0.9 74 Al800 s 1.0 75 Al800 s 0.8 76 Al800 s 0.8 77 Al800 s 0.7 > attach(tab) > library(nlme) > lm1<-lme(response~treatment,random=~1|box) > library(multcomp) Loading required package: mvtnorm > # first way to do (seem uncorrect) > summary(csimtest(coef(lm1),vcov(lm1),cmatrix=contrMat(table(treatment), type="Tukey"),df=59)) Error in csimtest(coef(lm1), vcov(lm1), cmatrix...
2006 May 06
2
How to test for significance of random effects?
...me() does provide a confidence interval for the between-group variance, but this is constructed so as to never include zero (I guess the interval is as narrow as possible on log scale, or something). I would be grateful if anyone could tell me how to test for zero variance between groups. If lm1 and lme1 are fitted with lm() and lme() respectively, then anova(lm1,lme1) gives an error, whereas anova(lme1,lm1) gives an answer which looks reasonable enough. The command logLik() can retrieve either restricted or ordinary log-likelihoods from a fitted model object, but the likelihoods ar...
2005 May 31
2
simple predict question
Excuse the simple question... I'm not sure what I'm doing wrong with predict, but let me use this example: Suppose I do: dat<-matrix(c(0,0,10,20),2,byrow=T) lm1<-lm(dat[,2]~dat[,1]) Suppose I want to generate the linearly-interpolated y-values between the point (0,0) and (0,20) at every unit interval. I thought I just do: predict(lm1, data.frame(seq(0,10,1))) to get 0,2,4,6...,18,20, but instead I just get: 1 2 0 20 Any suggestions? Thanks, Ste...
2006 Nov 30
1
data.frame within a function (PR#9294) (cont'd)
...k\n") } ######################### # compare f1() and f2() # ######################### f1<- function(){ x<- rnorm(10) y<- rmvnorm(10,mean=c(1,2)); colnames(y)<- paste("y",1:2,sep="") #c("y1","y2") dtf<- data.frame(y,x) lm1<- lm(cbind(y1,y2)~1,data=dtf); cat("ok\n") update(lm1,~ .+x,evaluate=T); cat("also ok\n") # only this line is different } f2<- function(){ x<- rnorm(10) y<- rmvnorm(10,mean=c(1,2)); colnames(y)<- paste("y",1:2,sep="") #c(&...
2008 Sep 17
2
Command Prompt Question
...: if I enter example(AIC), instead of just getting the regular '>' before each output line, I get 'AIC>' instead. I only want the '>' and have searched everywhere and can't find an option to change this. Thanks David ----------------------- AIC> lm1 <- lm(Fertility ~ . , data = swiss) AIC> AIC(lm1) [1] 326.0716 AIC> stopifnot(all.equal(AIC(lm1), AIC+ AIC(logLik(lm1)))) AIC> ## a version of BIC or Schwarz' BC : AIC> AIC(lm1, k = log(nrow(swiss))) [1] 339.0226 [[alternative HTML ver...
2010 Aug 17
2
how to selection model by BIC
Hi All: the package "MuMIn" can be used to select the model based on AIC or AICc. The code is as follows: data(Cement) lm1 <- lm(y ~ ., data = Cement) dd <- dredge(lm1,rank="AIC") print(dd) If I want to select the model by BIC, what code do I need to use? And when to select the best model based on AIC, what the differences between the function "dredge" in package"MuMIn" and the fun...
2013 May 01
2
significantly different from one (not zero) using lm
Hello, I am work with a linear regression model: y=ax+b with the function of lm. y= observed migration distance of butterflies x= predicted migration distance of butterflies Usually the result will show if the linear term a is significantly different from zero based on the p-value. Now I would like to test if the linear term is significantly different from one. (because I want to know
2006 Apr 14
5
vector-factor operation
I found myself wanting to average a vector [vec] within each level of a factor [Fac], returning a vector of the same length as vec. After a while I realised that lm1 <- lm(vec ~ Fac) fitted(lm1) did what I want. But there must be another way to do this, and it would be good to be able to apply other functions than mean() in this way. Cheers, Murray -- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, Univer...
2012 May 22
1
Adding Text to a Plot
Hi, all! I'm pretty sure I'm missing something about this. Is there a smart way of typping hat(R)^2 and it's value from a linear regression? I've just found this tricky one: # Sample data x <- sample(1:100,10) y <- 2+3*x+rnorm(10) # Run the regression lm1 <- lm(y~x) # Plotting plot(x,y, main="Linear Regression", col="red") abline(lm1, col="blue") placex <- par("usr")[1]+.1*(par("usr")[2]-par("usr")[1]) placey1 <- par("usr")[3]+.9*(par("usr")[4]-par(&q...
2006 Jun 07
4
R crashes on quantreg
I was trying "quantreg" package, lm1 <- lm(y~x) rq1 <- rq(y~x) plot(summary(rq1)) #then got a warning says singular value, etc. but this line can be omited plot(lm1) #crash here It happened every time on my PC, Windows XP Pro Serv. Pack 1, Pentium(4) 3.00G. [[alternative HTML version deleted]]
2013 Jan 18
1
Object created within a function disappears after the function is run
...traitsclean<-traits birdhabitat<-merge(birdmatrix,habitatmatrix,by="SARBASINYEAR") #merge bird and habitat data data<-birdhabitat; data$SAR<-substr(data$SARBASINYEAR,1,3) #convenience; create SAR variable #make a FUNCTION to combine variables into models dredgeit<-function(lm1){ dd1<-dredge(lm1,eval=FALSE) #create all possible combinations dd1<-gsub("formula = ","",dd1,fixed=TRUE) #delete characters dd1<-gsub(" + 1","",dd1,fixed=TRUE) #delete characters dd1#inspect model formulae } lm1<-lm(data$BiRich.o~log(data$HaArea...
2012 May 27
7
Customized R Regression Output?
Hello R-Experts, I am facing the problem that I have to estimate several parameters for a lot of different dependent variables. One single regression looks something like this: y = beta0 + beta1 * x1 + beta2 * x2 + beta3 * x1 * x2 + beta4 * x4 + beta5 * lag(x4,-1) where y is the dependent variable and xi are the independent ones. Important to me are the different estimates of betai and their
2010 Jun 17
1
Problems using allEffects() (package effect)
...14.03 55805.1 55805 7 3 3 1 59.92 55829.1 55829 7 3 1 1 15.31 55806.1 55806 7 3 2 1 28.01 50725.1 50725 7 3 2 1 34.48 55737.1 55737 7 3 2 1 43.56 The linear model is also quite simple : > lm1=lm(Volume ~ temps + Traitement:temps + S?rie , data) But when I try to use allEffects() I get this error: > eff.lm1 <- allEffect(mod=lm1, Error in apply(mod.matrix[, components], 1, prod) : index out of range I read the help and the example but I don't understand the reason why it does...
2010 Oct 12
1
delta AIC for models with 2 variables using MuMIn
...f it is possible to show models with any two only certain variables. Thank you. Elaine I asked a similar question and got a great help for models with only one variable as below. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In effect, you want data(Cement) lm1 <- lm(y ~ ., data = Cement) dd <- dredge(lm1, subset = X1) want <- with(dd, is.na(X) & is.na(X2) & is.na(X3) & is.na(X4)) want ## how many models selected? sum(want) ## OK selected just 1, show it dd[want, , drop = FALSE] Oh, actually, I suppose you could automate this, so it...
2009 Jan 16
1
specifying model terms when using predict
...ould be acceptable in all situations but it seems models written this way are not accepted by the predict function. Perhaps others have encountered this problem as well. The code below illustrates the issue. ###### ## linear model example # this works x<-1:100 y<-2*x lm1<-glm(y~x) pred1<-predict(lm1,newdata=data.frame(x=101:150)) ## so does this x<-1:100 y<-2*x orig.df<-data.frame(x1=x,y1=y) lm1<-glm(y1~x1,data=orig.df) pred1<-predict(lm1,newdata=data.frame(x1=101:150)) ## this does not run x<-1:100 y<-2*x ori...
2010 Apr 08
2
Overfitting/Calibration plots (Statistics question)
...f the data: > x1 <- rnorm(200, 0, 1) > x2 <- rnorm(200, 0, 1) > x3 <- rnorm(200, 0, 1) > x4 <- rnorm(200, 0, 1) > x5 <- rnorm(200, 0, 1) > x6 <- rnorm(200, 0, 1) > y <- x1 + x2 + rnorm(200, 0, 2) > d <- data.frame(y, x1, x2, x3, x4, x5, x6) > > lm1 <- lm(y ~ ., data = d[1:100,]) > lm2 <- lm(y ~ x1 + x2, data = d[1:100,]) > > plot(predict(lm1, d[101:200, ]), d$y[101:200]); abline(0,1) > x11(); plot(predict(lm2, d[101:200, ]), d$y[101:200]); abline(0,1) The plots for both lm1 and lm2 show the points scattered around a line wi...
2007 Apr 02
2
Why does lmList() fail when lm() doesn't?
Dear r-helpers, Can anyone suggest why lm() doesn't complain here: summary(osss.lm1 <- lm(logOdds ~ c.setSize %in% task, data = osss)) whereas in package:nlme (and in package:lme4) osss.lmL <- lmList(logOdds ~ c.setSize %in% task | subj, data = osss) # Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : # contrasts can be applied only to factors with...
2014 Jun 24
2
Making several plots using a loop function
...rent plots. Specifically, for the code below, I generated 9 plots. I would like to add a title to each plot. For example, the titles will be respectively, plot1, plot 2, … plot 9. Thank you very much! Hanna par(mfrow=c(3,3), pty="s", pch=16, col="blue") for ( i in 1:9) { lm1 <- lm(log(run_res[2:11, i]) ~ log(level)) plot(log(level), log(run_res[2:11, i]), xlab="dllution levels", ylab="%PS-80") abline(lm1)} [[alternative HTML version deleted]]