[R] sresid with lme4

2012-01-18 Thread Rense
Hi all,

does anyone know how to extract or calculate studentized residuals for mixed
effects models estimated with the lme4 package?

kind regards,
Rense 

--
View this message in context: 
http://r.789695.n4.nabble.com/sresid-with-lme4-tp4305922p4305922.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] warning inside loop

2010-01-12 Thread Rense

Dear William,

thank you kindly for this solution: it provides exactly what I need,
especially due to the fact that the encapsulating function returns a list,
from which I can extract all the information I need.

kind regards,

Rense Nieuwenhuis



William Dunlap wrote:
 
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Rense
 Sent: Monday, January 11, 2010 3:07 PM
 To: r-help@r-project.org
 Subject: [R] warning inside loop
 
 
 Hi,
 
 I'm running some data simulations using (mixed effects)* 
 regression models
 that show difficulty to converge. Therefore, I seek a way of capturing
 warnings (of false convergence) inside a loop.
 
 Inside that loop, I modify data and estimate a model. I do so 
 many times
 with slightly different modifications of the data. Next, I 
 extract some of
 the model parameters and store these in a matrix. However, as 
 some of the
 models do not converge well, some of the stored parameters 
 are extracted
 from the ill-converged models. Therefore, I seek a way of 
 automatically
 detecting whether the estimation procedure has resulted in a 
 warning, so I
 can distinguish between the well- and ill-converged models.
 
 I have been trying to use functions as warnings(), as well as 
 using the
 object last.warning, but unfortunately to no avail.
 
 Try withCallingHandlers(), as in the following function
 with returns the value of the expression along with
 any warning messages as a list:
 
 withWarnings
 function (expr) 
 {
 warnings - character()
 retval - withCallingHandlers(expr, warning = function(ex) {
 warnings - c(warnings, conditionMessage(ex))
 invokeRestart(muffleWarning)
 })
 list(Value = retval, Warnings = warnings)
 }
 environment: R_GlobalEnv
 
 Typical usage would be:
 lapply(-1:1, function(i)withWarnings(log(i)))
 [[1]]
 [[1]]$Value
 [1] NaN
 
 [[1]]$Warnings
 [1] NaNs produced
 
 
 [[2]]
 [[2]]$Value
 [1] -Inf
 
 [[2]]$Warnings
 character(0)
 
 
 [[3]]
 [[3]]$Value
 [1] 0
 
 [[3]]$Warnings
 character(0)
 
 Perhaps there is some encapsulation of this already in some
 package, as try() encapsulates error catching.
 
 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com 
 
 
 Although I cannot provide a reproducible example, I 
 schematically represent
 the procedure I seek to use below:
 
 
 for (i in 1:10)
 {
 modify data
 estimate model
 
 evaluate whether estimation produced warning
 
 extract model parameters, and store whether warning occured
 }
 
 I hope any one can give some guidelines on how to deal with 
 warnings inside
 a loop.
 
 With Kind regards,
 
 Rense
 
 
 
 
 
 *Although I use the lme4 package for that actual analysis, I sent my
 question to this mailinglist (instead of the R mixed list) 
 because I believe
 this is a general issue, rather than one associated 
 exclusively with mixed
 models.
 -- 
 View this message in context: 
 http://n4.nabble.com/warning-inside-loop-tp1011667p1011667.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org 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-help@r-project.org 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.
 
 

-- 
View this message in context: 
http://n4.nabble.com/warning-inside-loop-tp1011667p1011979.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] warning inside loop

2010-01-11 Thread Rense

Hi,

I'm running some data simulations using (mixed effects)* regression models
that show difficulty to converge. Therefore, I seek a way of capturing
warnings (of false convergence) inside a loop.

Inside that loop, I modify data and estimate a model. I do so many times
with slightly different modifications of the data. Next, I extract some of
the model parameters and store these in a matrix. However, as some of the
models do not converge well, some of the stored parameters are extracted
from the ill-converged models. Therefore, I seek a way of automatically
detecting whether the estimation procedure has resulted in a warning, so I
can distinguish between the well- and ill-converged models.

I have been trying to use functions as warnings(), as well as using the
object last.warning, but unfortunately to no avail.

Although I cannot provide a reproducible example, I schematically represent
the procedure I seek to use below:


for (i in 1:10)
{
modify data
estimate model

evaluate whether estimation produced warning

extract model parameters, and store whether warning occured
}

I hope any one can give some guidelines on how to deal with warnings inside
a loop.

With Kind regards,

Rense





*Although I use the lme4 package for that actual analysis, I sent my
question to this mailinglist (instead of the R mixed list) because I believe
this is a general issue, rather than one associated exclusively with mixed
models.
-- 
View this message in context: 
http://n4.nabble.com/warning-inside-loop-tp1011667p1011667.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Time-travelling laptop, or problem with system.time?

2008-11-01 Thread Rense

Playing around with my new laptop (Macbook, 2.4Ghz), I encountered
unexplained timings using system.time.

I did the following:

 X - Matrix(rnorm(1e6), 1000)
 system.time(for(i in 1:25) X%*%X)
