[R] fitting a model with the nlme package
Dear all, I am analyzing some data that requires a mixed model. I have been reading Pinheiro and Bates' book, but cannot find the notation to fit the following model: Suppose I have the dataset below. Here I am fitting variable p as a fixed effect, variable h as a random effect and variable t as nested within h. I would like to include the variable j as well as an independent (non-nested) random effect. I can't find the notation in the book to tell R to do this. Does anybody know? library(nlme) h<-c(1,1,1,2,2,2,3,3,3) j<-c(2,3,8,3,4,3,9,5,4) t<-c(1,2,3,1,2,3,1,2,3) f<-c(1,2,1,2,1,2,1,2,1) p<-c(45,32,35,12,23,12,2,9,12) set<-data.frame(p,h,j,t) out<-lme(p~ -1 + f,data=set, random=~1|h/t) Thanks a alot, frank. -- unladen european swallow __ R-help@stat.math.ethz.ch 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.
[R] lme4 package: Fitted values and residuals
Dear all, I have three concerns: 1) I am running models with the lme4 package. I cannot find a way to pull out a vector of the fitted values and the residuals. Does anybody know how to do it? 2) How can I nest a random effect variable into a "two-level" fixed effect variable? 3) Suppose I have the following model: y = a + b|c + d + error, where 'a' is a fixed effect, 'c' is a random effect nested with the random effect 'b', and 'd' is a non-nested random effect. Suppose I obtain parameter estimates for all of the predictor variables. Now, I would like to calculate a fitted value, 'yhat', from only the parameter estimates for 'a' and 'b|c'. Can this be done in lme4. That is; can I pull out all of the requisite elements from the output to calculate 'yhat'? Thanks for your help, Frank. -- __ R-help@stat.math.ethz.ch 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.
[R] loop problem
Hi, Here is my problem. Say I have two matrices, Matrix A: a b c 4 5 2 3 2 1 4 5 6 Matrix B: d e f g h 3 4 5 2 1 2 3 7 8 6 8 5 1 3 4 I would like to correlate vector a of matrix A with with vectors d,e,f,g,h of matrix "B" and save the p-values (or some type of statistic) in a seperate result vector, say z. Then, I would like to repeat this process for vector b and vector c of matrix A. In the present example, vector z would end up containg 15 elements. I tried a few double loops, but was not successful in saving the results in a vector. I was only able to print them with the "print" or "cat" command, but could not turn the print or cat results into an accessible object. Help would be appreciated. Thank you, Frank. -- or over the web __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] help with simple 3d graph
I have a large matrix and want to create a 3d surface of it. Suppose the matrix looks something like Matrix K: a<-c(1:1200) b<-c(rep(1:30,40)) c<-c(a+b^2) K<-data.frame(a,b,c) The vector values are not ordered (and repeat themselves as in b). Whenever I try commands like "persp" it wants ordered values. The only command that approximates what I want is "scatterplot3d" (see below) library(scatterplot3d) scatterplot3d(a,b,c) Can anybody help me with this. Thanks very much. Frank. -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] tapply question
HI, Suppose I have the following data structure. LRT tp 1 1.50654010 522 2 0.51793929 522 3 0.90340299 522 4 1.20293325 522 5 1.05578774 523 6 0.01617942 523 7 0.68183543 523 8 0.43820244 523 9 1.14123995 524 10 0.05809550 524 11 0.93061597 524 12 1.39739700 524 13 1.05220953 525 14 0.03471461 525 15 0.63168798 525 16 1.40592603 525 17 1.41884492 526 18 0.23388479 526 19 0.21881064 526 20 0.99710830 526 21 2.02054187 527 22 1.99872887 527 23 1.04187450 527 24 1.31556807 527 25 2.5190 528 26 2.94778561 528 27 1.88800177 528 28 2.08249941 528 I have succesfully used a command line such as the one below to get maxima for each "tp-category' data.out<-data[tapply(LRT,tp, function(x) which(LRT==max(x))),] However, when I try it on the above data, it gives me the following error message: >Error in "[.data.frame"(data, tapply(LRT, tp, function(x) which(LRT == : invalid subscript type I don't know what to do. Thanks for your help -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Newton-Raphson algorithm
Hi, I want to maximize a liklihood function with multiple parameters. There is no closed-form analytical solution to the estimates of the parameters, and I would like to implement a Newton-Raphson iterrative approach. Is there a maximization procedure, such as the Newton-Raphson algorithm, available in R? If not, does anybody have an idea how to best go about solving simultenous equations numerically in R? Thanks for your help. Frank. -- love email again __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html