nlme

Tricks for fitting data in nlme?

随声附和 提交于 2019-12-22 10:02:48
问题 When I fit data in nlme, I never succeed on the first try, and after nlme(fit.model) I am accustomed to seeing things such as: Error in nlme.formula(model = mass ~ SSbgf(day, w.max, t.e, t.m), random = list( : step halving factor reduced below minimum in PNLS step Error in MEestimate(nlmeSt, grpShrunk) : Singularity in backsolve at level 0, block 1 So I go back and 1)Change the units of the x-axis (e.g. from years to days, or days to growing degree days). 2)Make a x=0, y=0 measurement in my

R: fix model call in model using as.formula

一个人想着一个人 提交于 2019-12-22 09:18:12
问题 I have a gls model in which I assign a formula (from another object) to the model: equation <- as.formula(aic.obj[row,'model']) > equation temp.avg ~ I(year - 1950) mod1 <- gls(equation, data = dat) > mod1 Generalized least squares fit by maximum likelihood Model: equation Data: dat Log-likelihood: -2109.276 However I do not want the "Model" to be "equation" but rather the quation itself! How do I do this?? 回答1: This is pretty standard, even lm would do this. One approach: hijack the print

R error in lme function: NA/NaN/Inf in foreign function call (arg 3)

ぐ巨炮叔叔 提交于 2019-12-22 01:42:15
问题 I'm running linear mixed model in nlme package. control <- lmeControl(maxIter=100,opt = c("optim")) lme(response ~ 0+factorA+covariate,random=~1|factorB, weights=varIdent(form= ~1|factorA),control=control), And, it come an error as following. Error in logLik.reStruct(object, conLin) :NA/NaN/Inf in foreign function call (arg 3) Is it the same as the convergence error? or others? Thanks 回答1: This isn't quite an answer, but the formatting would be horrible in a comment. (Will delete or edit

Error in na.fail.default: missing values in object - but no missing values

流过昼夜 提交于 2019-12-17 19:58:05
问题 I am trying to run a lme model with these data: tot_nochc=runif(10,1,15) cor_partner=factor(c(1,1,0,1,0,0,0,0,1,0)) age=runif(10,18,75) agecu=age^3 day=factor(c(1,2,2,3,3,NA,NA,4,4,4)) dt=as.data.frame(cbind(tot_nochc,cor_partner,agecu,day)) attach(dt) corpart.lme.1=lme(tot_nochc~cor_partner+agecu+cor_partner *agecu, random = ~cor_partner+agecu+cor_partner *agecu |day, na.exclude(day)) I get this error code: Error in na.fail.default(list(cor_partner = c(1L, 1L, 2L, 1L, 1L, 1L, : missing

What is a dimnames error when estimating GLS?

房东的猫 提交于 2019-12-13 04:06:06
问题 I've Googled around quite a bit and can't find documentation on this. I'm trying to estimate a feasible generalized least squares (FGLS) model on cross-sectional time series data in R. For example: library(nlme) foo <- gls(Y ~ factor(panel_ID) + X1 + X2, data = myData, correlation=corARMA(p=1), method='ML', na.action=na.pass) When I run this (my data frame is quite large, which is why I don't include it here), I get the following error: # Error in array(c(X, y), c(N, ncol(X) + 1), list(row

covariance structure for multilevel modelling

旧街凉风 提交于 2019-12-12 14:57:05
问题 I have a multilevel repeated measures dataset of around 300 patients each with up to 10 repeated measures predicting troponin rise. There are other variables in the dataset, but I haven't included them here. I am trying to use nlme to create a random slope, random intercept model where effects vary between patients, and effect of time is different in different patients. When I try to introduce a first-order covariance structure to allow for the correlation of measurements due to time I get

Using R to calculate between- by within-subj ANOVA interaction contrasts using car or lme

不问归期 提交于 2019-12-12 03:37:25
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 4 years ago . Psychology student here. As part of my thesis I have some data from an experiment with two between-subjects IVs, classification and condition , and a within-subjects IV, trial_type . The data are of the form: test = data.frame( ID=rep(c(1,2,3,4,5,6), each=3), condition=rep(c('comp', 'seq', 'comp_text'), each=3, times=2), classification=rep(c('rule', 'exemplar'), each=3, length

Looping in nlme

扶醉桌前 提交于 2019-12-11 05:05:41
问题 Hi I am trying to perform a loop function to in which a new predictor variable is used in each iteration, however I get the following error. Error in model.frame.default(formula = ~age_c + zglobcog + apoee4_carrier + : variable lengths differ (found for 'i') The data I used can obtained from following google drive spreadsheet. https://docs.google.com/spreadsheets/d/18yll44P25qsGqgZw4RPTMjlGJ0aNLCp-vYugCD7GPk8/pubhtml library(nlme) snplist <- names(mydata)[5:7] models <- lapply(snplist,

gls object produced with wrapper function fails for prediction with new data

谁都会走 提交于 2019-12-11 04:43:00
问题 In the following example, I'm using a wrapper function to fit a gls object. I can successfully return the model prediction for the original data, but not when using newdata , which returns the error " Error in eval(expr, envir, enclos) : 'nthcdr' needs a list to CDR down ": # library ----------------------------------------------------------------- library(nlme) # wrapper function -------------------------------------------------------- test.gls <- function(data, ...){ fit <- gls(data=data, .

Trouble with achieving convergence in nonlinear mixed-effects model in Pinhiero and Bates book

。_饼干妹妹 提交于 2019-12-11 01:09:37
问题 I am working through Pinhiero and Bates' book Mixed Effects Models in S and S-Plus in R. I am having trouble getting a model in Chapter 8 (p. 387) to converge. library(nlme) fm1Wafer.nlmeR <- nlme(current ~ A + B * cos(4.5679 * voltage) + C * sin(4.5679 * voltage), data = Wafer, fixed = list(A ~ voltage + I(voltage^2), B + C ~ 1), random = list(Wafer = A ~ voltage + I(voltage^2), Site = pdBlocked(list(A ~ 1, A ~ voltage + I(voltage^2)-1))), start = c(-4.26, 5.62, 1.26, -0.10, 0.10), #