user system elapsed
8.306 0.591 5.031
 system.time(for(i in 1:25) solve(X))
user system elapsed
8.933 1.331 6.684
 system.time(for(i in 1:10) svd(X))
user system elapsed
36.989 3.665 33.384

From R-News I got the following description:

The returned value consists of user time (CPU time R needs for
calculations), system time (time the system is using for processing
requests, e.g., for handling files), total time (how long it really took to
process the command) and — depending on the operating system in use — two
further elements.

Do I misunderstand these timings, or is my laptop indeed capable of time
travel?

Kind regards,

Rense




-- 
View this message in context: 
http://www.nabble.com/Time-travelling-laptop%2C-or-problem-with-system.time--tp20279832p20279832.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Importing data

2008-01-06 Thread Rense Nieuwenhuis
Hi,

you might try to use the foreign-package, which contains the function  
read.spss. This works fine most of the time,

For a description of its usage, see the help-files or my own website:  
http://www.rensenieuwenhuis.nl/r-project/manual/basics/getting-data- 
into-r-2/

Remember, you'll need to install the foreign-package first.

Hope this helps,

Rense Nieuwenhuis
On Jan 6, 2008, at 12:46 , Simo Vundla wrote:

 Hi,
 I'm trying to import categorical data from SPSS to R using the script:
 xxx -spss.get(xxx.por, use.value.labels=TRUE) but unfortunately  
 am getting an error message 'error reading portable-file dictionary'.

 I have successfully imported data in the past.

 What could be the problem with this data?

 Thanks

 Simo








 __ 
 __
 Be a better friend, newshound, and


   [[alternative HTML version deleted]]

 __
 R-help@r-project.org 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-help@r-project.org 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.


Re: [R] Data frame manipulation - newbie question

2008-01-06 Thread Rense Nieuwenhuis
Hi,

you may want to use that apply / tapply function. Some find it a bit  
hard to grasp at first, but it will help you many times in many  
situations when you get the hang of it.

Maybe you can get some information on my site: http:// 
www.rensenieuwenhuis.nl/r-project/manual/basics/tables/


Hope this helps,

Rense Nieuwenhuis



On Jan 3, 2008, at 11:53 , José Augusto M. de Andrade Junior wrote:

 Hi all,

 Could someone please explain how can i efficientily query a data frame
 with several factors, as shown below:

 -- 
 ---
 Data frame: pt.knn
 -- 
 ---
 row | k.idx   |   step.forwd  |  pt.num |   model |   prev  |  value
 |  abs.error
 1  2000  1 lm  09
 10.5   1.5
 2  2000  2 lm  11
 10.5   1.5
 3  2011  1 lm  10
 12  2.0
 4  2011  2 lm  12
 12  2.0
 5  2022  1 lm  12
 12.1   0.1
 6  2022  2 lm  12
 12.1   0.1
 7  2000  1 rlm 10.1
 10.5   0.4
 8  2000  2 rlm 10.3
 10.5   0.2
 9  2011  1 rlm 11.6
 12  0.4
 102011  2 rlm 11.4
 12  0.6
 112022  1 rlm 11.8
 12.1   0.1
 122022  2 rlm 11.9
 12.1   0.2
 -- 
 

 k.idx, step.forwd, pt.num and model columns are FACTORS.
 prev, value, abs.error are numeric

 I need to take the mean value of the numeric columns  (prev, value and
 abs.error) for each k.idx and step.forwd and model. So: rows 1 and 2,
 3 and 4, 5 and 6,7 and 8, 9 and 10, 11 and 12 must be grouped
 together.

 Next, i need to plot a boxplot of the mean(abs.error) of each model
 for each k.idx.
 I need to compare the abs.error of the two models for each step and
 the mean overall abs.error of each model. And so on.

 I read the manuals, but the examples there are too simple. I know how
 to do this manipulation in a brute force manner, but i wish to learn
 how to work the right way with R.

 Could someone help me?
 Thanks in advance.

 José Augusto
 Undergraduate student
 University of São Paulo
 Business Administration Faculty

 __
 R-help@r-project.org 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-help@r-project.org 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] Same regression per sub-group: apply?

2007-12-07 Thread Rense Nieuwenhuis
Dear helpers,

I've come up with what is probably a simple problem, but I cannot  
find the solution. I have a data-set containing survey-data from  
several countries. What I want to do is to perform some regression  
analyses, for each country separately. The question is, how to do  
this nicely (thus without repeating the same syntax with another  
`subset' argument).

I thought of the following:

model.per.country - tapply(data, data$COUNTRY, function(x) glm 
(dependent.var ~ FEMALE + AGE + EDUCLIN + (), family=binomial,  
data=capital))

But this does not work. What goes wrong, I think, is that the  
dependent variable is clustered according to `Country', but not so  
for the predictors. The error message I received:

Error in tapply(dat, dat$COUNTRY, function(x) glm(participate ~  
FEMALE +  :
arguments must have same length
 


Could you please help me solving this little problem?

Thanks in advance:

Rense Nieuwenhuis



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.