Displaying 20 results from an estimated 6000 matches similar to: "Pasting data into scan() - oops!"
2006 May 01
2
Pasting data into scan()
The file TENSILE.DAT from the Hand et al "Handbook of Small Data Sets"
looks like this:
0.023 0.032 0.054 0.069 0.081 0.094
0.105 0.127 0.148 0.169 0.188 0.216
0.255 0.277 0.311 0.361 0.376 0.395
0.432 0.463 0.481 0.519 0.529 0.567
0.642 0.674 0.752 0.823 0.887 0.926
except that my mail client has replaced the tab separators by blanks. If
I paste this data into R 2.2.1 what I get is
2004 Feb 05
2
Sweave problem
Here is the file minimal.Snw:
\documentclass[a4paper]{article}
\title{R tips and tricks}
\author{Murray Jorgensen}
\usepackage{Sweave}
\begin{document}
\maketitle
\section*{Entering data from a single variable}
The following data are transformed tensile strength measurements on
polyester
fibres. They may be found on the file \texttt{TENSILE.DAT}. We
may enter this data into R using the
2006 Jul 21
0
[Fwd: Re: Parameterization puzzle]
Bother! This cold has made me accident-prone. I meant to hit Reply-all.
Clarification below.
-------- Original Message --------
Subject: Re: [R] Parameterization puzzle
Date: Fri, 21 Jul 2006 19:10:03 +1200
From: Murray Jorgensen <maj at waikato.ac.nz>
To: Prof Brian Ripley <ripley at stats.ox.ac.uk>
References: <44C063E5.3020703 at waikato.ac.nz>
2006 Jun 05
1
Extracting Variance components
I can ask my question using and example from Chapter 1 of Pinheiro & Bates.
> # 1.4 An Analysis of Covariance Model
>
> OrthoFem <- Orthodont[ Orthodont$Sex == "Female", ]
> fm1OrthF <-
+ lme( distance ~ age, data = OrthoFem, random = ~ 1 | Subject )
> summary( fm1OrthF )
Linear mixed-effects model fit by REML
Data: OrthoFem
AIC BIC
2008 Mar 02
2
Recommended Packages
Having just update to R 2.6.2 on my old Windows laptop I notice that the
number of packages is growing exponentially and my usual approach of
get-em-all may not be viable much longer. Has any thought been given to
dividing "contributed" binaries into a recommended set, perhaps a couple
of hundred, and the remained. That way one could install the recommended
ones routinely and add in
2006 Nov 13
2
A printing "macro"
I am exploring the result of clustering a large multivariate data set
into a number of groups, represented, say, by a factor G.
I wrote a function to see how categorical variables vary between groups:
> ddisp <- function(dvar) {
+ csqt <- chisq.test(G,dvar)
+ print(csqt$statistic)
+ print(csqt$observed)
+ print(round(csqt$expected))
+ round(csqt$residuals)
+ }
>
> x
2008 Oct 11
1
step() and stepAIC()
The birth weight example from ?stepAIC in package MASS runs well as
indeed it should.
However when I change stepAIC() calls to step() calls I get warning
messages that I don't understand, although the output is similar.
Warning messages:
1: In model.response(m, "numeric") :
using type="numeric" with a factor response will be ignored
(and three more the same.)
Checked
2007 Dec 05
2
Dimension of a vector
Consider the following:
> A <- 1:10
> A
[1] 1 2 3 4 5 6 7 8 9 10
> dim(A)
NULL
> dim(A) <- c(2,5)
> A
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10
> dim(A)
[1] 2 5
> dim(A) <- 10
> A
[1] 1 2 3 4 5 6 7 8 9 10
> dim(A)
[1] 10
Would it not make sense to have dim(A) = length(A) for all vectors?
2010 Jul 27
4
Sweave and scan()
I am introducing the scan() function to my class. Consider the following
file (Scanexamp.Rnw )
\documentclass[12pt]{article}
\begin{document}
<<>>=
height = scan()
64 62 66 65 62
69 72 72 70
part = scan(what = character(0))
"Soprano" "Soprano" "Soprano"
"Alto" "Alto" "Tenor"
"Tenor" "Bass"
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
2005 Sep 08
1
Coarsening Factors
It is not uncommon to want to coarsen a factor by grouping levels
together. I have found one way to do this in R:
> sites
[1] F A A D A A B F C F A D E E D C F A E D F C E D E F F D B C
Levels: A B C D E F
> regions <- list(I = c("A","B","C"), II = "D", III = c("E","F"))
> library(Epi)
> region <-
2005 Apr 05
1
nlme & SASmixed in 2.0.1
I assigned a class the first problem in Pinheiro & Bates, which uses the
data set PBIB from the SASmixed package. I have recently downloaded
2.0.1 and its associated packages. On trying
library(SASmixed)
data(PBIB)
library(nlme)
plot(PBIB)
I get a warning message
Warning message:
replacing previous import: coef in: namespaceImportFrom(self,
asNamespace(ns))
after library(nlme) and a
2006 Nov 13
1
stepAIC for overdispersed Poisson
I am wondering if stepAIC in the MASS library may be used for model
selection in an overdispersed Poisson situation. What I thought of doing
was to get an estimate of the overdispersion parameter phi from fitting
a model with all or most of the available predictors (we have a large
number of observations so this should not be problematical) and then use
stepAIC with scale = phi. Should this
2005 Dec 22
1
Huber location estimate
We have a choice when calculating the Huber location estimate:
> set.seed(221205)
> y <- 7 + 3*rt(30,1)
> library(MASS)
> huber(y)$mu
[1] 5.9117
> coefficients(rlm(y~1))
(Intercept)
5.9204
I was surprised to get two different results. The function huber() works
directly with the definition whereas rlm() uses iteratively reweighted
least squares.
My surprise is
2006 Jul 16
1
princomp and eigen
Consider the following output [R2.2.0; Windows XP]
> set.seed(160706)
> X <- matrix(rnorm(40),nrow=10,ncol=4)
> Xpc <- princomp(X,cor=FALSE)
> summary(Xpc,loadings=TRUE, cutoff=0)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4
Standard deviation 1.2268300 0.9690865 0.7918504 0.55295970
Proportion of Variance 0.4456907 0.2780929
2006 Sep 20
1
Pooled Covariance Matrix
I am in a discriminant analysis situation with a frame containing
several variables and a grouping factor, if you like:
set.seed(200906)
exampledf <- as.data.frame(matrix(rnorm(50,5,2),nrow=10,ncol=5))
exampledf$Group <- factor(rep(c(1,2,3),c(3,3,4)))
exampledf
I'm sure there must be a simple way to get the within group pooled
covariance matrix but I haven't found it yet.
I
2007 Nov 01
0
Reading R-help Digests with Mozilla Thunderbird
This is somewhat off-topic but I think that an answer may help other
users of R-help.
Thunderbird trys to help in the display of messages by "greying out"
quoted text. However when reading r-help in digest form it gets
thoroughly confused and usually ends up greying out the fresh text in a
message. [I'm using Windows XP].
Does anyone know how to turn off this Thunderbird
2005 Oct 06
0
R for teaching multivariate statistics (Summary)
Greetings all
I promised a summary of the responses that I got to my question:
"Next year I will be teaching a third year course in applied statistics
about 1/3 of which is multivariate statistics. I would be interested in
hearing experiences from those who have taught multivariate statistics
using R. Especially I am interested in the textbook that you used or
recommended."
There
2006 Aug 20
3
unquoting
I would like a function to strip quotes off character strings. I should
work like this:
> A <- matrix(1:6, nrow = 2, ncol=3)
> AF <- as.data.frame(A)
> names(AF) <- c("First","Second","Third")
> AF
First Second Third
1 1 3 5
2 2 4 6
> names(AF)[2]
[1] "Second"
> attach(AF)
>
2007 Jan 05
4
ifelse on data frames
[Using R 2.2.0 on Windows XP; OK, OK, I will update soon!]
I have noticed some undesirable behaviour when applying
ifelse to a data frame. Here is my code:
A <- scan()
1.000000 0.000000 0.000000 0 0.00000
0.027702 0.972045 0.000253 0 0.00000
A <- matrix(A,nrow=2,ncol=5,byrow=T)
A == 0
ifelse(A==0,0,-A*log(A))
A <- as.data.frame(A)
ifelse(A==0,0,-A*log(A))
and this is the output: