[R-sig-ME] Save estimates as CSV
Gabriel Baud-Bovy
baud-bovy.gabriel at hsr.it
Thu Oct 17 13:07:53 CEST 2013
Hi Anders,
You should use
print(summary(model))
in the loop.
Note that there are many functions to extract information
from a fitted model (e.g. coef, getME, VarCorr, ...) beside summary.
To save your results, it is best to define an empty structure (list,
array or data
frame) before running your loop and store your
results in it as you proceed. See also the plyr package.
There are many ways of computing the mean, interval of
confidence, SD, etc. in R. I suggest that you find a good
book on R as your question appears to me much more
R programming than to mixed effect models.
Best,
Gabriel
On 17/10/2013 11:34 AM, Anders Tisell wrote:
> Hi,
>
> I have measured a variable called R1 now I what to create a mixed linear model describing the variable R1, with the fixed effect Group which have 2 levels, and two random effects, called fpIDX and VOIidx.
>
> I want to calculate this model for a number of data sets therefore I tried to write a script with a for loop running over all data sets. When the loop is running I want to print the summery of the model. However, when I use the summary() function in the script there is no output, and I instead used the print() function (When I do it line by line in the console the summary() function works fine).
>
> Then, I also what to calculate the mean and standard deviation of the estimated R1 for each group, calculate 95% confidence the mean difference between the two groups, and calculate a post hoc t-test for the difference. Finally, I want to save the values of mean, SD of each group, the 95% conf.int. and the significance level to the t test in to a CSV file.
>
> The for loop now looks like the following:
> *** snip ***
>
> for(i in 1:length(FileList)){
>
>
>
> # Read the dataset into object data
> data <- read.csv(FileList[i])
>
> # display the data
>
>
>
> str(data)
>
> # Calculate a mixed linear model with Group as fixed effect, VOIidx and fpIDX as random effects
> model <- lmer(R1 ~ 1 + Group + ( 1 | fpIDX ) + ( 1 | VOIidx), data)
> print(model)
>
> summary(model) # this command do not yield any out put when I use it in the script file
>
>
>
> # Calculate mean R1 and SD for each Group
>
> #???
>
> # Calculate 95% of mean difference between Groups
> #???
>
> # Calculate post-hoc test between Groups
> #???
>
> # Save data to a result file
>
> # ???? How could I save the data
>
>
> }
>
> *** snip ***
>
> I would be glad for help in both my questions:
>
> 1. How do I get the information presented with the summary command for a lmer model when I am using a script?
>
> 2. How do I calculate and save estimates of mean, confint, test, etc of a lmer model?
>
> I'm using the R GUI for Mac OS version R 3.0.1 GUI 1.61 Snow Leopard build (6492)
>
> Best regards
> Anders
>
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> .
>
--
---------------------------------------------------------------------
Gabriel Baud-Bovy tel.: (+39) 02 2643 4839 (office)
UHSR University (+39) 02 2643 3429 (laboratory)
via Olgettina, 58 (+39) 02 2643 4891 (secretary)
20132 Milan, Italy fax: (+39) 02 2643 4892
More information about the R-sig-mixed-models
mailing list