use matrix columns in linear fitHow to sort a dataframe by multiple column(s)Drop data frame columns by nameread.table returning character matrix, would like numericDummy Variables for Data Frame Containing only PredictorsHow to write and read matrix from file without column names?Using 'scan' to read into a matrix in RHow can I read a matrix from a txt file in R?How can I make predictor variables into a matrix?Sort a matrix by last columnMultiple regression in R with matrix columns in model

Why do most published works in medical imaging try to reduce false positives?

Should one buy new hardware after a system compromise?

Pirate democracy at its finest

What are these arcade games in Ghostbusters 1984?

What is a really good book for complex variables?

Should breaking down something like a door be adjudicated as an attempt to beat its AC and HP, or as an ability check against a set DC?

Employer demanding to see degree after poor code review

Make 24 using exactly three 3s

Where is the logic in castrating fighters?

Python program to find the most frequent letter in a text

Teacher help me explain this to my students

What is Theresa May waiting for?

Where have Brexit voters gone?

How should I introduce map drawing to my players?

My employer faked my resume to acquire projects

In general, would I need to season a meat when making a sauce?

C++ forcing function parameter evalution order

Is real public IP Address hidden when using a system wide proxy in Windows 10?

What is the object moving across the ceiling in this stock footage?

Why does this if-statement combining assignment and an equality check return true?

Is it true that cut time means "play twice as fast as written"?

Why were helmets and other body armour not commonplace in the 1800s?

How to use libraries with delays inside within a time critical STM32 HAL application?

Who will lead the country until there is a new Tory leader?



use matrix columns in linear fit


How to sort a dataframe by multiple column(s)Drop data frame columns by nameread.table returning character matrix, would like numericDummy Variables for Data Frame Containing only PredictorsHow to write and read matrix from file without column names?Using 'scan' to read into a matrix in RHow can I read a matrix from a txt file in R?How can I make predictor variables into a matrix?Sort a matrix by last columnMultiple regression in R with matrix columns in model






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















How to use one column of a numeric matrix as target variable and the remaining columns as predictors?



Somehow this doesn't work



# read matrix with 14 columns
d <- read.table("myfile.txt")

# target variable is last column
y <- d[,14]
x <- d[,-14]
my.fit <- y~x









share|improve this question

















  • 2





    There are at least a couple of major problems with your approach. Have you ever done a linear regression in R before? You don't give a function for controlling your data. Your independent variable is literally a pile of numbers. You might start by looking up "r linear regression".

    – shea
    Mar 24 at 4:41


















-1















How to use one column of a numeric matrix as target variable and the remaining columns as predictors?



Somehow this doesn't work



# read matrix with 14 columns
d <- read.table("myfile.txt")

# target variable is last column
y <- d[,14]
x <- d[,-14]
my.fit <- y~x









share|improve this question

















  • 2





    There are at least a couple of major problems with your approach. Have you ever done a linear regression in R before? You don't give a function for controlling your data. Your independent variable is literally a pile of numbers. You might start by looking up "r linear regression".

    – shea
    Mar 24 at 4:41














-1












-1








-1


1






How to use one column of a numeric matrix as target variable and the remaining columns as predictors?



Somehow this doesn't work



# read matrix with 14 columns
d <- read.table("myfile.txt")

# target variable is last column
y <- d[,14]
x <- d[,-14]
my.fit <- y~x









share|improve this question














How to use one column of a numeric matrix as target variable and the remaining columns as predictors?



Somehow this doesn't work



# read matrix with 14 columns
d <- read.table("myfile.txt")

# target variable is last column
y <- d[,14]
x <- d[,-14]
my.fit <- y~x






r






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 4:25









quantum_wellquantum_well

374314




374314







  • 2





    There are at least a couple of major problems with your approach. Have you ever done a linear regression in R before? You don't give a function for controlling your data. Your independent variable is literally a pile of numbers. You might start by looking up "r linear regression".

    – shea
    Mar 24 at 4:41













  • 2





    There are at least a couple of major problems with your approach. Have you ever done a linear regression in R before? You don't give a function for controlling your data. Your independent variable is literally a pile of numbers. You might start by looking up "r linear regression".

    – shea
    Mar 24 at 4:41








2




2





There are at least a couple of major problems with your approach. Have you ever done a linear regression in R before? You don't give a function for controlling your data. Your independent variable is literally a pile of numbers. You might start by looking up "r linear regression".

– shea
Mar 24 at 4:41






There are at least a couple of major problems with your approach. Have you ever done a linear regression in R before? You don't give a function for controlling your data. Your independent variable is literally a pile of numbers. You might start by looking up "r linear regression".

– shea
Mar 24 at 4:41













1 Answer
1






active

oldest

votes


















0














You can just do:



data(mtcars) #get some preinstalled data


model <- lm(mpg ~ ., data = mtcars) #fit the model

summary(model) #get the summary



This does a linear regression of mpg against all other variables. No further processing required.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320723%2fuse-matrix-columns-in-linear-fit%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can just do:



    data(mtcars) #get some preinstalled data


    model <- lm(mpg ~ ., data = mtcars) #fit the model

    summary(model) #get the summary



    This does a linear regression of mpg against all other variables. No further processing required.






    share|improve this answer



























      0














      You can just do:



      data(mtcars) #get some preinstalled data


      model <- lm(mpg ~ ., data = mtcars) #fit the model

      summary(model) #get the summary



      This does a linear regression of mpg against all other variables. No further processing required.






      share|improve this answer

























        0












        0








        0







        You can just do:



        data(mtcars) #get some preinstalled data


        model <- lm(mpg ~ ., data = mtcars) #fit the model

        summary(model) #get the summary



        This does a linear regression of mpg against all other variables. No further processing required.






        share|improve this answer













        You can just do:



        data(mtcars) #get some preinstalled data


        model <- lm(mpg ~ ., data = mtcars) #fit the model

        summary(model) #get the summary



        This does a linear regression of mpg against all other variables. No further processing required.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 9:16









        HumpelstielzchenHumpelstielzchen

        2,3211422




        2,3211422



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320723%2fuse-matrix-columns-in-linear-fit%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현