similar to: design matrix creation in R

Displaying 20 results from an estimated 10000 matches similar to: "design matrix creation in R"

2011 May 11
1
Help with contrasts
Hi, I need to build a function to generate one column for each level of a factor in the model matrix created on an arbitrary formula (instead of using the available contrasts options such as contr.treatment, contr.SAS, etc). My approach to this was first to use the built-in function for contr.treatment but changing the default value of the contrasts argument to FALSE (I named this function
2016 Oct 03
2
suggested addition to model.matrix
Hello, All: What's the simplest way to convert a data.frame into a model.matrix? One way is given by the following example, modified from the examples in help(model.matrix): dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) ab <- model.matrix(~ a + b, dd) ab0 <- model.matrix(~., dd) all.equal(ab, ab0) What do you think about replacing "model.matrix(~ a +
2005 Nov 04
1
model.matrix for non-hierarchical models
Dear R-users, Using the function model.matrix I noticed the following behaviour (example below): Using the formula "~ a + a:b" will give a matrix of the same dimension as using "~ a * b". In the first case there are additional columns for the interaction (to compensate for the missing main-effect). dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) model.matrix(~ a*b, dd,
2009 Jan 23
1
Interpreting model matrix columns when using contr.sum
With the following example using contr.sum for both factors, > dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) # balanced 2-way > model.matrix(~ a * b, dd, contrasts = list(a="contr.sum", b="contr.sum")) (Intercept) a1 a2 b1 b2 b3 a1:b1 a2:b1 a1:b2 a2:b2 a1:b3 a2:b3 1 1 1 0 1 0 0 1 0 0 0 0 0 2 1 1 0 0 1 0
2011 May 18
1
Need expert help with model.matrix
Dear experts: Is it possible to create a new function based on stats:::model.matrix.default so that an alternative factor coding is used when the function is called instead of the default factor coding? Basically, I'd like to reproduce the results in 'mat' below, without having to explicitly specify my desired factor coding (identity matrices) in the 'contrasts.arg'. dd
2009 Jul 28
2
formatting in r
Hello, I have output that I want to print out. I am having a few issues. 1] output u to power is really nothing more than a 2 x 11 set of values formed using cbind function and printed out as a data frame How can I get it to output over several lines such as seen here? 2] Critical Z etc. were added by hand. I need an example of how I can mix alphanumeric and numeric data on
2009 Jul 25
4
graphs
Hello, I am plotting two distributions and want to draw a vertical line at the critical point 149. How can I stop it from going further up than the norm(140,15) curve? x<-seq(75,225,0.1) plot(x,dnorm(x,mean=140, sd=15), type='l', col='navy') abline(v = 149, col = "black") curve(dnorm(x,mean=150, sd=15),from=75, to=225, col='orange', add=TRUE) Thank you.
2009 Jul 09
2
naming of columns in R dataframe consisting of mixed data (alphanumeric and numeric)
Hello, I have an r function that creates the following dataframe tresults2. Notice that column 1 does not have a column heading. Tresults2: [,1] estparam 18.00000 nullval 20.00000 . . . ciWidth 2.04622 HalfInterval 1.02311 pertinent code: results<-cbind( estparam, nullval, t, pv_left, pv_right, pv_two_t, estse, df, cc, tbox, llim, ulim, ciWidth,
2011 May 21
3
Simple R Question...
Let's say I have the data frame 'dd' below. I'd like to select one column from this data frame (say 'a') and keep its name in the resulting data frame. That can be done as in #2. However, what if I want to make my selection based on a vector of names (and again keep those names in the resulting data frame). My attempt is #4 but doesn't work. dd <- data.frame(a =
2009 Mar 20
2
print of objects in R
Hello, I have been watching my output as I create functions and do other things in r. One thing I don't like is the [1,] type notation at the beginning of a line. I have been able to change that to a number such as 1 2 etc. using as.data.frame(object). How can I stop the printing of a line number and column heading if I want to? I am thinking about publishing and writing of papers.
2009 Jul 23
2
mathematical notation in R
Does this approach what you're looking for? See ?is.finite for more info > LBAuo<- -9999 > LBAuo [1] -9999 > if (LBAuo <= -9999) LBAuo <- -Inf > LBAuo [1] -Inf > HTH Steven McKinney > -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Mary A. Marion > Sent: Wednesday, July 22, 2009
2011 Nov 01
2
drawing ellipses in R
Hello, I have been following the thread dated Monday, October 9, 2006 when Kamila Naxerova asked a question about plotting elliptical shapes. Can you explain the equations for X and Y. I believe they used the parametric form of x and y (x=r cos(theta), y=r sin(theta). I don't know what r is here ? Can you explain 1)the origin of these equations and 2) what is r? Sincerely, Mary A. Marion
2009 Jul 10
2
IF STATEMENTS
Hello, I am working on using if statements. What is the error message telling me here and how do I correct for it? I have tried various combinations of quotes. Thank you. Sincerely, Mary A. Marion #Find critical values crit<-function(n,alpha,type) { if (type==twoSided) { alpha2=alpha/2 tL<-qt(alpha2,n-1) tU<-qt(1-alpha2,n-1) } if (type==Lower) { tL<- -9999
2000 Dec 18
3
problems with glm (PR#771)
R1.2.0 with Linux RH5.2 I do not believe that the problems below are new to 1.2 but I only cover this sort of thing once a year in my course and some of that happened to be last Friday so too late to report for 1.2. I see that one or two things that I was going to report have been corrected. I like the fact that interactions now show : instead of . Here is some output with comments inserted. R
2000 Dec 18
3
problems with glm (PR#771)
R1.2.0 with Linux RH5.2 I do not believe that the problems below are new to 1.2 but I only cover this sort of thing once a year in my course and some of that happened to be last Friday so too late to report for 1.2. I see that one or two things that I was going to report have been corrected. I like the fact that interactions now show : instead of . Here is some output with comments inserted. R
2010 Dec 03
3
Checking for orthogonal contrasts
A common point made in discussion of contrasts, type I, II, III SS etc is that for sensible comparisons one should use contrasts that are 'orthogonal in the row-basis of the model matrix' (to quote from http://finzi.psych.upenn.edu/R/Rhelp02/archive/111550.html) Question: How would one check, in R, that this is so for a particular fitted linear model object? Steve Ellison
2011 Oct 28
4
Contrasts with an interaction. How does one specify the dummy variables for the interaction
Forgive my resending this post. To data I have received only one response (thank you Bert Gunter), and I still do not have an answer to my question. Respectfully, John Windows XP R 2.12.1 contrast package. I am trying to understand how to create contrasts for a model that contatains an interaction. I can get contrasts to work for a model without interaction, but not after adding the
2010 Apr 21
5
Bugs? when dealing with contrasts
R version 2.10.1 (2009-12-14) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with
2010 Nov 20
1
extraction of element
Hello, I want only the value of Beta so the statement? Power<-1-Beta[1] works right. How to do?? See code below Beta <- integrate(dnorm,mean=0,sd=1, 2.3552,Inf) Power<- 1-Beta[1] Sincerely, Mary A. Marion
2004 Mar 29
2
Confidence Intervals for slopes
Hi, I'm trying to get confidence intervals to slopes from a linear model and I can't figure out how to get at them. As a cut 'n' paste example: ################# # dummy dataset - regression data for 3 treatments, each treatment with different (normal) variance x <- rep(1:10, length=30) y <- 10 - (rep(c(0.2,0.5,0.8), each=10)*x)+c(rnorm(10, sd=0.1), rnorm(10,